ilaplace() function is giving wrong results

HI,
I am using ilaplace() function to transform a function with this aspect
The temporal form of that function is a linear combination of a constant term and two exponentials.
I am particularly interested in noting that f(t) is a linear combination of a,b, and c. If I run this code
syms s t a b c d e f;
Fs = (a*s^2+b*s+c)/(s*(d*s^2+e*s+f));
ft = ilaplace(Fs)
The result is
Which IMHO is NOT a linear combination of a, b, and c. Why am I getting this? The result seems wrong to me.
Thanks in advanced.
EDIT:
Found the solution. Just use this function before applyting inverse Laplace tansform to F.
partfrac(F,'FactorMode','complex')

1 comentario

Walter Roberson
Walter Roberson el 3 de Sept. de 2020
Maple agrees with MATLAB as to what the inverse laplace transform is.

Iniciar sesión para comentar.

Respuestas (1)

David Goodmanson
David Goodmanson el 3 de Sept. de 2020
Editada: David Goodmanson el 7 de Sept. de 2020
Hi David,
plugging in
cosh(z) = ((exp(z) + exp(-z))/2
sinh(z) = ((exp(z) - exp(-z))/2
results in a constant and two exponentials, as you said.
Note that in the expression for #1, the d in the denominator belongs in the argument for the square root. It does not belong under the entire expression. The fraction bar is too long, and it looks quite likely that the expression for ft has similar problems.
If you want to find the coefficients of the exponentials with a minimum of fuss, the following works.
<< the original question has been modified and includes the form shown here below >>
Find the roots of (d*s^2 + e*s + f), and reverse their signs to obtain r1,r2. Then
F(s) = (a*s^2+b*s+c) / (d*s*(s+r1)*(s+r2))
The solution has the form A0 + A1* exp(-r1*t) + A2*exp(-r2*t).
For A0, evaluate F(s) at s = 0, neglecting s in the denominator.
For A1, evaluate F(s) at s = -r1, neglecting (s+r1) in the denominator.
For A2, evaluate F(s) at s = -r2, neglecting (s+r2) in the denominator.

8 comentarios

David
David el 4 de Sept. de 2020
Editada: David el 4 de Sept. de 2020
Hi David,
Thanks for taking the time. The bigger problem is the following. I use ilaplace() in order to obtain a symbolic temporal function that is evaluated at a certain value of the time. As a result, I should have an equation with a number of variables (say a, b, and c in our example).
I repeat that with a number of expressions in order to obtain a system of linear equations. Well, MATLAB says the system is not that linear...
Error using mupadengine/feval_internal
Unable to convert to matrix form because the system does not seem to be linear.
Error in sym/equationsToMatrix (line 61)
T = eng.feval_internal('symobj::equationsToMatrix',eqns,vars);
Error in HVCon (line 142)
[A,B] = equationsToMatrix(eqn, [VCflyi VCparBoti VCparTopi VCflyf VCparBotf VCparTopf Vo]);
I was debugging when I found that odd symbolic expression with cosh and sinh. The result should be a linear combination of coefficients a, b, and c from
Fs = (a*s^2+b*s+c)/(s*(d*s^2+e*s+f));
But the obtained expression doesn't seem linear!
In conclusion, as a far as I see, ilaplace() is transforming an 's' expression which is linearly dependent of coefficients a, b, and c into a 't' expression which is non-linearly dependent of those coefficients.
Thanks again.
Walter Roberson
Walter Roberson el 4 de Sept. de 2020
You might be able to get somewhere with rewrite()
However, it might require the more obscure and tricky mapSymType()
David
David el 4 de Sept. de 2020
The function rewrite() does replace the cosh and sinh functions with its exponential equivalents but the resulting expression is still not a linear combination of a, b, and c...
Sometimes you have to go through a mess of rewrite() and simplify() to push it into the form you want. But if a direct rewrite() does not work, then typically the chain to force in into a good form is fragile and could stop working at the next release.
So sometimes you are forced to use mapSymType(), which is more powerful but is also not quite designed properly, and so can get frustrating to use. Frustrating enough that anyone who knows the Symbolic Toolbox well enough to use mapSymType effectively is more likely to just drop into some evalin(symengine) or feval(symengine) to push the symbolic engine in productive ways.
In your case you might want to use mapSymType to implement the rule that David suggested,
cosh(z) = ((exp(z) + exp(-z))/2
It isn't pretty, but:
cosh2exp = @(z) (exp(z) + exp(-z))/2;
mapSymType(ft,'cosh',@(f) cosh2exp(children(f)))
and likewise for sinh
David
David el 4 de Sept. de 2020
Editada: David el 4 de Sept. de 2020
Thanks for your time Walter.
After implenting your suggestion, I have this code
syms s t a b c d e f;
Fs = (a*s^2+b*s+c)/(s*(d*s^2+e*s+f));
ft = ilaplace(Fs);
cosh2exp = @(z) (exp(z) + exp(-z))/2;
ft = mapSymType(ft,'cosh',@(f) cosh2exp(children(f)));
sinh2exp = @(z) (exp(z) - exp(-z))/2;
ft = mapSymType(ft,'sinh',@(f) sinh2exp(children(f)))
The result is
Again, I have to make sure that f(t) is a linear combination of a, b, and c. In the expression I obtain, there is an odd fraction that led me think that the expression was not a linear combination of a, b, and c but it you carefully look at the whole expression I think that the denominator is canceled and everythin is OK.
(b*f-c*e)/(a*f-c*d)
However, in my real problem I have a bunch of laplace expressions which are inverted and then evaluted at a certain value of time. Thus, I have a system of equations in which coefficients a, b, and c contains the variables. When I try to solve the problem (it should be a system of 29 linear equations and 29 variables), I get this error
Error using mupadengine/feval_internal
Unable to convert to matrix form because the system does not seem to be linear.
Error in sym/equationsToMatrix (line 61)
T = eng.feval_internal('symobj::equationsToMatrix',eqns,vars);
I think this is because my simbolic expressions contain numbers and symbolic variables. This somehow is preventing MATLAB from correctly simplify the expression as I noted before.
Walter Roberson
Walter Roberson el 4 de Sept. de 2020
Did you already separate out the exponential term? The presenses of the exponential term would be enough for it to complain about it not being linear.
David
David el 4 de Sept. de 2020
Exponential terms are gone once the function is evaluated at a certain value of time. The only variables are inside coefficients a, b, and c, which are not inside any exponential.
David
David el 4 de Sept. de 2020
Editada: David el 4 de Sept. de 2020
I wrote a MWE of the whole problem. If I enter the laplace functions with the second order polynomial in the denominator, the non-linear problem arise.
syms s t a b c;
Fs1 = (100*a*s^2+98493*b)/(s*(784937*s^2+890384*s+8374));
Fs2 = (45450*a*s+983*c)/(s*(784337*s^2+8384*s-34));
Fs3 = (545*b*s+98563*c)/(s*(4337*s^2+834*s+345454));
ft1 = vpa(ilaplace(Fs1));
ft2 = vpa(ilaplace(Fs2));
ft3 = vpa(ilaplace(Fs3));
eqn1 = c == subs(ft1, 10);
eqn2 = b == subs(ft2, 10);
eqn3 = a == subs(ft3, 10);
[A, B] = equationsToMatrix([eqn1, eqn2, eqn3]);
However, if I replace the second order polynomial with its two roots, everything works fine.
syms s t a b c;
Fs1 = (100*a*s^2+98493*b)/(s*(s-1.1249)*(s-0.0095));
Fs2 = (45450*a*s+983*c)/(s*(s-0.0138)*(s+0.0031));
Fs3 = (545*b*s+98563*c)/(s*(s-9.0215)*(s+8.8282));
ft1 = vpa(ilaplace(Fs1));
ft2 = vpa(ilaplace(Fs2));
ft3 = vpa(ilaplace(Fs3));
eqn1 = c == subs(ft1, 10);
eqn2 = b == subs(ft2, 10);
eqn3 = a == subs(ft3, 10);
[A, B] = equationsToMatrix([eqn1, eqn2, eqn3]);

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 3 de Sept. de 2020

Editada:

el 7 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by