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?
Element-by-element.
采纳的回答
V = B .* A ./ (B + 1);
15 个评论
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).
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 ?
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 ?
solve(Kgasa./(Kq-Kgasa)-Kg./(poro.*(Kq-Kg))==Kwsat./(Kq-Kwsat)-Kw./(poro.*(Kq-Kw)))
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?
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)
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Common Operations 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
