0% found this document useful (0 votes)
28 views89 pages

Chapter 7 Numerical Ordinary Differential Equations (ODEs)

Chapter 7 of BMED-3083 focuses on solving Ordinary Differential Equations (ODEs) using numerical methods. It covers various techniques including Taylor series methods, Euler's method, and Runge-Kutta methods, emphasizing the importance of selecting appropriate methods for different problems. The chapter also discusses the uniqueness of solutions, initial and boundary conditions, and compares numerical solutions with exact solutions.

Uploaded by

nigatudebebe3
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)
28 views89 pages

Chapter 7 Numerical Ordinary Differential Equations (ODEs)

Chapter 7 of BMED-3083 focuses on solving Ordinary Differential Equations (ODEs) using numerical methods. It covers various techniques including Taylor series methods, Euler's method, and Runge-Kutta methods, emphasizing the importance of selecting appropriate methods for different problems. The chapter also discusses the uniqueness of solutions, initial and boundary conditions, and compares numerical solutions with exact solutions.

Uploaded by

nigatudebebe3
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
You are on page 1/ 89

BMED-3083: Computational

Methods

Chapter 7
Numerical Ordinary Differential
Equations (ODEs)
Objectives of Lecture 7
◼ Solve Ordinary Differential Equations
(ODEs).
◼ Appreciate the importance of numerical
methods in solving ODEs.
◼ Assess the reliability of the different
techniques.
◼ Select the appropriate method for any
particular problem.
Outline of Lecture 7
◼ Introduction to ODEs
◼ Taylor series methods (Focus on Euler Method)
◼ Runge-Kutta 2nd order methods
• Heun’s, Midpoint, and Ralston method
◼ Runge-Kutta 4th order methods
Introduction to ODEs
Learning Objectives
◼ Recall basic definitions of ODEs:
• Order
• Linearity
• Initial conditions
• Solution
◼ Classify ODEs based on:
• Order, linearity, and conditions.
◼ Classify the solution methods.
Derivatives
Derivatives

Partial Derivatives
Ordinary Derivatives

dv u
dt y
u is a function of
v is a function of one
more than one
independent variable
independent variable
Differential Equations
Differential
Equations

Ordinary Differential Equations Partial Differential Equations


2
d v u u
2 2

+ 6tv = 1 − = 0
dt 2 y 2
x 2

involve one or more involve one or more


Ordinary derivatives of partial derivatives of
unknown functions unknown functions
Ordinary Differential Equations
Ordinary Differential Equations (ODEs) involve one or
more ordinary derivatives of unknown functions with
respect to one independent variable
Examples :
dv(t )
− v (t ) = e t x(t): unknown function
dt
2
d x(t ) dx(t )
2
−5 + 2 x(t ) = cos(t )
dt dt
t: independent variable
Example of ODE:
Model of Falling Parachutist

The velocity of a falling


parachutist is given by:

dv c
= 9 .8 − v
dt M
M : mass
c : drag coefficient
v : velocity
Definitions

Ordinary
differential
dv c equation
= 9 .8 − v
dt M
Definitions (Cont.)

dv c
= 9 .8 − v (Dependent
dt M variable)
unknown
function to be
determined
Definitions (Cont.)

dv c
= 9 .8 − v
dt M
(independent variable)
the variable with respect to which
other variables are differentiated
Order of a Differential Equation
The order of an ordinary differential equation is the order
of the highest order derivative.
Examples :
dx(t )
− x(t ) = e t First order ODE
dt
d 2 x(t ) dx(t )
2
−5 + 2 x(t ) = cos(t ) Second order ODE
dt dt
3
 d x(t )
2
 dx(t )
 2
 − + 2 x 4 (t ) = 1 Second order ODE
 dt  dt
Solution of a Differential Equation
A solution to a differential equation is a function that
satisfies the equation.

