# Preface

This tutorial was made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in normal font. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

# Solving IVPs with Laplace transform

Laplace transforms can be used as an alternative to the methods for solving initial value problems for linear differential equations with constant coefficients that were considered previously. The basic idea of using Laplace transform is to apply an (as yet underfined) transformation $${\cal L}$$ to both sides of a differential equation, thus converting the differential equation into an algebraic equation. Then, the algebraic equation is solved for the transform of the unknown function, and the inverse transform $${\cal L}^{-1}$$ is applied to both sides of the solved equation, thus yielding the solution to the differential equation.

Schematically, this process can be illustrated starting with, for example, a second order linear differential equation with constant coefficients, as follows.

\begin{eqnarray*} a\,y'' + b\, y' + c\,y &=& f (t) \\ &\Downarrow & \quad \mbox{apply } {\cal L}\\ {\cal L} \left[ a\,y'' + b\, y' + c\,y \right] &=& {\cal L} \left[ f (t) \right] \\ &\Downarrow & \quad \mbox{solve for } {\cal L}[y] = y^L \\ y^L \equiv {\cal L} \left[ f (t) \right] &=& F(\lambda ) \\ &\Downarrow & \quad \mbox{apply } {\cal L}^{-1} \\ y(t) &=& {\cal L}^{-1} \left[ F(\lambda ) \right] . \end{eqnarray*}
Of course, some details need to be addressed for this to make sense. In particular, we need to express the left side $${\cal L} \left[ a\,y'' + b\, y' + c\,y \right]$$ in terms of $${\cal L} \left[ y \right] = y^L .$$ We illustrate the method with examples.

Example: Consider the initial value problem

$y'' + 5\, y' +6\,y = \sin 2t , \qquad y(0) =-1, \quad y' (0) =2 .$
Applying the Laplace transform, we get
$\lambda^2 y^L - y' (0) - \lambda\,y(0) + 5\,\lambda \, y^L - 5\,y(0) +6\,y^L = \frac{2}{\lambda^2 +4} ,$
where
$y^L ( \lambda ) = {\cal L}\left[ y(t) \right] = \int_0^{\infty} e^{-\lambda\,t} \,y(t)\,{\text d} t$
is the Laplace transform of the unknown solution. Solving the above algebraic equation, we find
$y^L ( \lambda ) = -\frac{\lambda +3}{\lambda^2 +5\lambda +6} + \frac{1}{\lambda^2 +5\lambda +6} \cdot \frac{2}{\lambda^2 +4} .$
Since it is the sum of two fractions, we apply the inverse Laplace transform to each of them
\begin{eqnarray*} y_h (t) &=& {\cal L}^{-1} \left[ \frac{-\lambda -3}{(\lambda +2)(\lambda +3)} \right] = \left( \mbox{Res}_{\lambda = 2} + \mbox{Res}_{\lambda = 3} \right) \frac{-\lambda -3}{(\lambda +2)(\lambda +3)} \, e^{\lambda\, t} \\ &=& - e^{2t} - \frac{6}{5}\, e^{3t} , \end{eqnarray*}
which we have to multiply by the Heaviside function.

The denominator in the second term has two real nulls $$\lambda =2$$ and $$\lambda =3$$ and two complex conjugate $$\lambda = \pm 2{\bf j} .$$ We calculate residues at each pole separately.

\begin{eqnarray*} \mbox{Res}_{\lambda = 2} \, \frac{e^{\lambda\,t}}{\lambda^2 +5\lambda +6} \cdot \frac{2}{\lambda^2 +4} &=& \lim_{\lambda \to 2} \, \frac{e^{\lambda\,t}}{2\lambda +5} \cdot \frac{2}{\lambda^2 +4} = \frac{1}{36}\, e^{2t} , \\ \mbox{Res}_{\lambda = 3} \, \frac{e^{\lambda\,t}}{\lambda^2 +5\lambda +6} \cdot \frac{2}{\lambda^2 +4} &=& \lim_{\lambda \to 3} \, \frac{e^{\lambda\,t}}{2\lambda +5} \cdot \frac{2}{\lambda^2 +4} = \frac{2}{143} \, e^{3t} , \\ \mbox{Res}_{\lambda = 2{\bf j}} \, \frac{e^{\lambda\,t}}{\lambda^2 +5\lambda +6} \cdot \frac{2}{\lambda^2 +4} &=& \lim_{\lambda \to 2{\bf j}} \,\frac{e^{\lambda\,t}}{\lambda^2 +5\lambda +6} \cdot \frac{2}{2\,\lambda} \\ \frac{1}{2(5{\bf j} +1)} \cdot \frac{1}{2{\bf j}} \, e^{2{\bf j}t} = -\frac{1}{4} \left( \frac{5}{52} + \frac{\bf j}{52} \right) e^{2{\bf j}t} . \end{eqnarray*}
Extracting the real part and multiplying by 2, we obtain
${\cal L} \left[ y_p^L \right] = {\cal L} \left[ \frac{1}{\lambda^2 +5\lambda +6} \right] = \left[ \frac{\sin 2t}{104} -\frac{5\,\cos 2t}{104} + \frac{1}{36}\, e^{2t} + \frac{2}{143} \, e^{3t} \right] H(t) .$
LaplaceTransform[{y''[t] + 5 y'[t] + 6 y[t] == Sin[2 t], y[0] == -1, y'[0] == 2}, t, lambda]
Out[2]= {6 LaplaceTransform[y[t], t, lambda] + lambda^2 LaplaceTransform[y[t], t, lambda] +
5 (lambda LaplaceTransform[y[t], t, lambda] - y[0]) - lambda y[0] -
Derivative[1][y][0] == 2/(4 + lambda^2), (y[0] == -1)/lambda, ( Derivative[1][y][0] == 2)/lambda}
LaplaceTransform[y''[t] + 5 y'[t] + 6 y[t] == Sin[2 t], t, lambda];
% /. {y[0] -> -1, y'[0] -> 5}
Out[3]= -5 + lambda + 6 LaplaceTransform[y[t], t, lambda] +
lambda^2 LaplaceTransform[y[t], t, lambda] +
5 (1 + lambda LaplaceTransform[y[t], t, lambda]) == 2/(4 + lambda^2)
Solve[%, LaplaceTransform[y[t], t, lambda]]
Out[4]= {{LaplaceTransform[y[t], t, lambda] -> (
2 - 4 lambda - lambda^3)/((4 + lambda^2) (6 + 5 lambda + lambda^2))}}
InverseLaplaceTransform[%, lambda, t]
Out[5]= {{y[t] -> -(41/13) E^(-3 t) + (9 E^(-2 t))/4 + 1/52 (-5 Cos[2 t] + Sin[2 t])}}
v[t_] = y[t] /. % ;
Plot[v[t], {t, 0, 9}]

Example: Consider the initial value problem

$y'' -3\, y' -4\,y = -16\,t , \qquad y(0) =-4, \quad y' (0) =-5 .$
Its solution is the sum $$y(t) = y_h (t) + y_p (t)$$ of two functions, one of them, yh is the solution of the homogeneous equation subject to the given initial conditions
$y'' -3\, y' -4\,y = 0 , \qquad y(0) =-4, \quad y' (0) =-5 .$
Using the general formula, we find the Laplace transform of it:
$y_h^L = \frac{a \left( \lambda\,y(0) + y' (0) \right) + b\,y(0)}{a\lambda^2 + b\lambda +c} = \frac{7-4\lambda}{\lambda^2 -3\lambda -4} .$
Another function, yp is the particular solution of the inhomogeneous equation subject to homogeneous initial conditions
$y'' -3\, y' -4\,y = -16\,t , \qquad y(0) =0, \quad y' (0) =0 .$
Its Laplace transform is
$y_p^L = \frac{1}{\lambda^2 -3\lambda -4} \cdot {\cal L} \left[ -16\,t \right] = - \frac{16}{\lambda^2 \left( \lambda^2 -3\lambda -4 \right)} .$
Therefore, to determine the required solution, we need to find the inverse Laplace transforms of these functions and add them. We start with yh:
\begin{eqnarray*} y_h (t) &=& {\cal L}^{-1} \left[ \frac{7-4\lambda}{\lambda^2 -3\lambda -4} \right] = \left( \mbox{Res}_{\lambda = 4} + \mbox{Res}_{\lambda = -1} \right) \frac{7-4\lambda}{\lambda^2 -3\lambda -4} \, e^{\lambda\, t} \\ &=& \left. \frac{7-4\lambda}{2\lambda -3} \, e^{\lambda\, t} \right\vert_{\lambda = 4} + \left. \frac{7-4\lambda}{2\lambda -3} \, e^{\lambda\, t} \right\vert_{\lambda = -1} \\ &=& -\frac{9}{5}\, e^{4t} - \frac{11}{4}\, e^{-t} , \end{eqnarray*}
which we have to multiply by the Heaviside function. Now we find the inverse Laplace transform of the second function:
\begin{eqnarray*} y_p (t) &=& {\cal L}^{-1} \left[ - \frac{16}{\lambda^2 \left( \lambda^2 -3\lambda -4 \right)} \right] = \left( \mbox{Res}_{\lambda = 4} + \mbox{Res}_{\lambda = -1} + \mbox{Res}_{\lambda = 0} \right) \frac{-16}{\lambda^2 \left( \lambda^2 -3\lambda -4 \right)} \, e^{\lambda\, t} \\ &=& \left. \frac{-16}{\lambda^2 \left( 2\lambda -3 \right)} \, e^{\lambda\, t} \right\vert_{\lambda = 4} + \left. \frac{-16}{\lambda^2 \left( 2\lambda -3 \right)} \, e^{\lambda\, t} \right\vert_{\lambda = -1} + \lim_{\lambda \to 0} \,\frac{\text d}{{\text d} \lambda} \frac{-16}{\lambda^2 -3\lambda -4} \, e^{\lambda\, t} \\ &=& \frac{1}{80} \, e^{4t} - \frac{1}{5}\, e^{-t} + \lim_{\lambda \to 0} \, \frac{16 \left( 2\lambda -3 \right)}{\left( \lambda^2 -3\lambda -4 \right)^2} + + \lim_{\lambda \to 0} \, \frac{-16 \,t}{\lambda^2 -3\lambda -4} \, e^{\lambda\, t} \\ &=& \frac{1}{80} \, e^{4t} - \frac{1}{5}\, e^{-t} + \frac{3-4t}{4} . \end{eqnarray*}
Now we add these two functions to obtain the required solution of the given initial value problem:
$y(t) = y_h (t) + y_p (t) = \left[ \frac{3-4t}{4} - \frac{143}{80} \, e^{4t} - \frac{59}{20}\, e^{-t} \right] H(t) .$