Solving ODE using laplace

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 Comments

I guess 1(t-3) and 1(t) are dirac(t-3) and dirac(t), not 1*(t-3) and 1*t.
That may be correct. I certainly didn’t interpret the ‘1*’ notation as the delta function.
Torsten
Torsten on 21 Apr 2024
Edited: Torsten on 21 Apr 2024
Not '1*', just '1'.
I think the notation is quite common for the indicator function:
But I'm not sure how it translates to a known Matlab function.
1(t), as in the question, most likely means the unit step function. I’d be surprised if it means 1*t.
Considering that this appears to be a homework question at a typical undergraduate level, and given that the initial values start from zero, I am inclined to agree with @Paul's interpretation of as the unit step function, a.k.a. the Heaviside function. It seems that the original poster may not be proficient in properly expressing mathematical notations, which naturally leads to the interpretation of the missing asterisk as a multiplication operator between two values.
Additionally, it appears that the undamped mass-spring system has an analytical solution, though I'm unsure how to get that from Inverse Laplace Transform.
%% Input signal
sympref('HeavisideAtOrigin', 1);
t = 0:0.001:6;
u = 16*(heaviside(t-3) - heaviside(t));
plot(t, u, 'linewidth', 1.5), grid on, ylim([-25 25]), xlabel('t'), title('u(t)')
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)')
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

Sign in to comment.

Answers (1)

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 = 
.

Categories

Tags

Asked:

on 21 Apr 2024

Edited:

on 21 Apr 2024

Community Treasure Hunt

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

Start Hunting!