Example: −t
Solution x(t ) = e
dx(t )
+ x(t ) = 0 Proof :
dt
dx(t )
= −e −t
dt
dx(t )
+ x(t ) = −e −t + e −t = 0
dt
Linear ODE
An ODE is linear if:
-The unknown function and its derivatives appear to power one AKA a
Degree of 1.
- No product of the unknown function and/or its derivatives

Examples:
dx(t )
− x(t ) = e t
dt Linear ODE
d 2 x(t ) dx(t )
2
− 5 + 2t 2
x(t ) = cos(t ) Linear ODE
dt dt
3
 d 2 x(t )  dx(t )
 2
 − + x(t ) = 1 Non-linear ODE
 dt  dt
Solutions of Ordinary
Differential Equations
x(t ) = cos(2t )
is a solution to the ODE
2
d x(t )
2
+ 4 x(t ) = 0
dt
Is it unique?
All functions of the form x(t ) = cos(2t + c)
(where c is a real constant) are solutions.
Uniqueness of a Solution

In order to uniquely specify a solution to an nth


order differential equation we need n conditions.

d 2 x (t )
+ 4 x (t ) = 0 Second order ODE
dt 2
x ( 0) = a Two conditions are
x (0) = b needed to uniquely
specify the solution
Auxiliary Conditions
Auxiliary Conditions

Initial Conditions Boundary Conditions

 All conditions are at one ◼ The conditions are not at one


point of the independent point of the independent
variable variable

18
Boundary-Value and
Initial value Problems
Initial-Value Problems Boundary-Value Problems

 The auxiliary conditions ◼ The auxiliary conditions are not


are at one point of the at one point of the independent
independent variable
variable ◼ More difficult to solve than initial
value problems
−2 t
x + 2 x + x = e −2 t x + 2 x + x = e
x(0) = 1, x (0) = 2.5 x(0) = 1, x(2) = 1.5
same different
Analytical Solutions
◼ Analytical Solutions to ODEs are available for
linear ODEs and special classes of nonlinear
differential equations.
Numerical Solutions
◼ Most of the Numerical methods used to solve
ODEs are based directly (or indirectly) on the
truncated Taylor series expansion.
◼ Numerical methods are used to obtain a graph
or a table of the unknown function.
Classification of the Methods
Numerical Methods
for Solving ODE

Single-Step Methods Multiple-Step Methods

Estimates of the solution Estimates of the solution


at a particular step are at a particular step are
entirely based on based on information on
information on the more than one step
previous step
Taylor Series Methods
Learning Objectives
◼ Derive Euler formula using the Taylor series
expansion.
◼ Solve the first order ODEs using Euler method.
◼ Assess the error level when using Euler
method.
Taylor Series Method
The problem to be solved is a first order ODE:

dy( x)
= f ( x, y ), y ( x0 ) = y0
dx
Estimates of the solution at different base points:
y ( x0 + h), y ( x0 + 2h), y ( x0 + 3h), ....
are computed using the truncated Taylor series
expansions.
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of:

= f ( x, y )
dy
dx

Example

+ 2 y = 1.3e − x , y (0) = 5 is rewritten as = 1.3e − x − 2 y, y (0 ) = 5


dy dy
dx dx

In this case,

f (x, y ) = 1.3e − x − 2 y
Taylor Series Expansion
Truncated Taylor Series Expansion
n
h k  d k y 

y ( x0 + h)  
k !  dx k

k =0
 x = x0 , y = y 0 

dy h2 d 2 y hn d n y
 y ( x0 ) + h + + ... +
dx xy==xy0 , 2! dx2 x = x0 , n! dxn x = x0 ,
0 y = y0 y = y0

The nth order Taylor series method uses the


nth order Truncated Taylor series expansion.
Euler Method
◼ First order Taylor series method is known
as Euler Method.

◼ Only the constant term and linear term are


used in the Euler method and sometimes
referred as Tangent Method.

◼ The error due to the use of the truncated


Taylor series is of order O(h2).
Euler’s Method
y

