0% found this document useful (0 votes)
42 views22 pages

Unit 3

The document provides an overview of Ordinary Differential Equations (ODEs), focusing on numerical methods for solving first-order ODEs, specifically Euler's Method and Runge-Kutta Methods. It discusses the formulation, error analysis, and stability of Euler's Method, as well as the structure and application of the Runge-Kutta methods. Examples illustrate the implementation of these methods in solving initial value problems.

Uploaded by

Lap Sang Ho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views22 pages

Unit 3

The document provides an overview of Ordinary Differential Equations (ODEs), focusing on numerical methods for solving first-order ODEs, specifically Euler's Method and Runge-Kutta Methods. It discusses the formulation, error analysis, and stability of Euler's Method, as well as the structure and application of the Runge-Kutta methods. Examples illustrate the implementation of these methods in solving initial value problems.

Uploaded by

Lap Sang Ho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

(EE3006/3006A)

Unit 3. Ordinary Differential Equations


1. Introduction
2. Euler’s Method
• Euler’s method
• Error analysis for Euler’s method
• Stability of Euler’s method
3. Runge-Kutta Methods
• Second-Order Runge-Kutta Method
• Classical Fourth-Order Runge-Kutta Method
4. System of Equations
• Euler’s method
• Runge-Kutta method
1

(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).

• Differential equations play a fundamental role in science and


engineering because many physical phenomena are best
formulated mathematically in terms of their rate of change.
2
(EE3006/3006A)

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

where g is the gravitational constant, m


is the mass, and cd is a drag coefficient.

=> rate equations, differential equations

(EE3006/3006A)

 The sequence of events in the development and solution of ODEs


(using the example of the free-falling bungee jumper):

4
(EE3006/3006A)

• ODEs are always classified according to their orders:


– A first-order equation includes a first derivative as its highest derivative;
– A second-order equation includes a second derivative as its highest derivative.
For example, the equation describing the position x of an unforced mass-
spring system is:
d 2x dx
m  c  kx = 0
dt 2 dt

• Higher-order equations can be reduced to a system of the first-order


equations by redefining variables:

dx
=v
dt dY  x
= UY , Y= 
dv c k dt v 
=  v x
dt m m
5

(EE3006/3006A)

 This unit is to study how to numerically solve the first-order ordinary


differential equations in the form of
dy
= f (t , y ) (where y is an unknown function with respect to the variable t)
dt
and the system of first-order ordinary differential equations as
dy1
= f1 (t, y1, y2 ,..., yn )
dt
dy2
= f2 (t, y1, y2 ,..., yn )
dt

dyn
= fn (t, y1, y2 ,..., yn ) (where yi is an unknown function with respect to the variable t)
dt
 Two methods to be studied include:
 Euler’s Method
 Runge-Kutta Method (RK)
6
(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   h (where the slope ϕ is called as increment function )

 = f (ti , yi ) (the first derivative is used to estimate the slope ϕ)

yi 1 = yi  f (ti , yi )h

(This formula is referred as Euler’s method, or Euler-Cauchy or


point-slope method)
7

(EE3006/3006A)

• Graphical depiction of Euler’s method

ti ti+1 t

yi 1 = yi  f (ti , yi )h

=> A new value of y is predicted using the slope to extrapolate


linearly over the step size h.
8
(EE3006/3006A)

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  e0.5t )  2e0.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.81 0.51
y= (e e )  2e 0.51 = 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.81  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)

2.2 Error analysis for Euler’s method


Numerical solutions of ODEs involves two types of errors:
I. Truncation errors
=> errors caused by the nature of the techniques employed to
approximate values
 Local truncation error (results from a single step calculation)
 Propagated truncation error (results from previous steps)

II. Round-off errors


=> errors caused by the limited numbers of significant digits that can
be retained by a computer

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!

=> Local truncation error of Euler’s method is:

f (ti , yi ) 2
Et = h , or Et = O ( h 2 )
2! n+1

Hence, the Euler’s method is a first-order method.

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)

2.3 Stability of Euler’s method


 The stability of a solution method is another important aspect
that must be considered when solving ODEs;
 A numerical solution is said to be unstable if errors grow
exponentially for a problem that has a bounded solution;
 The stability of a particular application depends on three
factors:
• the differential equation
• the numerical method
• the step size

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 eat when y(0)=y0 .

The formula of Euler’s method is


dy
yi1 = yi  i h
dt
= yi  a yi h
= yi (1  a h)

17

(EE3006/3006A)

yi 1 = yi (1  ah)

 The parenthetical quantity (1−ah) is called an amplification factor.


If its absolute value is greater than unity, the solution will grow in
an unbounded fashion;
 Clearly, the stability depends on the step size h. That is,
if h >2/a, |yi|→ ∞ as i → ∞;

 Based on these analysis, Euler’s method is said to be conditionally


stable;
 If the errors always grow regardless of the method, the ODE is
called as ill-conditioned.

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 )

( 0 < pj < 1, j = 1, 2, …. n-1 ) 19

