Solving equation with symbolic vector variable

I want to solve an equation of the form: V/(A-V)=B where A and B are known vectors and V is the symbolic vector variable I want to solve for. I created V by >>V=sym('V',[n 1]); and solved the equation by using 'solve' but in the output I get only the 'names' of the elements - V1, V2, V3, ... How do I get the values of V1, V2,...? Any help is much appreciated.

2 comentarios

Walter Roberson
Walter Roberson el 16 de Nov. de 2013
Is the division to be matrix division, or element-by-element?
Rinu
Rinu el 16 de Nov. de 2013
Element-by-element.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Nov. de 2013
V = B .* A ./ (B + 1);

15 comentarios

Rinu
Rinu el 17 de Nov. de 2013
Sorry, I should have mentioned that in my equation, A and B are not simple vectors but functions of scalars and vectors, such that it is difficult to isolate V to the left hand side of the equation and everything else to the right hand side. That is the reason why I think I need to solve the equation symbolically (by creating a symbolic vector variable V).
Rinu
Rinu el 17 de Nov. de 2013
If V were a simple symbolic variable (not vector), I think I know how to solve the equation symbolically. But I don't know how to handle symbolic VECTOR variables.
Walter Roberson
Walter Roberson el 17 de Nov. de 2013
So V/(A-V)=B is not really the form you are using? Or is it just "expensive" to calculate A and B ?
Rinu
Rinu el 17 de Nov. de 2013
Yeah, I thought solving it symbolically was the easiest way. I can solve it by calculating A and B, or using a for loop.
Walter Roberson
Walter Roberson el 17 de Nov. de 2013
Could you show your solve() command ?
Rinu
Rinu el 17 de Nov. de 2013
solve(Kgasa./(Kq-Kgasa)-Kg./(poro.*(Kq-Kg))==Kwsat./(Kq-Kwsat)-Kw./(poro.*(Kq-Kw)))
Rinu
Rinu el 17 de Nov. de 2013
I need to solve for Kgasa. poro and Kwsat are the known vectors.
Walter Roberson
Walter Roberson el 17 de Nov. de 2013
Which of those are intended to be numeric and which are intended to involve symbols? Are there any symbols present other that the V ? Are you assigning the output to anything?
Rinu
Rinu el 17 de Nov. de 2013
Only Kgasa is a symbolic variable (vector). All the others are either scalars or vectors in my workspace. Actually, it's just a linear equation with one variable (Kgasa) which I want to solve for 10 different values of poro and Kwsat. I want the vector Kgasa to contain those 10 roots. The code runs well without any error, but instead of getting numerical values in Kgasa, I get the elements as Kgasa1, Kgasa2,... I dont know how to display their numeric values.
Kgasa = ((-Kwsat .* poro + Kw - Kg) .* Kq.^2 + Kwsat .* ((Kw + Kg) .* poro - Kw + Kg) .* Kq - Kwsat .* poro .* Kg .* Kw) ./ (-poro .* Kq.^2 + ((Kw + Kg) .* poro + Kw - Kg) * Kq + (Kg - Kw) .* Kwsat - poro .* Kg .* Kw)
Rinu
Rinu el 17 de Nov. de 2013
Wow, you did some hard work. :) I was too lazy to do that. Now I dont need to use a symbolic variable. Thanks a lot.
Walter Roberson
Walter Roberson el 17 de Nov. de 2013
I simply used a symbolic package. The hard work was in editing the text to space it nicely and to add all of the "." in appropriate places ;-)
Well, got the same problem, only I cannot avoid using symbolic variables. And here on top of google search quiery we have an 'accepted' answer that DOESN'T ANSWER THE GODDAMN QUESTION. Shame on your face. If you are content with people doing your job for you, however not connected with the question you've asked, would you please go to some other forum.
Alexander Kharlan:
V = B .* A ./ (B + 1)
is the solution to the question originally presented. It turned out that question originally presented was not the real question, and the real question was solved to the user's satisfaction.
The more general question of how to solve a symbolic vector equation depends upon the release you are using . In current releases, you just use solve() on the vector equation. In slightly older releases, you use num2cell() to break the vector up into a cell array, and then you use cell array expansion to push the elements as separate parameters to solve(). For example,
mveq = num2cell(myVectorOfEquations);
mvvar = num2cell(VariablesToSolveFor);
solve(mveq{:}, mvvar{:})
"If you are content with people doing your job for you"
Answering questions here is not my job. As far as I know, the only people who are paid to answer questions here are the Mathworks staff who work on the Answers forum software itself. Everyone else who answers questions here (including the other people who happen to work for Mathworks) does so as a volunteer. I do not work for Mathworks; I have never worked for Mathworks.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 16 de Nov. de 2013

Comentada:

el 7 de Mayo de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by