= f ( x, y ), y (0 ) = y 0
dy True value
dx
y1, Predicted
value
Rise Φ
=
x0,y0
Slope
Run
y1 − y0
= Step size, h
x1 − x0
x
= f ( x0 , y 0 )

y1 = y0 + f (x0 , y 0 )(x1 − x0 )
Figure 1 Graphical interpretation of the first step of Euler’s method
= y0 + f (x0 , y0 )h
Euler’s Method
y

yi +1 = yi + f (xi , yi )h True Value

h = xi +1 − xi yi+1, Predicted value

Φ
yi
h
Step size
x
xi xi+1

Figure 2. General graphical interpretation of Euler’s method


Euler Method
Problem:
Given the first order ODE : y ( x) = f ( x, y )
with the initial condition : y0 = y ( x0 )
Determine : yi = y ( x0 + ih) for i = 1,2,...

Euler Method :
y0 = y ( x0 )
yi +1 = yi + h f ( xi , yi ) for i = 1,2,...
Interpretation of Euler Method
y2

y1

y0

x0 x1 x2 x
Interpretation of Euler Method

Slope=f(x0,y0)
y1
y1=y0+hf(x0,y0)
hf(x0,y0)
y0

x0 x1 x2 x
h
Interpretation of Euler Method
y2 y2=y1+hf(x1,y1)
Slope=f(x1,y1)
hf(x1,y1)
Slope=f(x0,y0)
y1 y1=y0+hf(x0,y0)
hf(x0,y0)
y0

x0 x1 x2 x
h h
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature of
300K. Assuming heat is lost only due to radiation, the differential equation
for the temperature of the ball is given by

d
dt
( )
= −2.206710−12  4 − 81108 ,  (0) = 1200K

Find the temperature at t = 480 seconds using Euler’s method. Assume a step size of

h = 240 seconds.
Solution
Step 1:
d
dt
(
= −2.2067 10−12  4 − 81 108 )
(
f (t , ) = −2.206710−12  4 − 81108 )
 i +1 =  i + f (ti ,  i )h
1 =  0 + f (t0 , 0 )h
= 1200 + f (0,1200)240
( (
= 1200 + − 2.2067 10−12 12004 − 81 108 240 ))
= 1200 + (− 4.5579)240
= 106.09K
1 is the approximate temperature at t = t1 = t0 + h = 0 + 240 = 240
 (240)  1 = 106.09K
Solution Cont.
Step 2: For i = 1, t1 = 240, 1 = 106.09

 2 = 1 + f (t1 , 1 )h
= 106.09 + f (240,106.09)240
( (
= 106.09 + − 2.206710−12 106.094 − 81108 240 ))
= 106.09 + (0.017595)240
= 110.32K

 2 is the approximate temperature at t = t2 = t1 + h = 240 + 240 = 480


 (480)   2 = 110.32K
Solution Cont.

The exact solution of the ordinary differential equation is given by the


solution of a non-linear equation as
 − 300
0.92593ln − 1.8519 tan −1 (0.00333 ) = −0.2206710−3 t − 2.9282
 + 300

The solution to this nonlinear equation at t=480 seconds is

 (480) = 647.57K
Comparison of Exact and
Numerical Solutions
1400

1200
Temperature, θ(K)

1000
Exact Solution
800

600

400
h=240
200

0
0 100 200 300 400 500
Time, t(sec)

Figure 3. Comparing exact and Euler’s method


Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h

Step, h (480) Et |єt|%


480 −987.81 1635.4 252.54
240 110.32 537.26 82.964
120 546.77 100.80 15.566
60 614.97 32.607 5.0352
30 632.77 14.806 2.2864

 (480) = 647.57K (exact)


Comparison with exact results

1500

1000 Exact solution


Temperature, θ(K)

500
h=120
h=240
0
0 100 200 300 400 500
-500
Tim e, t (sec) h=480
-1000

-1500

