Solving initial value problems with the Laplace transform
Let
Since
we have syms s t Y % define symbolic variables s,t,Y
Example 1: 
Take the Laplace transform of the right-hand side function
: F = laplace(f)
F =

Find
: Solve the equation
for
: Sol = solve(Y1-3*Y==F,Y)
Sol =

Find the partial fraction decomposition by hand:
, multiply by
: Find the partial fraction decomposition using Matlab:
partfrac(Sol)
ans =

Now we can apply the inverse Laplace transform: Using
we obtain Use ilaplace to find the inverse Laplace transform:
sol = ilaplace(Sol)
sol = 
Example 2:
Here
and
has a double root
. F = laplace(f)
F =

Find
: Find
: Solve the equation
for
: Sol = solve(Y2+3*Y1+2*Y==F,Y)
Sol =

Find the partial fraction decomposition by hand:
We first need the roots of the characteristic polynomial:
gives
and
, so we have
. The denominator function for
will be Hence we want to find a partial fraction decomposition
Multiplying by
gives It remains to find A.
Method 1: Take the derivative of
: In the derivative plug in
. This gives
, so
. Method 2: In
, plug in a different value, e.g.,
this gives
, 
Find the partial fraction decomposition using Matlab:
partfrac(Sol)
ans =

Now we can apply the inverse Laplace transform: Using
we obtain Use ilaplace to find the inverse Laplace transform:
sol = ilaplace(Sol)
sol = 
Example 3: 
Here
and
has complex roots
. So far we just used F=laplace(f)
The full form of the command is F=laplace(f,t,s) where t is the variable for f, and s is the variable for F.
F = laplace(f,t,s) % since there is no explicit t in f we need to use laplace(...,t,s)
F =

Here is
: Sol = solve(Y2-2*Y1+5*Y==F,Y)
Sol =

Taking the inverse Laplace transform gives the solution
: sol = ilaplace(Sol)
sol =

If we want to find this by hand we first need the partial fraction decomposition. There are two ways to do this:
Method 1: Partial fraction decomposition (real version)
partfrac(Sol)
ans =

We have
, so
. We have
since the roots are
. We want to write the term as yielding
Here
, so Method 2: Partial fraction decomposition (complex version)
partfrac(Sol,'FactorMode','full')
ans =

We get complex roots
. If these occur once (as in this example) the partial fraction decomposition has terms with complex
,
. After we multiply by the denominators we can find the complex number C by plugging in
. Then we obtain
If the complex roots
occur twice (as in Example 4 below) we will get additional terms with complex
. We obtain
In example 3 we have simple roots
and
, so Example 4: 
Here
and
has double complex roots
. F = laplace(f)
F =

Y2 = s*Y1-2
Y2 = 
We obtain
Sol = simplify( solve(Y2+Y==F,Y) )
Sol =

Partial fraction decomposition by hand: (complex version)
multiply by
: plug in
: take the derivative:
plug in
: Partial fraction decomposition with Matlab: (complex version)
partfrac(Sol,'FactorMode','full')
ans =

sol = ilaplace(Sol)
sol =
