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

조회 수: 1 (최근 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
VBBV
VBBV 2020년 10월 19일
편집: Walter Roberson 2020년 10월 19일
You missed a parenthesis on right )
fplot(matlabFunction(t1))
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
Walter Roberson
Walter Roberson 2024년 1월 18일
(The fplot of G got fixed at some point.)

댓글을 달려면 로그인하십시오.

추가 답변 (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