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

Is the division to be matrix division, or element-by-element?
Rinu
Rinu 2013년 11월 16일
Element-by-element.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2013년 11월 16일
V = B .* A ./ (B + 1);

댓글 수: 15

Rinu
Rinu 2013년 11월 17일
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 2013년 11월 17일
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.
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 2013년 11월 17일
Yeah, I thought solving it symbolically was the easiest way. I can solve it by calculating A and B, or using a for loop.
Could you show your solve() command ?
Rinu
Rinu 2013년 11월 17일
solve(Kgasa./(Kq-Kgasa)-Kg./(poro.*(Kq-Kg))==Kwsat./(Kq-Kwsat)-Kw./(poro.*(Kq-Kw)))
Rinu
Rinu 2013년 11월 17일
I need to solve for Kgasa. poro and Kwsat are the known vectors.
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 2013년 11월 17일
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 2013년 11월 17일
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.
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2013년 11월 16일

댓글:

2016년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by