How to quickly "plug in" numerical values into symbolic equations to get a numerical result
171 次查看(过去 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
0 个评论
采纳的回答
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)
t = 0;
yt1_0 = subs(yt1);
t = Inf;
yt1_inf = subs(yt1);
display(yt1_0); display(yt1_inf);
yt1_0 = double(yt1_0);
yt1_inf = double(yt1_inf);
display(yt1_0); display(yt1_inf);
1 个评论
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)
t = [0 Inf];
yt1_0_inf = subs(yt1);
display(yt1_0_inf);
yt1_0_inf = double(yt1_0_inf);
display(yt1_0_inf);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!