How do I get an Expression to Use the Value of a Variable that was Assigned after the Expression was Defined?

1 回表示 (過去 30 日間)
Suppose I assign to a sym as follows:
syms z f g
Define f in terms of z
f = 2*z
f = 
Now assign a value to z
z = sym(2)*1i;
But f is still expressed in terms of z and it doesn't seem to substitute the value for z
f
f = 
simplify(f)
ans = 
simplify(f - sym(2)*1i)
ans = 
But assigning to a new expression in terms of z works as expected.
g = 2*z
g = 
How do I get the SMT to realize that f = 2i?

採用された回答

Steven Lord
Steven Lord 2021 年 9 月 13 日
Use subs.
syms z
f = 2*z
f = 
z = 4;
f
f = 
g = subs(f)
g = 
8

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by