(EE3006/3006A)

 The recurrent relationship (that is, k1 appears in the equation


for k2, which appears in the equation for k3, and so forth)
makes RK methods efficient for computer calculations;
 Various types of Runge-Kutta methods can be designed by
employing different numbers of terms in the increment
function as specified by n:
 n=1 Euler’s method.

 n=2 second-order RK method

 n=4 fourth-order RK method

20
(EE3006/3006A)

3.1 Second-order Runge-Kutta method


The second-order RK equation is
yi1 = yi  (a1k 1  a2 k2 )h
where
k1 = f (ti , yi )
k2 = f (ti  p1h, yi  q11k1h)

=> 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)

Then, the second-order RK equation can be written as


yi1 = yi  (a1k1  a2 k2 )h
  f (ti , yi ) f (ti , yi ) 
= yi  a1 f (ti , yi )  a2  f (ti , yi )  p1h  q11k1h   h
  t y 
 f (ti , yi ) f (ti , yi )  2
= yi  (a1  a2 ) f (ti , yi )h   a2 p1  a2 q11 f (ti , yi ) h
  t y 
Comparing with the Taylor series expansion mentioned above, i.e.
 f (ti , yi ) f (ti , yi )  h2
yi 1 = yi  f (ti , yi )h    f (ti , yi ) 
 t y  2
one obtains
a1  a2 = 1
1
a 2 p1 = => undetermined :
2
3 equations ~ 4 unknowns
1
a2 q11 =
2 23

(EE3006/3006A)

 As we may choose an infinite number of values for the constants


a1, a2, p1, and q11, there are an infinite number of second-order
RK formulations;

 Three of the most commonly used methods are:

 Heun’s Method (a2=1/2)

 The Midpoint Method (a2=1)

 Ralston’s Method (a2=2/3)

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
yi1 = yi  ( k1  k2 )h
2 2
where

k1 = f (ti , yi )
k2 = f (ti  h, yi  k1h)

25

(EE3006/3006A)

3.2 Classical fourth-order Runge-Kutta method


 There are many versions of RK methods. The most widely used form
is the classical fourth-order RK method:
1
yi1 = yi  (k 1  2k2  2k3  k4 )h
6
where
k1 = f (ti , yi )
1 1
k2 = f (ti  h, yi  k1h)
2 2 y(ti+h/2)
1 1
k3 = f (ti  h, yi  k2 h)
2 2 y(ti+h/2)
k4 = f (ti  h, yi  k3 h)
y(ti+h)
26
(EE3006/3006A)

 Graphical depiction of the slope estimates comprising the classical


fourth-order RK method:

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;

 The fourth-order RK method is similar to the Heun’s method in


which multiple estimates of the slope are developed to produce
an improved average slope for the interval;

 As depicted in the previous figure, each of kj (j=1, 2, 3, 4)


represents a slope. The fourth order RK equation represents a
weighted average of these slopes to obtain an improved slope.

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

Next, this slope is used to compute a value of y and a slope at


the end of the interval:
y(1.0) = 2 + 3.912974×1.0 = 5.912974
k4 = f (1.0, 5.912974) = 4e0.8×1.0 − 0.5×5.912974= 5.945677

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)

4.1 Euler’s method ( for systems of equations)


 Engineering applications can involve thousands of simultaneous
equations.

 The procedure for solving a system of equations simply involves


by applying the one-step technique for every equation at each
step before proceeding to the next step.

 For each step, Euler’s method for single equations is extended to


solve systems of ODEs.

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)

4.2 Runge-Kutta methods ( for systems of equations)


1) First, find slopes for all equations at
the initial value (a set of k1’s);
2) The slopes k1 are then used to make
predictions of the dependent variable
at the midpoint of the interval, and
compute a set of slopes at the midpoint
(the k2’s);
3) The slopes k2 are then taken back to the
starting point to make another set of
midpoint predictions that lead to new slopes k3;
4) The slope k3 are then employed to develop slopes at the end of the interval
(the k4’s);
5) Finally, all the k’s are combined into a set of increment that are brought
back to the beginning to make the final prediction of ϕ. 37

(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

These are used to determine the second set of midpoint predictions:


h 2
x(1) = x(0)  k2,1 = 0  9.8100  = 9.8100
2 2
h 2
v(1) = v(0)  k2,2 = 0  9.4567  = 9.4567
2 2
which can be used to compute the second set of midpoint slopes:
k3,1 = f1 (1, 9.8100, 9.4567) = 9.4567
39
k3,2 = f 2 (1, 9.8100, 9.4567) = 9.4817

(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)

Q2. Find the solution of the following initial value problem


dy
= y  x 2  2 , where y(0)=1,
dx
from x=0 to x=0.3 by using the classical fourth-order Runge-Kutta method
with the step size h=0.15. (give your answer to 4 decimal places)

42
(EE3006/3006A)

Reference:
( S.C. Chapra, Applied numerical methods with MATLAB for engineers and
scientists, McGraw Hill, 2008)

1. Euler’s method (pp. 323)


2. Runge-Kutta method (pp. 335)
3. System of equations (pp. 339)

43

You might also like