How to quickly "plug in" numerical values into symbolic equations to get a numerical result
조회 수: 46 (최근 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!