SOLVING ORDINARY DIFFERENTIAL EQUATIONS WITH
THE LAPLACE TRANSFORM USING MATLAB
Ian Cooper
[email protected]
Doing Physics with Matlab
https://d-arora.github.io/Doing-Physics-With-Matlab/
Download Scripts
https://drive.google.com/drive/u/3/folders/1j09aAhfrVYpiMavajrgSv
UMc89ksF9Jb
Laplace07.m
The Laplace transform is used to solve the ODE for the cases where
the System is driven via the mass.
Laplace08.m
The Laplace transform is used to solve the ODE for the cases where
the System is driven via the mass by a sinusoidal driving force.
Laplace09.m
The Laplace transform is used to solve the ODE for the cases where
the System is driven via the dashpot by a sinusoidal driving force.
Laplace11.m
The Laplace transform is used to solve the ODE for the cases where
the System is driven via the spring by a sinusoidal driving force.
Laplace12.m
The Laplace transform is used to solve the ODE for the cases where
the System is driven via the dashpot and spring by a sinusoidal
driving force.
1
INTRODUCTION
Starting from a linear ordinary differential equation in x with constant
coefficients, the Laplace transform X produces an algebraic equation
that can be solved for X. The solution x is then found by taking the
inverse Laplace transform of X. The Laplace transform method is
most compatible with initial value problems.
Many physical systems can be modelled by ordinary differential
equations (ODEs) with time independent coefficients. In this paper
we will consider solving ODEs of the form
(1) m x b x k x f (t )
where m, b and k are constants and x is the displacement of the system
from its equilibrium position (x = 0). The initial conditions are
specified by the displacement x(0) and velocity v(0). The time
dependent function f(t) is called the input signal or forcing function or
driving force. The solution x(t) is called the output signal.
Equation (1) is used to model a mass m, spring k, and dashpot -
damping b System as shown in figure 1 for different input signals.
2
Fig. 1. Mass / spring / dashpot System.
LAPLACE TRANSFORM
The Laplace transform and its inverse can be used to find the solution
of initial value problems for ordinary differential equations.
Suppose that the function f (t ) is defined for all t 0 . Then its
Laplace transform is the function F ( s ) as given by
(2) F ( s ) L f (t ) f (t ) e s t dt
0
where L is the symbol used for the Laplace transform operator and s
is a complex variable such that
(3) s i dimensions s, , [1/time]
3
An important property of the Laplace transform is that it turns a
derivative into an algebraic operation. For example,
(4) L f s L f f (0)
L f s 2 L f s f (0) f '(0)
The Laplace transform of a function can be easily computed in Matlab
(Symbolic Maths and Signal Processing toolboxes required) as shown
by the following examples. The function f and variables t and s are all
declared as symbolic variables
syms f t s
f = 2; laplace(f,t,s) 2/s
f = sin(4*t); laplace(f,t,s) 4/(s2+16)
f = 10*sin(4*t); laplace(f,t,s) 40/(s2+16)
f = 5*cos(2*t); laplace(f,t,s) 5s/(s2+4)
f = x^5; laplace(f,t,s) 120/s6
f = exp(-2*t); laplace(f,t,s) 1/(s+2)
f = 3*exp(4*t); laplace(f,t,s) 3/(s-4)
4
Table 1 lists a few of the most frequently used Laplace transforms.
Table 1. Laplace transforms.
f(t) F(s)
a a/s
A sin(b t) A b / (s2+b2)
A cos(b t) A s / (s2+b2)
xn n! / sn+1
Ae- a t A / (s+a)
You can also do the reverse by finding the function f(t) from its
Laplace transform F(s) using the inverse Laplace transform. For
example
L1{3 / (( s 1) ^ 2 6)}
6 / 2 et sin 6t
ilaplace(3/((s-1)^2+6)) (6^(1/2)*exp(t)*sin(6^(1/2)*t))/2
5
LAPLACE TRANSFORM AND ORDINARY DIFFERENTIAL EQUATIONS
Initial value ordinary differential equation problems can be solved
using the Laplace transform method. We want to solve ODE given by
equation (1) with the initial the conditions given by the displacement
x(0) and velocity v(0) v x . Our goal is to find the output signal
x (t ) for a given input signal f (t ) .We will denote the Laplace
transform of the input as F(s) and the output as X(s). Taking the
Laplace transform of both sides of equation (1) and using equation (4),
we find
(5) m s 2
b s k X ( s ) m s x (0) v (0) b x (0) F ( s ) 0
This algebraic equation can be solved to find X(s). We than take the
inverse Laplace transform of X(s) to find the output signal x(t).
We can also find dependence of both the velocity v and acceleration a
of the mass by from the Laplace transform of the output signal X(s)
Velocity v and its Laplace transform V(s)
V ( s) s X ( s ) x(0) L1{V ( s)} v(t )
Acceleration a and its Laplace transform A(s)
A( s ) s 2 X ( s ) s x(0) v(0) L1{ A( s)} a(t )
6
A1 System driven through via the mass Laplace07.m
Four plots are used to display the output in a Figure Window: (1)
displacement x vs time t; velocity v vs t; acceleration a vs t; phase plot
v vs t; function f vs t. The labelling shows the System parameters m, b
and k; the natural frequency of oscillation N k / m and the natural
period of oscillation TN 2 / N and the period Test estimated from
the x vs t graph using the Matlab function findpeaks. The symbolic
results are displayed in the Command Window, for example,
Sol_x = s/(s^2 + 4)
sol_x = cos(2*t) cos(2 t)
Sol_v = s^2/(s^2 + 4) - 1
sol_v =-2*sin(2*t) -sin(2 t) 2
Sol_a = s^3/(s^2 + 4) - s
sol_a = -4*cos(2*t) -cos(2 t) 4
7
A1.1 Simple harmonic motion
Sol x s / ( s 2 4) x cos 2 t
Solv s 2 / ( s 2 4) v 2sin 2t
Sola s 3 / ( s 2 4) a 4cos 2t
8
Poles of the Laplace transform Solx
demoniator Sol x s 2 4 0
s i 2i 0 2
Hence, the natural frequency of oscillation is 2 and the solution
of the displacement is of the form
x c1 exp( t ) c2 cos( t ) c3 sin( t
x c2 cos(2 t ) c3 sin(2 t ) x (0) 1 v (0) 0
x cos(2 t )
A1.2 Damped harmonic motion
9
Sol x 5 s 1 / 5 s 2 s 20
x exp t / 10 cos( 399 t / 10) 399 sin( 399 t / 10) / 399
Solv s 5 s 1 / 5 s 2 s 20
v 40 399 exp t / 10 sin( 399 t / 10) / 399
Sola s 2 5 s 1 / 5 s 2 s 20
a 4 exp t / 10 cos( 399 t / 10) 399 sin( 399 t / 10) / 399
Poles of the Laplace transform Solx
The solution of the displacement is of the form
x c1 exp( t ) c2 cos( t ) c3 sin( t
demoniator Sol x s 2 4 0
s 0.1000 1.9975 i
s i 2 i 0.1000 1.9975 399 / 10
10
A1.3 Exponential impulsive force
m x b x k x exp( t ) 0
Sol_x = 1/(s^3 + s^2 + 4*s + 4)
sol_x = exp(-t)/5 - cos(2*t)/5 + sin(2*t)/10
Sol_v = s/(s^3 + s^2 + 4*s + 4)
sol_v = cos(2*t)/5 - exp(-t)/5 + (2*sin(2*t))/5
Sol_a = s^2/(s^3 + s^2 + 4*s + 4)
sol_a = (4*cos(2*t))/5 + exp(-t)/5 - (2*sin(2*t))/5
11
Poles of the Laplace transform Solx
s3 s 2 4s 4 0 s 0 2 i,0 2 i, 1 0 i
The roots of the polynomial are computed using the Command
Window
>> p = [1 1 4 4] p=1 1 4 4
>> roots(p)
0.0000 + 2.0000i
0.0000 - 2.0000i
-1.0000 + 0.0000i
After the initial disturbance the System oscillates at its natural
frequency indefinitely since the damping is zero.
A2 System driven through via the mass by sinusoidal functions
Laplace08.m
We next consider the system driven via the mass by a sinusoidal
driving force. This example allows you to study the phenomena of
resonance. The ODE to be solved is
m x b x k x A cos t
given the initial displacement and velocity of the mass. The ODE
equation can be also expressed as
m z b z k z A exp t
12
where the output z is assumed to be a sinusoidal function of the form
z G exp(i t )
where G is the complex function
G G exp i t
After a bit of algebra, you can derive the following relationships:
G
A k m 2 b i
k m
2
2
b 2 2
A
G
2
k m 2 b 2 2
Resonance frequency G max R k / m b 2 / 2m 2
Natural frequency N k / m
b
Phase tan 1 2
k m
13
A2.1 System driven at its natural frequency of vibration with no
damping.
The System vibrates at the driving frequency. When the System is
driven at its natural frequency, then the oscillations continually grow
with time x t .
Sol_x = s/(s^2 + 4)^2
s i s 2 i 0 2
sol_x = (t*sin(2*t))/4
Sol_v = s^2/(s^2 + 4)^2 sol_v = sin(2*t)/4 + (t*cos(2*t))/2
Sol_a = s^3/(s^2 + 4)^2 sol_a = cos(2*t) - t*sin(2*t)
14
The oscillations of the input and output are in phase.
15
A2.2 System driven at its natural frequency of vibration with
damping.
Sol_x = s/((s^2 + 4)*(s^2 + s/2 + 4))
In the Command Window
>> p=[1 0.5 4] p = 1.0000 0.5000 4.0000
>> roots(p) ans = -0.2500 + 1.9843i -0.2500 - 1.9843i
s i s 2 i 0.25 1.9843
sol_x = sin(2*t) - (8*7^(1/2)*exp(-t/4)*sin((3*7^(1/2)*t)/4))/21
The System’s resonance frequency is R 3 7 / 4 1.9843 .
16
Since the System is driven at a frequency very close to its resonance
frequency, large amplitude oscillations result with the output leading
the input by 90o.
17
When the System is driven at a frequency which is away from the
resonance frequency, the System will vibrate at the driving frequency
with small amplitude oscillations after the initial transient oscillations
die away exponentially.
Sol_x = s/((s^2 + 9)*(s^2 + s/2 + 4))
sol_x = (6*sin(3*t))/109 - (20*cos(3*t))/109 +
(20*exp(-t/4)*(cos((3*7^(1/2)*t)/4) –
(13*7^(1/2)*sin((3*7^(1/2)*t)/4))/105))/109
18
19
B System driven through the dashpot Laplace09.m
To illustrate the Laplace transform method to solve ODEs, we will
consider the example of the mass / spring / dashpot System excited by
a sinusoidal displacement of the piston in the dashpot. The ODE for
this system is
mxbxk x b y y A cos t y A sin t
The output and input functions can be expressed in exponential form
as
y Aei t x G ei t G g e i x g e i ei t
where G is the transfer function. By substitution, we can find the
expressions for the transfer function G, its magnitude g and argument
.
G
b i
b2 2 b k m 2 i
k m b i
2
b2 2 k m 2
2
2
b4 4 b2 2 k m 2
(8) gG
2
b2 2 k m 2
tan 1
b k m 2
b
2 2
20
The maximum gain is g = 1 when N k / m . N is the natural
frequency of the System. At the natural frequency of excitation, the
input and output oscillations are in phase 0 . For the System
driven through the damper, the natural frequency N and maximum
gain are both independent upon the damping parameter b. If N
then the phase lag is negative 0 and the response runs behind the
input (lags). If N then the phase lag is positive 0 and the
response runs ahead of the input (leads).
21
B.1 Example N
Sol_x = (s - 4/(5*(s^2 + 1)) + 1)/(s^2 + (4*s)/5 + 4)
sol_x = (16*cos(t))/241 - (60*sin(t))/241 +
(225*exp(-(2*t)/5)*(cos((4*6^(1/2)*t)/5) +
(991*6^(1/2)*sin((4*6^(1/2)*t)/5))/5400))/241
The Laplace transform X(s) gives us information directly about the
nature of the oscillation when it has the largest magnitude and this
occurs when each denominator approaches zero
22
The first term
s i s 2 1 0 s 1i 0 1
describes the sinusoidal oscillations with frequency 1
For the second term, we can find the values of s from the poles of the
solution for x in the Command Window
>> p = [1 0.8 4] p= 1.0000 0.8000 4.0000
>> roots(p) ans = -0.4000 + 1.9596i -0.4000 - 1.9596i
>> 4*sqrt(6)/5 ans = 1.9596
This terms describes the decaying oscillations with a frequency of
4 6 / 5 1.9596
and decay constant 2 / 5 0.4
Initially there are transient oscillation which quickly decay
exponentially, leaving the mass oscillating at the same frequency as
the input signal .
23
The Bode and Nyguist plots for the response of the System
as functions of the driving frequency .
24
The Bode plot gives graphs of the frequency response of a system,
one displaying the magnitude of the response and other graph, the
phase lag of the output signal to the input signal. Once the transient
oscillations have died away, the output signal oscillates at the driving
frequency .
A Nyquist plot is a parametric plot of the frequency response where
the imaginary part of the transfer function G is plotted against the real
part. In our example, as the frequency increases from zero, a circular
contour with the centre at (0.5,0) is swept out in a clockwise sense.
The green dot is for the initial point where 0 . to The red dot on
the contour gives the real and imaginary parts at the driving frequency.
The length of the line from zero to this point is the magnitude of the
transfer function G and the angle gives the phase shift between the
output and the input.
25
B.2 Example N
Sol_x = (s - 16/(5*(s^2 + 4)) + 1)/(s^2 + (4*s)/5 + 4)
sol_x = cos(2*t) + (6^(1/2)*exp(-(2*t)/5)*sin((4*6^(1/2)*t)/5))/24
The transient effects die away exponentially and then the System
vibrates with maximum amplitude at its natural frequency.
26
The solutions for the velocity and acceleration are:
Sol_v = (s*(s - 16/(5*(s^2 + 4)) + 1))/(s^2 + (4*s)/5 + 4) – 1
sol_v = (exp(-(2*t)/5)*(cos((4*6^(1/2)*t)/5) –
(6^(1/2)*sin((4*6^(1/2)*t)/5))/12))/5 - 2*sin(2*t)
Sol_a = (s^2*(s - 16/(5*(s^2 + 4)) + 1))/(s^2 + (4*s)/5 + 4) - s - 1/5
sol_a = - 4*cos(2*t) - (4*exp(-(2*t)/5)*(cos((4*6^(1/2)*t)/5) +
(23*6^(1/2)*sin((4*6^(1/2)*t)/5))/24))/25
The Bode and Nyquist plots are:
27
When the System is driven via the dashpot at resonance, then the
amplitude of the oscillation is a maximum and the System vibrates in
phase with the input signal.
C System driven through the spring Laplace11.m
The equation of motion for the System driven by a sinusoidal input
signal via the spring is
mxbxk x k y y A cos t
Assume exponential input and output function of the form
Input y Ae i t
Output x G e i t g e i Ae i t G g e i
where G is the transfer function.
After a bit of algebra you can derive the following
k2 m k 2 b k i
G
2
k m 2 b2 2
28
The gain function G approaches a maximum when the denominator D
approaches a minimum
dD / d 2 2 m k m 2 2b 2
0
Hence, the resonant frequency is
R k / m b 2 / 2 m 2
The phase lag is
b / m
tan 1 2
k / m
If there is zero damping b = 0, then the System will oscillate in phase
with maximum amplitude when excited at the natural frequency.
29
C.1 Example R
Sol_x = -(s/2 - (4*s)/(s^2 + 1) + 1/2)/(s^2 + s + 4)
sol_x = (6*cos(t))/5 + (2*sin(t))/5 - (17*exp(-t/2)*(cos((15^(1/2)*t)/2)
+ (5*15^(1/2)*sin((15^(1/2)*t)/2))/51))/10
30
31
C.2 Example R
Sol_x = -(s/2 - (4*s)/(s^2 + 4) + 1/2)/(s^2 + s + 4)
sol_x = 2*sin(2*t) - (exp(-t/2)*(cos((15^(1/2)*t)/2) +
(17*15^(1/2)*sin((15^(1/2)*t)/2))/15))/2
32
33
D System driven through the spring and dashpot Laplace12.m
The equation of motion for the System driven by a sinusoidal input
signal via the dashpot and spring is
mxbxk x b y k y y A cos t y A sin t
Assuming the input and output can be expressed as exponential
functions
y Ae i t y A i e i t y A 2 e i t
G g ei xGy
k b i
G
m 2 k b i
34
D.1 Example R
35
36