Figure 4. Comparison of Euler’s method with exact solution for different step sizes
Effects of step size on Euler’s
Method
800

400
Temperature,θ(K)

0
0 100 200 300 400 500
-400
Step size, h (s)
-800

-1200

Figure 5. Effect of step size in Euler’s method.


Errors in Euler’s Method
It can be seen that Euler’s method has large errors. This can be
illustrated using Taylor series.

1 d2y 1 d3y
yi +1 = yi +
dy
(xi +1 − xi ) + (xi +1 − xi ) 2
+ (xi +1 − xi )3 + ...
dx xi , yi 2! dx 2 xi , yi
3! dx 3 xi , yi

yi +1 = yi + f ( xi , yi )( xi +1 − xi ) + f ' ( xi , yi )( xi +1 − xi ) + f ' ' ( xi , yi )( xi +1 − xi ) + ...


1 2 1 3

2! 3!

As you can see the first two terms of the Taylor series

yi +1 = yi + f (xi , yi )h are the Euler’s method.

The true error in the approximation is given by


f (xi , yi ) 2 f (xi , yi ) 3 Et  h 2
Et = h + h + ...
2! 3!
First Order Taylor Series Method
(Euler Method)

dy
y ( x0 + h) = y ( x0 ) + h + O(h 2 )
dx xy==xy0 ,
0

Notation:
xn = x0 + nh, yn = y ( xn ),
dy
= f ( xi , yi )
dx xy==xyi ,
i

Euler Method
yi +1 = yi + h f ( xi , yi )
Runge 2nd Order Method
Runge-Kutta 2nd Order Method
Includes only three terms of the Taylor series as follows:

= y i + f ( xi , y i )h + f ( xi , y i )h 2
1
y i +1 (1)
2!
dy
For = f ( x, y ), y (0) = y0
dx
Runge Kutta 2nd order method is given by
yi +1 = yi + (a1k1 + a2 k 2 )h (2)
where
k1 = f (xi , yi )
k2 = f (xi + p1h, yi + q11k1h )

Equating Equation (1) and (2) , gives the following three equations:
a1 + a2 = 1
1
a 2 p1 =
2
1
a 2 q11 =
2
Heun’s Method
Here a2=1/2 is chosen, giving

1
a1 =
2
p1 = 1
q11 = 1

resulting in
1 1 
yi +1 = yi +  k1 + k2 h
2 2 

where
k1 = f (xi , y i )
k 2 = f (xi + h, yi + k1 h )
Midpoint Method
Here a2 = 1 is chosen, giving

a1 = 0
1
p1 =
2
1
q11 =
2
resulting in
yi +1 = yi + k2h

where

k1 = f (xi , yi )
 1 1 
k 2 = f  x i + h , y i + k1 h 
 2 2 
Ralston’s Method
Here a2 = 2 is chosen, giving
3
1
a1 =
3
3
p1 =
4
3
q11 =
4
resulting in
1 2 
yi +1 = yi +  k1 + k 2 h
3 3 
where
k1 = f (xi , yi )
 3 3 
k 2 = f  x i + h , y i + k1 h 
 4 4 
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature of
300K. Assuming heat is lost only due to radiation, the differential equation
for the temperature of the ball is given by
d
dt
( )
= −2.2067 10−12  4 − 81 108 , (0 ) = 1200K

Find the temperature at t = 480 seconds using Heun’s method. Assume a step size of
h = 240 seconds.
d
dt
(
= −2.2067 10−12  4 − 81 108 )
(
f (t , ) = −2.206710−12  4 − 81108 )
1 1 
 i +1 =  i +  k1 + k 2 h
2 2 
Solution

Step 1: i = 0, t0 = 0,0 =  (0) = 1200K

k1 = f (t0 , o ) k 2 = f (t0 + h, 0 + k1h )


