How can I assign a symbolic expression to symbolic an element of an array

4 ビュー (過去 30 日間)
Felix Albrecht
Felix Albrecht 2018 年 9 月 28 日
コメント済み: madhan ravi 2018 年 10 月 5 日
syms x y u v w
var = [x,y];
sol = [u+w,v-w]
I just started learning MATLAB and I hope someone out there can help me.
How can I assign the symbolic expressions of sol to the elements of var, so that x and y have the values
x = u+w;
y = v-w;
Thanks

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 28 日
We recommend against that.
I suspect you should consider using the single output version of solve(): when there is more than one variable being solved for, it returns a struct or struct array whose fields are named after the variables. You can use that struct as the second input of subs()
sol = solve(....)
subs(EXPRESSION, sol)
When you compute a value and think you want to assign it to a a dynamic variable name, then the large majority of the time it is better to subs() instead.

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 9 月 28 日
編集済み: madhan ravi 2018 年 9 月 28 日
syms x y u v w
var = [x,y];
sol = [u+w,v-w];
disp(var==sol)
  5 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 5 日
crystal clear thank you @sir Walter

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by