How do I plot an Inverse Laplace? (symbolic to vectorized equations)

2 views (last 30 days)
I am having trouble plotting the following inverse Laplace functions. Not sure what I am doing wrong.
syms s t
F1 = (6*s + 18)/(s^4 + 6*s^3 + 11*s^2 + 24*s);
F2 = (12*s + 36)/(s^4 + 6*s^3 + 11*s^2 + 42*s);
F3 = (18*s + 54)/(s^4 + 6*s^3 + 11*s^2 + 60*s);
F4 = (24*s + 72)/(s^4 + 6*s^3 + 11*s^2 + 78*s);
t1 = ilaplace(F1); t2 = ilaplace(F2);
t3 = ilaplace(F3); t4 = ilaplace(F4);
fplot(matlabFunction(t1);
Any Help would be greatly appreciated. Thanks.
  2 Comments
VBBV
VBBV on 19 Oct 2020
Edited: Walter Roberson on 19 Oct 2020
You missed a parenthesis on right )
fplot(matlabFunction(t1))
Walter Roberson
Walter Roberson on 19 Oct 2020
Yes, but even if you provide that, matlabFunction() is going to give an error
Error using symengine
Code generation failed due to unexpected object of type 'RootOf'.
Error in sym/matlabFunction>mup2mat (line 404)
res = mupadmex('symobj::generateMATLAB',r.s,ano,spa,0);
Error in sym/matlabFunction>mup2matcell (line 374)
r = mup2mat(c{1},true,sparseMat);
Error in sym/matlabFunction (line 188)
body = mup2matcell(funs, opts.Sparse);

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Oct 2020
Edited: Walter Roberson on 19 Oct 2020
As is not uncommon, the inverse laplace of that particular function is defined in terms of a quantity evaluated over the sum of the roots of a polynomial (in this case a polynomial of degree 3), with the user seeing unresolved calls to root() in the results.
However by default the symbolic engine only creates explicit solutions for degree 2, and does not offer any mechanism to convert the root() placeholder calls into explicit roots (which would be possible for degree 3 or 4, and occassionally higher degrees but mostly not.)
I could possibly write some code that used mapSymType to rewrite as explicit roots; it would require that I dig into the MuPAD symbolic engine to figure out how to get it to return an explicit root given an index... it would take me a while. And it would only be useful if you had Good Reasons for wanting exact formulas for the roots, even though those are typically pretty long.
In the meantime, for your purposes, the workaround is
fplot(matlabFunction(vpa(t1)));
Or just
fplot(vpa(t1))
As fplot() is generally happy with symbolic expressions without using matlabFunction, you could try
fplot(t1)
but in practice you will get an empty plot... which is probably a bug, and I will report that.
  4 Comments
Walter Roberson
Walter Roberson on 19 Oct 2020
Further testing shows that the problem is with the root() not with the symsum() .
syms t s4
G=sum(exp(t*solve(s4^3 + 6*s4^2 + 11*s4 + 24, s4)))
G = 
fplot(G) %fails
H=sum(exp(t*solve(s4^3 + 6*s4^2 + 11*s4 + 24, s4, 'MaxDegree',3)))
H = 
fplot(H) %works

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!