Solving ODE using laplace

조회 수: 16 (최근 30일)
LUCA
LUCA 2024년 4월 21일
편집: Torsten 2024년 4월 21일
This is the question I'm struggling on
Using the Laplace transform find the solution for the following ODE:
d^2/dt(y(t)) + 16y(t) = 16[1(t-3) -1(t)]
initial conditions:
y(0) = 0
dy(t)/dt = 0
I have to solve the ODE with laplace and with inverse laplace
Save the inverse laplace in y_sol.
This is what I wrote but it gives me the wrong answer:
syms t s y(t) Y X
y0 = 0;
dot_y0 = 0;
dot_y = diff(y,t);
ddot_y = diff(dot_y,t);
ode = ddot_y + 16*y == 16*(1*(t-3)-1*(t))
ode(t) = 
Y1 = laplace(ode,t,s)
Y1 = 
ysol1 = subs(Y1,laplace(y,t,s),X)
ysol1 = 
ysol2 = subs(ysol1,y(0),y0)
ysol2 = 
ysol3 = subs(ysol2, subs(diff(y(t), t), t, 0), dot_y0)
ysol3 = 
ysol = solve(ysol3, X)
ysol = 
Y = simplify(expand(ysol))
Y = 
y_sol = ilaplace(Y)
y_sol = 
  댓글 수: 7
Sam Chak
Sam Chak 2024년 4월 21일
I didn't simplify the analytical solution from dsolve, but it seems to yield the similar plot as WolframAlpha.
sympref('HeavisideAtOrigin', 1);
syms y(t) t s
dy = diff( y,t);
ddy = diff(dy,t);
massSpring = ddy + 16*y == 16*(heaviside(t-3) - heaviside(t))
massSpring(t) = 
sol = dsolve(massSpring, y(0) == 0, dy(0) == 0)
sol = 
fplot(sol, [0 13]), grid on, xlabel('t'), title('y(t)')
Torsten
Torsten 2024년 4월 21일
편집: Torsten 2024년 4월 21일
syms t s y(t) Y X
y0 = 0;
dot_y0 = 0;
dot_y = diff(y,t);
ddot_y = diff(dot_y,t);
ode = ddot_y + 16*y == 16*(heaviside(t-3)-heaviside(t));
Y1 = laplace(ode,t,s);
ysol1 = subs(Y1,laplace(y,t,s),X);
ysol2 = subs(ysol1,y(0),y0);
ysol3 = subs(ysol2, subs(diff(y(t), t), t, 0), dot_y0);
ysol = solve(ysol3, X);
Y = simplify(expand(ysol));
y_sol = ilaplace(Y)
y_sol = 
Check_Laplace_Solution = dsolve(ode, y(0) == 0, dot_y(0) == 0)
Check_Laplace_Solution = 
hold on
fplot(y_sol,[0 13])
fplot(Check_Laplace_Solution,[0 13])
hold off
grid on

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

답변 (1개)

Star Strider
Star Strider 2024년 4월 21일
Your code looks correct to me, and when I checked the result with dsolve, its solution agreees with yours —
syms t s y(t) Y X
y0 = 0;
dot_y0 = 0;
dot_y = diff(y,t);
ddot_y = diff(dot_y,t);
ode = ddot_y + 16*y == 16*(1*(t-3)-1*(t))
ode(t) = 
Y1 = laplace(ode,t,s)
Y1 = 
ysol1 = subs(Y1,laplace(y,t,s),X)
ysol1 = 
ysol2 = subs(ysol1,y(0),y0)
ysol2 = 
ysol3 = subs(ysol2, subs(diff(y(t), t), t, 0), dot_y0)
ysol3 = 
ysol = solve(ysol3, X)
ysol = 
Y = simplify(expand(ysol))
Y = 
y_sol = ilaplace(Y)
y_sol = 
Check_Laplace_Solution = dsolve(ode, y(0) == 0, dot_y(0) == 0)
Check_Laplace_Solution = 
.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by