How to `subs` with both scalar variable and arrays?

1 回表示 (過去 30 日間)
wei zhang
wei zhang 2020 年 6 月 22 日
回答済み: madhan ravi 2020 年 6 月 22 日
I am evaluating some expression with subs. I need to input a scalar variable and an array. But it always give errors as I substitute them in one command as below.
e.g.
syms x
syms t [1 3]
g = x+t1+t2;
result = subs(g,{x,t},{1,[1,2,3]});
This is a mini case for my problem. How to solve this error? Must I subs the variables in several independent steps?

採用された回答

madhan ravi
madhan ravi 2020 年 6 月 22 日
syms x
syms t [1 3]
g = x+t1+t2;
t_vars = num2cell(t);
t_vals = num2cell(1:3);
result = subs(g,{x,t_vars{:}},{1,t_vals{:}})

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by