Example 4 (Periodic Function)
In[81]:=
Clear[f]
f[t_]:=(UnitStep[t]-UnitStep[t-Pi])-(UnitStep[t-Pi]-UnitStep[t-2 Pi])+
(UnitStep[t-2 Pi]-UnitStep[t-3 Pi])-(UnitStep[t-3 Pi]-UnitStep[t-4 Pi])
Plot[Evaluate[f[t]],{t,0,4 Pi}];

The function is written in that way for your benefit. If you had a longer interval, you would need to be clever about it.
In[82]:=
Clear[g]
g[t_]:=Sum[(-1)^k (UnitStep[t-k Pi]-UnitStep[t-(k+1) Pi]),{k,0,7}]
Plot[Evaluate[g[t]],{t,0,8 Pi}];

In[83]:=
Clear[de,tde,newtde,Y,y]
Here's the differential equation:
In[84]:=
de=y''[t]+3 y'[t]+2 y[t]==f[t]
Out[84]=
2 y[t] + 3 y'[t] + y''[t] ==
UnitStep[t] + UnitStep[-4 Pi + t] - 2 UnitStep[-3 Pi + t] +
2 UnitStep[-2 Pi + t] - 2 UnitStep[-Pi + t]
Here is the transformed differential equation:
In[85]:=
tde=LaplaceTransform[de,t,s]
Out[85]=
2
2 LaplaceTransform[y[t], t, s] + s LaplaceTransform[y[t], t, s] +
3 (s LaplaceTransform[y[t], t, s] - y[0]) - s y[0] - y'[0] ==
1 1 2 2 2
- + --------- - --------- + --------- - -------
s 4 Pi s 3 Pi s 2 Pi s Pi s
E s E s E s E s
Let's make use of the initial values:
In[86]:=
newtde=tde/.{y[0]->0,y'[0]->0}
Out[86]=
2 LaplaceTransform[y[t], t, s] +
3 s LaplaceTransform[y[t], t, s] +
2
s LaplaceTransform[y[t], t, s] ==
1 1 2 2 2
- + --------- - --------- + --------- - -------
s 4 Pi s 3 Pi s 2 Pi s Pi s
E s E s E s E s
Now solve this equation for Y[s].
In[87]:=
Solve[newtde,LaplaceTransform[y[t],t,s]];
Y[s_]:=Evaluate[LaplaceTransform[y[t],t,s]/.Flatten[%]]
Y[s]
Out[87]=
Pi s 2 Pi s 3 Pi s 4 Pi s
-1 + 2 E - 2 E + 2 E - E
-(----------------------------------------------)
4 Pi s 2
E s (2 + 3 s + s )
Expect to wait for this one. Maybe go out for lunch.
In[88]:=
y[t_]:=InverseLaplaceTransform[Y[s],s,t]
y[t]
Out[88]=
8 Pi - 2 t
1 1 -t 1 E 4 Pi - t
- + ------ - E + (- + ----------- - E )
2 2 t 2 2
2 E
6 Pi - 2 t 3 Pi - t
UnitStep[-4 Pi + t] + (-1 - E + 2 E )
4 Pi - 2 t 2 Pi - t
UnitStep[-3 Pi + t] + (1 + E - 2 E )
2 Pi - 2 t Pi - t
UnitStep[-2 Pi + t] + (-1 - E + 2 E )
UnitStep[-Pi + t]
In[89]:=
Plot[Evaluate[y[t]],{t,0,4 Pi}];

Up to Solving Constant Coefficient Initial Value Problems with Special Forcing Functions