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

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2020-10-19
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);

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-10-18
编辑:Walter Roberson 2020-10-19
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 个评论
Walter Roberson
Walter Roberson 2020-10-19
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by