= f (0,1200) = f (0 + 240,1200 + (− 4.5579)240)
= −2.206710−12 (12004 − 81108 ) = f (240,106.09)
= −4.5579 (
= −2.206710−12 106.094 − 81108 )
= 0.017595
1 1 
1 =  0 +  k1 + k 2 h
2 2 
1 
= 1200 +  (− 4.5579) + (0.017595)240
1
2 2 
= 1200 + (− 2.2702)240
= 655.16K
Solution Cont.
Step 2: i = 1, t1 = t 0 + h = 0 + 240 = 240,1 = 655.16K
k1 = f (t1 ,1 ) k 2= f (t1 + h,1 + k1h )
= f (240,655.16) = f (240 + 240,655.16 + (− 0.38869)240)
= f (480,561.87)
= −2.206710−12 (655.164 − 81108 )
= −0.38869
(
= −2.206710−12 561.874 − 81108 )
= −0.20206

1 1 
 2 = 1 +  k1 + k 2 h
2 2 
1 
= 655.16 +  (− 0.38869) + (− 0.20206)240
1
2 2 
= 655.16 + (− 0.29538)240
= 584.27K
Solution Cont.

The exact solution of the ordinary differential equation is given by


the solution of a non-linear equation as

 − 300
0.92593ln − 1.8519 tan −1 (0.0033333 ) = −0.22067 10−3 t − 2.9282
 + 300

The solution to this nonlinear equation at t=480 seconds is

 (480) = 647.57K
Comparison with exact results
1200
Temperature, θ(K)

Exact h=120
800

h=240
400
h=480

0
0 100 200 300 400 500

-400
Time, t(sec)

Figure 2. Heun’s method results for different step sizes


Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h

Step size, h (480) Et |єt|%

480 −393.87 1041.4 160.82


240 584.27 63.304 9.7756
120 651.35 −3.7762 0.58313
60 649.91 −2.3406 0.36145
30 648.21 −0.63219 0.097625

 (480) = 647.57K (exact)


Effects of step size on Heun’s
Method
800
Temperature, θ(480)

600

400

200

0
0 100 200 300 400 500
-200 Step size, h

-400

Figure 3. Effect of step size in Heun’s method


Comparison of Euler and Runge-
Kutta 2 Order Methods
nd

Table 2. Comparison of Euler and the Runge-Kutta methods

Step size, (480)


h
Euler Heun Midpoint Ralston
480 −987.84 −393.87 1208.4 449.78
240 110.32 584.27 976.87 690.01
120 546.77 651.35 690.20 667.71
60 614.97 649.91 654.85 652.25
30 632.77 648.21 649.02 648.61

 (480) = 647.57K (exact)


Comparison of Euler and Runge-
Kutta 2nd Order Methods
Table 2. Comparison of Euler and the Runge-Kutta methods

t %
Step size,
h Euler Heun Midpoint Ralston

480 252.54 160.82 86.612 30.544


240 82.964 9.7756 50.851 6.5537
120 15.566 0.58313 6.5823 3.1092
60 5.0352 0.36145 1.1239 0.72299
30 2.2864 0.097625 0.22353 0.15940

 (480) = 647.57K (exact)


Comparison of Euler and Runge-
Kutta 2nd Order Methods
1200

1100
Temperature, θ(K)

1000 Midpoint

900 Ralston

800 Heun

700
Analytical
600
Euler
500
0 100 200 300 400 500 600

Time, t (sec)

Figure 4. Comparison of Euler and Runge Kutta 2nd order methods with
exact results.
Runge 4th Order Method
Runge-Kutta 4th Order Method
- Includes only five terms of the Taylor series as follows:

y i +1 = y i + f (xi , y i )h + f (xi , y i )h 2 + f '' (xi , y i )h 3 + f (xi , yi )h 4


1 ' 1 1 '''
(1)
2! 3! 4!
dy
For = f ( x, y ), y (0) = y0
dx
- Runge Kutta 4th order method is given by
yi +1 = yi + (a1k1 + a2 k 2 + a3 k3 + a4 k 4 )h (2)

