MATLAB: How to put the step function into the differential equation solution, h.. in this case

differential equationlaplace transformstep function

syms s t Y;
warning('off')
t=0:0.001:10;
h=4*t.*(heaviside(t)-heaviside(t-1))+4*(heaviside(t-1))
figure (4)
plot(t,h);axis([0,10,0,6])
ode='D(D(y))(t)+4*y(t)=h';
solg=laplace(ode,t,s);
solp=subs(solg,{'laplace(y(t),h,t,s)','y(0)','D(y)(0)'},{Y,1,0});
Y=(solve(solp,Y))
yt=ilaplace(Y,s,t)
figure (5)
fplot(yt,[0 10])
title('ODE Solution')
xlabel ('Time [sec] ')
ylabel( 'Amplitude [m]')

Best Answer

I do not understand what you are trying to do. The approach I would take would be
syms y(t) s
eqn = diff(y(t), t, t)+4*y(t) == 4*t*(heaviside(t)-heaviside(t-1))+4*heaviside(t-1)
ode = dsolve(eqn, y(0)==1, subs(diff(y(t),t),t,0)==0)
laplace(ode, t, s)
I would not attempt a laplace before doing the dsolve because at that point the equation has not been sufficiently resolved to do a laplace. The h part has a nice laplace transform but the other side does not.
But if you must...
syms y(t) s Y
eqn = diff(y(t), t, t)+4*y(t) == 4*t*(heaviside(t)-heaviside(t-1))+4*heaviside(t-1)
sol = ilaplace( solve( subs(laplace(eqn, t, s), laplace(y(t), t, s), Y), Y), s, t)
yt = subs(sol, {y(0), sym('D(y)(0)')}, {1, 0})