Laplace transform for ODE with piecewise forcing function

clearvars
syms s t Y
We want to solve the initial value problem
where the forcing function is defined as a piecewise function:

Step 1: Rewrite f(t) using step function

We can rewrite a piecewise defined function using the unit step function (Heaviside function) as follows
Here we obtain
f = t + heaviside(t-1)*(-t);
fplot(f,[0 6]); title('forcing function f(t)')

Step 2: Find Laplace transform

We have
For the first term we get
For the second term we use the following rule:

Here , so .
Now we find .
This gives
F = laplace(f)
F = 

Step 3: Find Laplace transform of left hand side and solve for

We have
Y1 = s*Y-0;
Y2 = s*Y1-0;
We obtain
Sol = simplify( solve(Y2+3*Y1+2*Y==F,Y) ,1000)
Sol = 
collect(Sol,'exp')
ans = 

Step 4: Find inverse Laplace transform

We obtained with rational functions
We need to find the partial fraction decomposition for and :
R1 = partfrac(1/(s^2*(s + 1)*(s + 2)))
R1 = 
R2 = partfrac((-1/(s^2*(s + 2))))
R2 = 
The solution is given by
It is clear how to find :
ilaplace(R1)
ans = 
For we use the rule

We first find
g = ilaplace(R2)
g = 
We then obtain
In Matlab we can just apply ilaplace to Sol:
sol = ilaplace(Sol)
sol = 
fplot(sol,[0 6]); title('solution y(t)'); axis auto
We can collect the terms with 'heaviside':
sol = collect(sol,'heaviside')
sol = 
We can rewrite this as a "piecewise defined function":
sol = rewrite(sol,'piecewise')
sol = 
We can see that the solution for converges to zero as .