How to quickly "plug in" numerical values into symbolic equations to get a numerical result
34 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Voss
am 23 Jan. 2022
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 Kommentar
Voss
am 23 Jan. 2022
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Conversion Between Symbolic and Numeric finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!