- Equating Equation (1) and (2), one of the popular solutions is:

yi +1 = yi + (k1 + 2k2 + 2k3 + k4 )h


1
6
where
 1 1 
k1 = f (xi , yi ) k3 = f  xi + h, yi + k 2 h 
 2 2 
 1 1 
k2 = f  xi + h, yi + k1h  k4 = f (xi + h, yi + k3h )
 2 2 
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature of
300K. Assuming heat is lost only due to radiation, the differential equation
for the temperature of the ball is given by
d
dt
( )
= −2.2067 10−12  4 − 81 108 , (0 ) = 1200K

Find the temperature at t = 480 seconds using Runge-Kutta 4th order method.

Assume a step size of h = 240 seconds.


d
dt
(
= −2.2067 10−12  4 − 81 108 )
(
f (t , ) = −2.206710−12  4 − 81108 )
 i +1 =  i +
1
(k1 + 2k 2 + 2k 3 + k 4 )h
6
Solution
Step 1: i = 0, t0 = 0,  0 =  (0) = 1200

( )
k1 = f (t0 ,o ) = f (0,1200) = −2.206710−12 12004 − 81108 = −4.5579

   
k 2 = f  t0 + h,  0 + k1h  = f  0 + (240),1200 + (− 4.5579)240
1 1 1 1
 2 2   2 2 
( )
= f (120,653.05) = −2.2067 10−12 653.054 − 81 108 = −0.38347

   
k3 = f  t0 + h,  0 + k 2 h  = f  0 + (240),1200 + (− 0.38347)240
1 1 1 1
 2 2   2 2 
( )
= f (120,1154.0 ) = 2.2067 10−12 1154.0 4 − 81 108 = −3.8954

k 4 = f (t0 + h,  0 + k3h ) = f (0 + (240),1200 + (− 3.984)240)


(
= f (240,265.10) = 2.206710−12 265.104 − 81108 = 0.0069750 )
Solution Cont.
1 =  0 +
1
(k1 + 2k 2 + 2k3 + k4 )h
6
= 1200 + (− 4.5579 + 2(− 0.38347) + 2(− 3.8954) + (0.069750))240
1
6
= 1200 + (− 2.1848)240
1
6
= 675.65K

1 is the approximate temperature at

t = t1 = t0 + h = 0 + 240 = 240

 (240)  1 = 675.65K
Solution Cont.
Step 2: i = 1, t1 = 240,1 = 675.65K

( )
k1 = f (t1 ,1 ) = f (240,675.65) = −2.206710−12 675.654 − 81108 = −0.44199

   
k 2 = f  t1 + h, 1 + k1h  = f  240 + (240), 675.65 + (− 0.44199)240
1 1 1 1
 2 2   2 2 
( )
= f (360,622.61) = −2.206710−12 622.614 − 81 108 = −0.31372

   
k3 = f  t1 + h, 1 + k 2 h  = f  240 + (240),675.65 + (− 0.31372)240
1 1 1 1
 2 2   2 2 
( )
= f (360, 638.00) = 2.2067 10−12 638.004 − 81108 = −0.34775

k 4 = f (t1 + h,1 + k3 h ) = f (240 + (240),675.65 + (− 0.34775)240)


( )
= f (480,592.19) = 2.206710−12 592.194 − 81108 = −0.25351
Solution Cont.
1
 2 = 1 + (k1 + 2k2 + 2k3 + k4 )h
6
= 675.65 + (− 0.44199+ 2(− 0.31372) + 2(− 0.34775) + (− 0.25351))240
1
6
= 675.65 + (− 2.0184)240
1
6
= 594.91K
2 is the approximate temperature at

t2 = t1 + h = 240 + 240 = 480

 (480)   2 = 594.91K
Solution Cont

The exact solution of the ordinary differential equation is given by the


solution of a non-linear equation as
 − 300
