%% Example for forcing function with Dirac deltas
% Solve the initial value problem
%          y''+3y'+2y=2\delta(t-1)-3\delta(t-2),\qquad y(0)=0,\quad y'(0)=0

clearvars
syms s t Y 
f = 2*dirac(t-1)-3*dirac(t-2)

% Matlab plots dirac(t) as a zero function, so we don't need to plot the function f.

F = laplace(f)
Y1=s*Y-0; Y2 = s*Y1-0;
Sol = solve(Y2+3*Y1+2*Y==F,Y)
partfrac(1/(s^2+3*s+2))
sol = ilaplace(Sol)
fplot(sol,[0 6]); xlabel('t'); title('solution y(t)'); ax_origin

% We can see that at t=1 the function y'(t) has a jump of 2, and at t=2 the function y'(t) has a jump of -3.

fplot(diff(sol),[0 6]); xlabel('t'); title('derivative y''(t)'); ax_origin
simplify( diff(sol) )

%
% Draw the x and y axes through the origin:

function ax_origin
  set(gca,'XAxisLoc','origin','YAxisLoc','origin'); box off
end