Chapter 8. Numerical Solution of Ordinary Differential Equations
Chapter 8. Numerical Solution of Ordinary Differential Equations
Chapter 8. Numerical Solution of Ordinary Differential Equations
For an n-th order ordinary differential equation, n conditions are required to solve the
equation.
d 2x
m 2 = − Kx
dt K
2
0
d x x
2
= −K m
dt m
x
with the initial off balance displacement:
x(t = 0) = x0
and initial speed:
dx(t = 0)
v(t = 0) = = v0
dt
The problem is called an initial-value problem (which is associated with time t ).
99
Example-2: Now consider the deflection of the sea boat mast
The governing equation is
f EI
d 2 y M ( z) f
2
= = ( L − z )2 L
dz EI 2 EI
z
y
f: wind force, EI: the bending stiffness
The conditions (boundary conditions) at the built-in end are:
y ( z = 0) = 0
dy
( z = 0) = 0
dz
100
8.2. First-order ordinary differential equations
Euler’s method
Consider a first-order equation
d
= f ( x, ) (1)
dx
with
( x0 ) = 0
(b) = ?
d
( x = a)
dx
(a)
x
a b
x
Taylor series
d (a ) d 2 (a) x 2
b = a + x + +
dx dx 2
ignoring the second and higher order terms, we have
d (a)
b = a + x = a + f [a, (a )]x
dx
We use the tangent at point a to approximate the function/curve.
Now we divide the solution domain into a number of small grid cells.
101
3 4
1
2
numerical solution
0
true solution
x x x x
x0 x1 x2 x3 x4 x
0 1 2 3 4
x1 = x0 + x, 1 = 0 + f ( x0 , 0 )x
x2 = x1 + x, 2 = 1 + f ( x1 , 1 )x
x3 = x2 + x, 3 = 2 + f ( x2 , 2 )x
This is called Euler’s method. The accuracy of the Euler’s method is first -order.
d
j +1 = j + f ( x j , j ) x = j + 0.2 (x = x j )
dx
= j + ( x j + j ) 0.2 = 0.2 x j + 1.2 j
102
The exact solution is ( x) = e x − x − 1
j +1 = 0.2 x j + 1.2 j
j xj j j +1 exact j error
0 0 0 0 0 0
j x analytical error
0 0 0 0 0
1 0.2 0 0.021 0.021
2 0.4 0.04 0.092 0.052
3 0.6 0.1280 0.222 0.094
4 0.8 0.2736 0.4255 0.1519
5 1.0 0.4883 0.7183 0.2300
103
Improved Euler’s Method
d
to solve = f ( x, )
dx
This is a two-step method:
j +1 = j + f ( x j , j )x (3)
f ( x j +1 , j +1 )
1
[ f ( x j , j ) + f ( x j +1 , j +1 )]
2
f ( x j , j )
xj x j +1 x
1
j +1 = j + [ f ( x j , j ) + f ( x j +1 , j +1 )]x (4)
2
It can be shown that the improved Euler’s method is a second-order method
(error O ( x 2 ) ).
104
Example: to solve the same problem:
d
= x + with (0) = 0
dx
using the improved Euler’s method
1
from eq. (4) j +1 = j + [ f ( x j , j ) + f ( x j +1 , j +1 )]x
2
1
= j + [( x j + j ) + ( x j +1 + j +1 )] 0.2
2
1
= j + [( x j + j ) + ( x j + 0.2 + 0.2 x j + 1.2 j )] 0.2
2
= 0.02 + 0.22x j + 1.22 j
j x j exact error
0 0 0 0 0
1 0.2 0.020 0.0214 0.0014
2 0.4 0.0884 0.0918 0.0034
3 0.6 0.2158 0.2221 0.0063
4 0.8 0.4153 0.4255 0.0102
5 1.0 0.7027 0.7183 0.0156
The errors are smaller than those derived from the original Euler’s
method.
105
8. 3. Linked (simultaneous) First-order Ordinary Differential Equations
We have studied methods for the numerical solution of equations of the form
dx
= f (t , x) with x(t = t0 ) = x0
dt
It is also possible to have a set of linked first-order equations
dx
= f (t , x, y ) , x(t = t0 ) = x0 (5, a)
dt
dy
= g (t , x, y ), y (t = t0 ) = y0 (5, b)
dt
For example,
dx
= x − y 2 + xt
dt
dy
= 2 x 2 + xy − t
dt
x j +1 = x j + tf (t , x j , y j ) (6. a)
y j +1 = y j + tg (t , x j , y j ) (6. b)
y j +1 = y j + tg (t , x j , y j ) (7. b)
t (8. a)
x j +1 = x j + [ f (t j , x j , y j ) + f (t j +1 , xj +1 , y j +1 )]
2
t (8. b)
y j +1 = y j + [ g (t j , x j , y j ) + g (t j +1 , xj +1 , y j +1 )]
2
106
Example: to find the value of x(1.4) which satisfies the following problem:
dx
= x − y 2 + xt , x(t = 1) = 0.5
dt
dy
= 2 x 2 + xy − t , y (t = 1) = 1.2
dt
Solution:
j=0 1 2 3 4
x j +1 = x j + tf (t j , x j , y j ) = x j + 0.1 ( x j − y 2j + x j t j )
y j +1 = y j + tg (t j , x j , y j ) = y + 0.1 (2 x 2 + x y − t )
j j j j j
y1 = y0 + 0.1 (2 x02 + x0 y0 − t0 )
107
For j=1 2 (i.e., t=1.1 to 1.2)
y2 = y1 + 0.1 (2 x12 + x1 y1 − t1 )
……
x4 = 0.2980
dy1
= f1 ( x, y1 , y2 ,, yn ) y1 ( x = x0 ) = y1,0
dx
dy2 y2 ( x = x0 ) = y2,0
= f 2 ( x, y1 , y2 ,, yn )
dx
…………… …………..
dyn
= f n ( x, y1 , y2 ,, yn ) yn ( x = x0 ) = yn,0
dx
108
8. 4. Numerical Solution of Higher-order Equations
consider
d 2x dx 1
2
+ x 2t − xt 2 = t 2 (9)
dt dt 2
dx
x(0) = 1.2 , (t = 0) = 0.8
dt
If we introduce an additional variable
dx d 2 x d dx dy
y= 2
= ( )=
dt dt dt dt dt
Then we have
dx
=y , x(0) = 1.2
dt
dy 1
+ x 2ty − xt 2 = t 2 , y (0) = 0.8
dt 2
Thus the original single second-order differential equation is replaced by a pair of
linked first-order differential equations. (one 2nd order equation = two 1st order
equations).
109
Example:
Find the value of x(0.2) satisfying the initial-value problem
d 3x d 2x dx
3
+ xt 2 + t − t 2 x = 0
dt dt dt
dx d 2x
x(t = 0) = 1 , (t = 0) = 0.5 (t = 0) = −0.2
dt , dt 2
Solution
Since this is a third-order equation, we need to introduce two new variables:
dx
y=
dt
dy d 2 x
z= =
dt dt 2
Then the equation is transformed into:
dx
= y = f1 (t , x, y, z ) , x(0) = 1
dt
dy
= z = f 2 (t , x, y, z ) , y (0) = 0.5
dt
dz
= − xtz − ty + t 2 x = f 3 (t , x, y, z ), z (0) = −0.2
dt
Applying Euler’s method
110
8.5. Boundary-value Problems
d 2x t dy t
− (1 − ) x = t dt = (1 − )x + t
2
5
dt 5 dx
=y
dt
x
3
2
1
0 t
1 2 3
-1
111
Main steps
112
Finite difference method
Consider
d 2x t
2
− (1 − ) x = t (1)
dt 5
Main steps:
t =1 t =3
t t
t
j=0 1 2 j −1 j j +1 N
d 2x d dx = ( x j +1 − x j − x j − x j −1 ) / t x j −1 − 2 x j + x j +1
= ( ) = (2)
dt 2
dt dt t t t 2
x j −1 − 2 x j + x j +1 tj (3)
− (1 − )x j = t j
t 2 5
or
'
x j −1 − [2 + t 2 (1 − t j / 5)]x j + x j +1 = t j t 2 (3 )
113
1.5 2.0 2.5 3.0
t =1
j=0 1 2 3 4
at j=1, t=1.5
j=2, t=2.0
j=3, t=2.5
− 2.175 x1 + x2 = 0.375 − x0
x1 − 2.15 x2 + x3 = 0.5
x2 − 2.125 x3 = 0.625 − x 4
x0 = 2 and x4 = −1
114
− 2.175 x1 + x2 = −1.625 (a)
(c)
x2 − 2.125 x3 = 1.625
Now, we have:
115
Backward substitution:
x2 = −0.424
x1 = 0.552
116