0.92593ln − 1.8519tan −1 (0.00333) = −0.22067 10−3 t − 2.9282
 + 300

The solution to this nonlinear equation at t=480 seconds is

 (480) = 647.57K
Comparison with exact results
1600
Temperature, θ(K)

1200

h=120
800 Exact
h=240
400

h=480
0
0 200 400 600
-400
Time,t(sec)

Figure 1. Comparison of Runge-Kutta 4th order method with exact solution


Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h

Step size, h  (480) Et |єt|%

480 −90.278 737.85 113.94


240 594.91 52.660 8.1319
120 646.16 1.4122 0.21807
60 647.54 0.033626 0.0051926
30 647.57 0.00086900 0.00013419
 (480) = 647.57K (exact)
Effects of step size on Runge-
Kutta 4th Order Method
800
Temperature, θ(480)

600

400

200

0
0 100 200 300 400 500
-200
Step size, h

Figure 2. Effect of step size in Runge-Kutta 4th order method


Comparison of Euler and
Runge-Kutta Methods
1400
Temperature, θ(K)

1200
4th order
1000

800
Exact
600
Heun
400

200 Euler

0
0 100 200 300 400 500
Time, t(sec)

Figure 3. Comparison of Runge-Kutta methods of 1st, 2nd, and 4th order.


Higher Order Equations
ODE
We have learned Euler’s and Runge-Kutta methods to solve first order
ordinary differential equations of the form:

= f ( x, y ), y (0) = y0
dy
(1)
dx

What do we do to solve simultaneous (coupled) differential equations, or


differential equations that are higher than first order?
Higher Order Equations
ODE
An nth order differential equation of the form:

dny d n −1 y
+ ao y = f (x )
dy
a n n + a n −1 n −1 +  + a1 (2)
dx dx dx

with n − 1 initial conditions can be solved by assuming

y = z1 (3.1)

dy dz1
= = z2 (3.2)
dx dx
Higher Order Equations
ODE
d 2 y dz2
2
= = z3 (3.3)
dx dx


d n −1 y dzn −1
n −1
= = zn (3.n)
dx dx

d n y dzn
=
dxn dx
1  d n −1 y 
− a0 y + f ( x )
dy
=  − an −1 n −1  − a1
an  dx dx 

(3.n+1)
=
1
(− a n−1 z n  − a1 z 2 − a0 z1 + f (x ))
an
Higher Order Equations
ODE
The Equations from (3.1) to (3.n+1) represent n first order differential
equations as follows
dz1
= z 2 = f1 (z1 , z 2 ,, x ) (4.1)
dx
dz2
= z 3 = f 2 (z1 , z 2 ,, x ) (4.2)
dx

dzn
=
1
(− an−1 z n  − a1 z 2 − a0 z1 + f (x )) (4.n)
dx an

Each of the first order ordinary differential equations are accompanied by one
initial condition. These first order ordinary differential equations are simultaneous
in nature but can be solved by the methods used for solving first order ordinary
differential equations that we have already learned.
Example
Rewrite the following differential equation as a set of first order differential
equations.

d2y
3 2 + 2 + 5 y = e − x , y (0) = 5, y(0) = 7
dy
dx dx
Solution
The ordinary differential equation would be rewritten as follows. Assume

dy
= z,
dx
Then
d 2 y dz
2
=
dx dx
Substituting this in the given second order ordinary differential equation gives

= z, y (0) = 5
dy
dx
Solution Cont.
= (e − 2 z − 5 y ), z (0) = 7
dz 1 − x
dx 3

Now one can apply any of the numerical methods used for solving first order
ordinary differential equations.
Example
Given

d2y
2
+ 2
dy
+ y = e −t
, y (0 ) = 1,
dy
(0) = 2 , find by Euler’s method
dt dt dt

(a) y(0.75)

(b) the absolute relative true error for part(a), if y(0.75) exact = 1.668

(c)
dy
(0.75)
dt

