Unit 3
Unit 3
(EE3006/3006A)
1. Introduction
• Equations composed of an unknown function and its derivatives
are called differential equations.
• When a differential equation involves one independent variable,
the equation is called an ordinary differential equation (ODE):
dy
= f (t, y)
dt
• If a differential equation involves two or more independent
variables and their partial derivatives, it is a partial differential
equation (PDE).
Example of case:
The velocity of a free-falling bungee jumper can be described
by Newton’s second law:
dv c
= g d v2
dt m
(EE3006/3006A)
4
(EE3006/3006A)
dx
=v
dt dY x
= UY , Y=
dv c k dt v
= v x
dt m m
5
(EE3006/3006A)
2. Euler’s Method
2.1 Euler’s method (for an initial-value problem of ODE)
dy ?
= f (t, y) , y(0)= c. y(T)
dt
yi 1 = yi f (ti , yi )h
(EE3006/3006A)
ti ti+1 t
yi 1 = yi f (ti , yi )h
Example 1:
Use Euler’s method to find the solution of the initial value problem
y′= 4e0.8t − 0.5y
from t = 0 to 4 by using the initial condition y = 2 at t = 0 ad the step
size of 1. Calculate the corresponding relative percent errors by
using the exact solution analytically determined as
4
y = (e0.8t e0.5t ) 2e0.5t .
1.3
Solution:
The increment function is
f (ti , yi ) = 4e0.8ti 0.5 yi
9
(EE3006/3006A)
Continue:
Then, the Euler’s method is implemented as
y(1) = y(0) f (0, 2) 1
where y(0)=2 and the slope estimate at t=0 is
f (0, 2) = 4e0 0.5 2 = 3
Therefore, y(1)=2+3×1=5.
The true solution at t=1 is
4 0.81 0.51
y= (e e ) 2e 0.51 = 6.19463
1.3
Thus, the relative percent error is
6.19463 5
et = 100% = 19.28%
6.19643
10
(EE3006/3006A)
Continue:
For the second step:
y (2) = y (1) f (1, 5) 1
=5+(4e0.81 0.5 5) 1 = 11.40216
Proceeding in a like manner for the remaining steps yields the values:
11
(EE3006/3006A)
*Example 2:
Use Euler’s method to integrate y′= y−x+2 from x = 0 to x=0.4
using step size of 0.1. The initial condition at x = 0 is y = 1.
Solution:
The increment function is f (xi, yi)=yi-xi+2.
Then,
y(0.1)=y(0)+f (0, 1)×0.1 =1.3,
y(0.2)=y(0.1)+f (0.1, 1.3)×0.1 =1.62,
y(0.3)=y(0.2)+f (0.2, 1.62)×0.1 =1.962,
y(0.4)=y(0.3)+f (0.3, 1.962)×0.1 =2.328.
12
(EE3006/3006A)
13
(EE3006/3006A)
dy
ODE: = f (t, y)
dt
Taylor series expansion about the starting value (ti, yi) can
be written as:
h2 hn
yi 1 = yi f (ti , yi )h f (ti , yi ) f ( n 1) (ti , yi ) O(hn 1 )
2! n!
f (ti , yi ) 2
Et = h , or Et = O ( h 2 )
2! n+1
14
(EE3006/3006A)
Remarks:
The method provides error-free predictions if the underlying
function (i.e., the solution of the differential equation) is linear,
because the second derivative of a straight line is zero.
The global error can be reduced by decreasing the step size.
t
15
(EE3006/3006A)
16
(EE3006/3006A)
=> To gain insight into the step size required for stability, one can
study a very simple ODE:
dy
= a y
dt
whose analytical solution is y = y0 eat when y(0)=y0 .
17
(EE3006/3006A)
yi 1 = yi (1 ah)
18
(EE3006/3006A)
3. Runge-Kutta Methods
The increment function ϕ in the formula yi 1 = yi h
can be written in a more general form:
= a1k1 a2 k2 an kn k1
where the ai are constants and ki are ϕ
k1 = f (ti , yi )
k 2 = f (ti p1h, yi q11k1h ) ti ti+1 t
k 3 = f (ti p2 h, yi q21k1h q 22 k 2 h )
k n = f (ti pn 1 h, yi q n 1,1k1h qn 1,2 k 2 h qn 1, n 1k n 1h )
(EE3006/3006A)
20
(EE3006/3006A)
=> How to reasonably select the constants a1, a2, p1, and q11
to minimize error?
21
(EE3006/3006A)
=> According to Taylor series expansion, the second order approximation of yi+1
can be expressed as
f '(ti , yi ) 2
yi 1 yi f (ti , yi )h h
2!
which can be further written as
f (ti , yi ) f (ti , yi ) dy h 2
yi 1 yi f (ti , yi )h
t y dt 2
f (ti , yi ) f (ti , yi ) h2
yi f (ti , yi )h f (ti , yi )
t y 2
On the other hand, k2 can be expanded as
k2 = f (ti p1h, yi q11k1h) (assume that both p1h and q11k1h are small quantities)
f (ti , yi ) f (ti , yi )
f (ti , yi ) p1h q11k1h
t y
22
(EE3006/3006A)
(EE3006/3006A)
24
(EE3006/3006A)
Heun’s Method
If a2 is assumed to be 1/2, one can obtain
1
a1 = , and p1 = q11 = 1
2
Then, the formula of the second order RK method can be written as
1 1
yi1 = yi ( k1 k2 )h
2 2
where
k1 = f (ti , yi )
k2 = f (ti h, yi k1h)
25
(EE3006/3006A)
k1 = f (ti , yi )
1 1
k2 = f (ti h, yi k1h)
2 2
1 1
k3 = f (ti h, yi k2 h)
2 2
k4 = f (ti h, yi k3h )
27
(EE3006/3006A)
Remarks:
For ODEs that are a function of t alone, the classical fourth-
order RK method is similar to Simpson’s 1/3 rule;
28
(EE3006/3006A)
Example 3:
Use the classical fourth-order RK method to find the initial value
problem y′= 4e0.8t − 0.5y from t = 0 to 1 by using the initial condition
y(0)=2 and the step size of 1.
Solution:
For this case, the slope at the beginning of the interval can be
computed as
k1 = f(0,2)=4e0.8×0 −0.5×2=3
This value is used to compute a value of y and a slope at the midpoint:
y(0.5) = 2 + 3×0.5 = 3.5
k2 = f (0.5, 3.5) = 4e0.8×0.5 − 0.5×3.5 = 4.217299
29
(EE3006/3006A)
Continue:
This slope in turn is used to compute another value of y and
another slope at the midpoint:
y(0.5) = 2+4.217299×0.5 = 4.108649
k3 = f (0.5, 4.108649) = 4e0.8×0.5 − 0.5×4.108649 = 3.912974
30
(EE3006/3006A)
Continue:
Finally, the four slope estimates are combined to yield an average
slope. This average slope is then used to make the final prediction at
the end of the interval.
ϕ = [3 + 2×4.217299 + 2×3.912974 + 5.945677] /6 = 4.201037
y(1.0) = 2 + 4.201037×1.0 = 6.201037
Remarks:
As the true solution of y(1.0) is 6.194631 (given in Example 1), the relative
percent error is εt = 0.103%.
Compared with the result obtained with Euler’s method, whose relative percent
error is 19.28% (shown in Example 1), the solution by the fourth-order RK is
much closer to the true value.
31
(EE3006/3006A)
4. System of Equations
=> A system of simultaneous ordinary differential equations can be
represented generally as
dy1
= f1 (t, y1, y2 ,..., yn )
dt
dy2
= f2 (t, y1, y2,..., yn )
dt
dyn
= fn (t, y1, y2,..., yn )
dt
The solution of such a system requires that n initial conditions
are known at the starting value of t.
32
(EE3006/3006A)
33
(EE3006/3006A)
Example 4:
Solve for the velocity and position of the free-falling bungee jumper
using Euler’s method. Assuming that at t = 0, x = v = 0, and integrate
to t = 4 s with a step size of 2 s. The gravitational acceleration g is
9.81 m/s2, and the jumper has a mass m of 68.1 kg with a drag
coefficient cd of 0.25 kg/m. The equation describing the position x is:
d 2x c dx
= g d ( ) 2.
dt 2 m dt
The analytical solutions for velocity and distance are
gm gcd
v(t) = tanh( t) , and x(t) = m ln cosh gcd t .
cd m cd m
Use these analytical solutions to compute the true relative errors of
the results.
34
(EE3006/3006A)
Solution:
The second-order ODE can be rewritten into a system of equations as:
dx
=v
dt
dv c
= g d v2
dt m
With the initial conditions, the ODEs can be used to compute the slopes at t
= 0 as
dx dv 0.25 2
= 0, = 9.81 0 = 9.81
dt dt 68.1
Euler’s method is then used to compute the values at t = 2 s,
x(2) =0+0×2=0, v(2) = 0 + 9.81×2 = 19.62
x(0) v(0)
The analytical solutions can be computed as
x(2) = 19.16629 and v(2) = 18.72919.
Thus, the percent relative errors are 100% and 4.756%, respectively.
35
(EE3006/3006A)
Continue:
The process can be repeated to compute the results at t = 4 as
x(4) = 0 19.62 2 = 39.24
0.25
v(4) = 19.62 (9.81 19.622 ) 2 = 36.41368
68.1
Proceeding in a like manner gives the results displayed in the
followed Table:
36
(EE3006/3006A)
(EE3006/3006A)
Example 5:
Use the classical fourth-order RK method to solve for the same
problem addressed in Example 4:
dx
= f1 (t, x, v) = v
dt
dv c
= f2 (t, x, v) = g d v 2
dt m
Solution:
The first step in obtaining the solution is to solve for all the
slopes at the beginning of the interval:
k1,1 = f1 (0, 0, 0) = 0
0.25 2
k1,2 = f 2 (0, 0, 0) = 9.81 0 = 9.81
68.1
where ki, j is the ki for the j-th dependent variable.
38
(EE3006/3006A)
Continue :
Next, we calculate the first values of x and v at the midpoint of the first
step: h 2
x (1) = x (0) k = 0 0 = 0
1,1
2 2
h 2
v (1) = v (0) k1,2 = 0 9.81 = 9.81
2 2
which can be used to compute the first set of midpoint slopes:
k2,1 = f1 (1, 0, 9.81) = 9.8100
k2,2 = f2 (1, 0, 9.81) = 9.4567
(EE3006/3006A)
Continue :
These are used to determine the predictions at the end of the interval:
x(2) = x(0) k3,1h = 0 9.4567 2 = 18.9134
v(2) = v(0) k3,2 h = 0 9.4817 2 = 18.9634
which can be used to compute the endpoint slopes:
k4,1 = f1 (2, 18.9134, 18.9634) = 18.9634
k4,2 = f 2 (2, 18.9134, 18.9634) = 8.4898
The values of k can then be used to compute:
1
x(2) = 0 [0 2 (9.8100 9.4567) 18.9634] 2 = 19.1656
6
1
v(2) = 0 [9.8100 2 (9.4567 9.4817) 8.4898] 2 = 18.7256
6
40
(EE3006/3006A)
Continue :
Proceeding in a like manner for the remaining steps yields the
values displayed in the followed table:
41
(EE3006/3006A)
Classwork 3:
Q1. Solve the following initial value problem over the interval from t = 0 to 1
by using Euler’s method with step size h = 0.25
dy
= yt 3 1.8 y , where y(0) = 1.
dt
(give your answer to 3 decimal places)
42
(EE3006/3006A)
Reference:
( S.C. Chapra, Applied numerical methods with MATLAB for engineers and
scientists, McGraw Hill, 2008)
43