How to quickly "plug in" numerical values into symbolic equations to get a numerical result

172 ビュー (過去 30 日間)
Setup:
syms s
fs = (-2*(s-1))/((s+1)*(s+2));
fs1 = (1/s)*fs;
yt1 = ilaplace(fs1)
At this point Matlab returns the following symbolic equation:
yt1 = 3*exp(-2*t) - 4*exp(-t) + 1
To find yt1 when t = 0 and t = inf I can do the following:
yt1_0 = 3*exp(-2*0) - 4*exp(-0) + 1
yt1_inf = 3*exp(-2*inf) - 4*exp(-inf) + 1
But I was hoping that there is a smarter way to manipulate symbolic equations like:
yt1(t ==0)
yt1(t ==inf)
Or something like that so I do not have to write out the entire equation and update "t" as I have above.
Thoughts?
Thank you,
C

採用された回答

Voss
Voss 2022 年 1 月 23 日
You can use subs() to do that. It will evaluate yt1 and give you a symbolic value, on which you can use double() to convert to a numeric value.
syms s
fs = (-2*(s-1))/((s+1)*(s+2));
fs1 = (1/s)*fs;
yt1 = ilaplace(fs1)
yt1 = 
t = 0;
yt1_0 = subs(yt1);
t = Inf;
yt1_inf = subs(yt1);
display(yt1_0); display(yt1_inf);
yt1_0 = 
0
yt1_inf = 
1
yt1_0 = double(yt1_0);
yt1_inf = double(yt1_inf);
display(yt1_0); display(yt1_inf);
yt1_0 = 0
yt1_inf = 1
  1 件のコメント
Voss
Voss 2022 年 1 月 23 日
Better yet, do both values of t at once:
syms s
fs = (-2*(s-1))/((s+1)*(s+2));
fs1 = (1/s)*fs;
yt1 = ilaplace(fs1)
yt1 = 
t = [0 Inf];
yt1_0_inf = subs(yt1);
display(yt1_0_inf);
yt1_0_inf = 
yt1_0_inf = double(yt1_0_inf);
display(yt1_0_inf);
yt1_0_inf = 1×2
0 1

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by