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 件のコメント
Walter Roberson
2013 年 11 月 16 日
Is the division to be matrix division, or element-by-element?
Rinu
2013 年 11 月 16 日
Element-by-element.
採用された回答
Walter Roberson
2013 年 11 月 16 日
V = B .* A ./ (B + 1);
15 件のコメント
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
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.
Walter Roberson
2013 年 11 月 17 日
So V/(A-V)=B is not really the form you are using? Or is it just "expensive" to calculate A and B ?
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.
Walter Roberson
2013 年 11 月 17 日
Could you show your solve() command ?
Rinu
2013 年 11 月 17 日
solve(Kgasa./(Kq-Kgasa)-Kg./(poro.*(Kq-Kg))==Kwsat./(Kq-Kwsat)-Kw./(poro.*(Kq-Kw)))
Rinu
2013 年 11 月 17 日
I need to solve for Kgasa. poro and Kwsat are the known vectors.
Walter Roberson
2013 年 11 月 17 日
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
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.
Walter Roberson
2013 年 11 月 17 日
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
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.
Walter Roberson
2013 年 11 月 17 日
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 ;-)
Alexander Kharlan
2016 年 5 月 6 日
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{:})
Walter Roberson
2016 年 5 月 7 日
"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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