Use a step size of h = 0.25.


Solution
First, the second order differential equation is written as two simultaneous
first-order differential equations as follows. Assume

dy
=z
dt
then
dz
+ 2 z + y = e −t
dt

dz
= e −t − 2 z − y
dt
Solution Cont.
So the two simultaneous first order differential equations are

= z = f1 (t,y,z ), y (0) = 1
dy
(E2.1)
dt

= e −t − 2 z − y = f 2 (t , y , z ), z (0) = 2
dz
(E2.2)
dt

Using Euler’s method on Equations (E2.1) and (E2.2), we get

yi +1 = yi + f1 (t i , yi , z i )h (E2.3)

z i +1 = z i + f 2 (t i , yi , z i )h (E2.4)
Solution Cont.
a) To find the value of y(0.75) and since we are using a step size of 0.25 and
starting at t = 0 , we need to take three steps to find the value of y(0.75).

For i = 0, t0 = 0, y0 = 1, z0 = 2

From Equation (E2.3)

y1 = y 0 + f1 (t 0 , y 0 , z 0 )h

= 1 + f1 (0,1,2)(0.25)
= 1 + 2(0.25)
= 1.5
Solution Cont.
y1 is the approximate value of y at

t = t1 = t 0 + h = 0 + 0.25 = 0.25

y1 = y(0.25)  1.5

From Equation (E2.4)

z1 = z 0 + f 2 (t 0 , y 0 , z 0 )h

= 2 + f 2 (0,1,2)(0.25)
(
= 2 + e −0 − 2(2) − 1 (0.25) )
=1
dy
Z1 is the approximate value of Z (same as ) at t =0.25
dt
z1 = z(0.25)  1
Solution Cont.
For i = 1, t1 = 0.25, y1 = 1.5, z1 = 1

From Equation (E2.3)


y2 = y1 + f1 (t1 , y1 , z1 )h

= 1.5 + f1 (0.25,1.5,1)(0.25)

= 1.5 + (1)(0.25)
= 1.75
y2 is the approximate value of y at

t = t 2 = t1 + h = 0.25 + 0.25 = 0.50

y2 = y(0.5)  1.75
Solution Cont.
From Equation (E2.4)
z 2 = z1 + f 2 (t1 , y1 , z1 )h

= 1 + f 2 (0.25,1.5,1)(0.25)
= 1 + (e −0.25 − 2(1) − 1.5)(0.25)

= 1 + (− 2.7211)(0.25)
= 0.31970

Z2 is the approximate value of Z at

t = t 2 = 0.5

z2 = z(0.5)  0.3197
Solution Cont.
For i = 2, t2 = 0.5, y2 = 1.75, z2 = 0.31970

From Equation (E2.3)

y3 = y 2 + f1 (t 2 , y 2 , z 2 )h

= 1.75 + f1 (0.50,1.75,0.31970)(0.25)
= 1.75 + (0.31970)(0.25)
= 1.8299

y3 is the approximate value of y at

t = t 3 = t 2 + h = 0.5 + 0.25 = 0.75

y3 = y(0.75)  1.8299
Solution Cont.
From Equation (E2.4)

z 3 = z 2 + f 2 (t 2 , y 2 , z 2 )h

= 0.31972+ f 2 (0.50,1.75,0.31970)(0.25)

= 0.31972 + (e −0.50 − 2(0.31970) − 1.75)(0.25)

= 0.31972+ (− 1.7829)(0.25)

= −0.1260
Z3 is the approximate value of Z at

t = t 3 = 0.75
z 3 = z (0.75)  −0.12601

y (0.75)  y3 = 1.8299
Solution Cont.
b) The exact value of y(0.75) is

y(0.75) exact = 1.668

The absolute relative true error in the result from part (a) is

1.668 − 1.8299
t =  100
1.668
= 9.7062%

c)
dy
(0.75) = z 3  −0.12601
dx
The End

You might also like