Solving equations using Laplace transform

I am trying to solve an equation using the Laplace transform without having to find the Laplace transforms of the terms in the equation. Matlab is unable to find a solution based on the code below, although a solution can be found by writing the terms as a function of s. Could someone please suggest a method to do this?
syms y(t)
Dy2 = diff(y,t,2); Dy1 = diff(y,t,1);
eqn = laplace(Dy2+3*Dy1+2*y) == laplace(exp(-t))
cond = [y(0)==4, Dy(0)==5];
sol = dsolve(eqn,cond)
f

 Respuesta aceptada

Star Strider
Star Strider el 14 de En. de 2021
Unless you are solving a partial differential equation, such that the Laplace transform produces an ordinary differential equation in one of the two variables and a Laplace transform of ‘t’, dsolve is not appropriate. It is simply necessary to solve for (in this instance) ‘Y(s)’ and then invert it to get ‘y(t)’:
syms t y(t) Y(s) Dy0
Dy2 = diff(y,t,2);
Dy1 = diff(y,t,1);
eqn = laplace(Dy2+3*Dy1+2*y == exp(-t))
eqn = subs(eqn, {laplace(y(t), t, s), subs(diff(y(t), t), t, 0)},{Y(s), Dy0})
cond = [y(0)==4, Dy1(0)==5];
Soln_s = isolate(eqn, Y(s))
Soln_t = ilaplace(Soln_s)
Soln_t = subs(Soln_t, {ilaplace(Y(s), s, t)}, {y(t)})
Soln_t = simplify(Soln_t, 'Steps',500)
.

6 comentarios

Aleem Andrew
Aleem Andrew el 14 de En. de 2021
Thank you for your help
Star Strider
Star Strider el 14 de En. de 2021
As always, my pleasure!
I made a small modification by replacing Dy0 with 5 so the value of Dy0 is output. Could you please tell me how y(0) can also be output in the soln_t variable instead of the symbolic variable y(0)?
syms t y(t) Y(s) Dy0
Dy2 = diff(y,t,2);
Dy1 = diff(y,t,1);
eqn = laplace(Dy2+3*Dy1+2*y == exp(-t))
eqn = subs(eqn, {laplace(y(t), t, s), subs(diff(y(t), t), t, 0)},{Y(s), 5})
cond = [y(0)==4, Dy1(0)==5];
Soln_s = isolate(eqn, Y(s))
Soln_t = ilaplace(Soln_s)
Soln_t = subs(Soln_t, {ilaplace(Y(s), s, t)}, {y(t)})
Soln_t = simplify(Soln_t, 'Steps',500)
My apologies for forgetting about the ‘cond’ variable, since the laplace transforms do not allow initial conditions to be included, as they would in dsolve. (I submitted an enhancement request about that a few years ago. It apparently has not yet been implemented.)
Changing this ‘eqn’ subs call will replace both of the ‘cond’ variables appropriately:
eqn = subs(eqn, {laplace(y(t), t, s), subs(diff(y(t), t), t, 0), y(0)},{Y(s), 5, 4})
producing in the end:
Soln_t =
exp(-t)*(t + 12) == 8*exp(-2*t) + y(t)
and with the addition of:
Soln_t = isolate(Soln_t, y)
after that line, producing:
Soln_t =
y(t) == exp(-t)*(t + 12) - 8*exp(-2*t)
.
Aleem Andrew
Aleem Andrew el 14 de En. de 2021
Thank you. You have been very helpful
Star Strider
Star Strider el 14 de En. de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Logeshwari S
Logeshwari S el 19 de Nov. de 2021

0 votos

clear all clc syms x w f=input('Enter the function of x: '); F=laplace(f,x,w); disp('Laplace transform of f(t) = '); disp(F);

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 14 de En. de 2021

Respondida:

el 19 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by