Numerical Solution of ODE
Numerical Solution of ODE
st
1 Order Ordinary Differential
Equations
Dr. Amit Mishra
Department of Mathematics & Humanities,
Institute of Technology,
Nirma University.
Introduction
Numerical ordinary differential equations is the part of numerical analysis which
studies the numerical solution of ordinary differential equations (ODEs). It is very
important for industrial and practical engineering applications , Mechanics, Chemistry and
Physics.
Boundary value problem
It is an ordinary differential equation which satisfies the boundary conditions.
A boundary value problem has conditions specified at the extremes of the
independent variable.
Initial value problem
It is an ordinary differential equation together with specified value, called the initial
condition, of the unknown function at a given point in the domain of the solution.
. Initial value problem has all of the conditions specified at the same value of the
independent variable in the equation and that value is at the lower boundary of the
domain
Numerical Methods for Solving 1st order ODE
• Taylor Series Method
• Picard’s Method
• Euler’s Method
• Runge Kutta Method
Taylor Series Method
It is a numerical methods for solving ordinary differential equations
(O.D.Es) with a given conditions.
y' = f(x, y), y(x0) = y0.
Taylor series expansion of the function f(x) around a point of expansion x has the
following form: (x x 0 ) (x x 0 ) 2
y(x) y(x 0 ) y(x 0 ) y(x 0 ) .......
1! 2!
Assume h = x – x0
h h2 h3
y(x 0 h) y(x 0 ) y(x 0 ) y(x 0 ) y(x 0 ) .......
Hint: 1! 2! 3!
1- When the step h becomes small, the numerical solution becomes nearly the same as the
exact solution.
2- y = f(x).
3- computing approximate values of the solution f(x) at the points: x1 = x0 +h, x2 = x0 +2h,
x3 = x0 + 3h,… y1 y(x 0 h), y 2 y(x1 h), y 3 y(x 2 h),...
Example 1 Solve the boundary value problem y’ = - y at x = 0.2, 0.4 given that
y(0) = 1.
Solution: Taylor expansion given by:
h h2 h3
y(x 0 h) y(x 0 ) y(x 0 ) y(x 0 ) y(x 0 ) .......
1! 2! 3!
Consider the point of expansion zero
h x x0 0.2 0 0.2
Evaluate the derivatives at the point of expansion zero y(x) y y(x 0 ) y(x 0 ) 1,
y(x) y(x) y(x 0 ) y(x 0 ) 1,
y(x) y(x) y(x 0 ) y(x 0 ) 1,
0.2 (0.2) 2 (0.2) 3
Then, y (0.2) y (0 0.2) 1
1!
(1)
2!
(1)
3!
(1) ....... 0.81867
0.2 (0.2) 2 (0.2)3
y (0.4) y (0.2 0.2) 0.81867 (0.81867) (0.81867) (0.81867) ....... 0.67022
1! 2! 3!
Example 2 Solve the boundary value problem y’ = - 2x - y at x = 0.1, given that
y(0) = -1.
Solution: Taylor expansion given by:
h h2 h3
y(x 0 h) y(x 0 ) y(x 0 ) y(x 0 ) y(x 0 ) .......
1! 2! 3!
Consider the point of expansion zero
h x x0 0.1 0 0.1
Evaluate the derivatives at the point of expansion zero y(x) 2 x y y(x 0 ) 2x 0 y(x 0 ) 1,
y(x) 2 y(x) y(x 0 ) 2 y(x 0 ) 3,
y(x) y(x) y(x 0 ) y(x 0 ) 3,
Then, 0.1 (0.1) 2 (0.1) 3
y (0.1) y (0 0.1) 1 (1) (3) (3) ....... 0.91451
1! 2! 3!
Example 3 Solve the boundary value problem y’ = x + y at x = 1.1, given that
y(1) = 0. Compare the answer with exact solution.
Solution: Taylor expansion given by: 2 3
h h h
y(x 0 h) y(x 0 ) y(x 0 ) y(x 0 ) y(x 0 ) .......
1! 2! 3!
Consider the point of expansion zero h x x0 1.1 1 0.1
Evaluate the derivatives at the point of expansion zero y(x) x y y(x 0 ) x 0 y(x 0 ) 1,
y(x) 1 y(x) y(x 0 ) 1 y(x 0 ) 2,
y(x) y(x) y(x 0 ) y(x 0 ) 2,
Then,
0.1 (0.1) 2 (0.1) 3
y (1.1) y (1 0.1) 0
1!
(1)
2!
(2)
3!
(2) ....... 0.11033
Example 4 Solve the boundary value problem y’ = x2 + y2 at x = 0.1, given that
y(0) = 1. Compute the answer with four decimal accuracy.
Solution: Taylor expansion given by: 2 3
h h h
y(x 0 h) y(x 0 ) y(x 0 ) y(x 0 ) y(x 0 ) .......
1! 2! 3!
Consider the point of expansion zero h x x0 0.1 0 0.1
Evaluate the derivatives at the point of expansion zero y(x) x 2 y 2 y(x 0 ) x 0 2 y(x 0 ) 2 1,
y(x) 2 x 2 y y(x) y(x 0 ) 2 x0 2 y ( x0 ) y(x 0 ) 2,
y(x) 2 2 y ' ( x) 2 2 y y(x) y(x 0 ) 2 2 y ' ( x) 2 2 y y(x) 8,
y' ' ' ' (x) 4 y ' ( x) y ' ' ( x) 2 y ' ( x) y' ' (x) 2 y ( x) y' ' ' (x)
y ' ' ' ' (x 0 ) 6 y ' ( x0 ) y' ' (x 0 ) 2 y ( x0 ) y' ' ' (x 0 ) 28,
0.1 (0.1) 2 (0.1) 3 (0.1) 4
Then, y (0.1) y (0 0.1) 1 (1) (2) (8) (28) .......
1! 2! 3! 4!
= 1 + 0.1 + 0.01 + 0.0013333 + 0.000116666 1.11145
Example 5 Solve the boundary value problem y’ = xy1/3 at x = 1.1, given that
y(1) = 1. Compute the answer with three decimal accuracy.
Solution: Taylor expansion given by: 2 3
h h h
y(x 0 h) y(x 0 ) y(x 0 ) y(x 0 ) y(x 0 ) .......
1! 2! 3!
Consider the point of expansion zero h x x0 1.1 1 0.1
Evaluate the derivatives at the point of expansion zero y(x) xy1/3 y(x 0 ) x 0 y(x 0 )1/3 1,
2 1
1 3 1
2 1 4
y(x) xy y ' y y(x 0 ) x0 y0 3 y0 ' y0 3 ,
3
3 3 3
5 2 2 2
2 3 2 1 3 1 3 1 3 2
5
2 1
2 1
2 1 2
y ' ' ' (x) xy y ' y y ' xy y ' ' y y ' y(x 0 ) x0 y0 3 y0 ' y0 3 y0 ' x0 y0 3 y0 ' ' y0 3 y0 '
9 3 3 3 9 3 3 3
2 1 4 1 8
,
9 3 9 3 9 0.1 (0.1) 2 4 (0.1) 3 8
Then, y (1.1) y (1 0.1) 1 (1) ( ) ( ) .......
1! 2! 3 3! 9
= 1 + 0.1 + 0.00666 + 0.000148 1.10681
Picard's Method of Successive Approximation
Let us consider the initial-value problem:
y ' ( x ) f ( x, y )
x
dy x0 h
f ( x, y ) dy f ( x, y )dx dy f ( x, y )dx
dx x0
x0
By, the fundamental theorem of calculus, since f(x, y)
x0 h
y ( x ) y0 f ( x, y )dx is a continuous function of x due to continuity of f and y in
x0
y = - (x + 1) + 2ex.
2 2
x
y2(x) = y0 +
x0
f ( x, y1 )dx
3
x x x x4 x2 1 1 x4 x2 5
y2 = 1 + 1 ( )dx 1
2 2 8 4 8 4 8 4 8
x
y3(x) = y0 +
x0
f ( x, y2 )dx
x x5 x3 5x x6 x 4 5x 2 1 1 5
y3 = 1 + 1 ( )dx 1
8 4 8 48 16 16 48 16 16
6 4 2
x x 5x 29
48 24 16 48
Euler’s Method
f x, y , y x0 y0
dy y
dx
True value
Rise
Slope
Run y1, Predicted
y1 y0
value
Φ
x0,y0
x1 x0
f x0 , y 0
Step size, h
y1 y0 f x0 , y0 x1 x0 x
y0 f x0 , y0 h
Figure 1 Graphical interpretation of the first step of Euler’s method
f x, y , y x0 y0
dy
Euler’s Method dx
yi 1 yi f xi , yi h y
h xi 1 xi
True Value
y1 = y0 + h f(x0, y0)
Φ
.................... yi
h
...................., Step size
xi+1 x
xi
yn+1 = yn + h f(xn, yn)
0.4 1.59
The exact solution of the problem is, y = -2x – 2 + 3ex , y(0.4) = 1.6755
Geometric Interpretation of Euler’s Method
dy
f ( x, y ), y ( x0 ) y0
dx
y dy
f ( x, y )
x dx
y f ( x, y )x
y1 y0 y f ( x0 , y0 )x
y1 y0 f ( x0 , y0 )x
Think in
terms of
Taylor’s If the true solution were a straight line, then
expansion
Euler is exact.
Euler’s Method Analysis Taylor’s Expansion
y ( x x) y ( x) y( x)x y( x) x 2
2 y( x) x 3
6
y ( x) f ( x, y )x d
dx f ( x, y ) x 2
2
where y *
n 1 yn hf ( xn , yn )
is commonly known as the Improved Euler’s method.
• In general, the improved Euler’s method is an example of predictor-
corrector method.
The exact solution of the problem is, y = -2x – 2 + 3ex , y(0.4) = 1.6755
Example 13 Solve y’ = 2x + y, y(0) = 1 by Improved Euler’s method for
y (0.4) by using four equal subintervals. Compare the answer with exact
solution.
Solution: y’ = 2x + y, x0 = 0, y0 = 1, x1 = 0.1, x2 = 0.2, x3 = 0.3, x4 = 0.4, h = 0.1.
The Improved Euler Method
M = 1 [(2xn+ yn) +(2xn+1+ yt)]
xn yn yt = yn + 0.1(2xn+yn) 2 yn+1 = yn + 0.1M
0.4 1.673
The exact solution of the problem is, y = -2x – 2 + 3ex , y(0.4) = 1.6755
Example 14 Solve y’ = y - (2x/y), y(0) = 1 by Improved Euler’s method for
y (0.2) by using two equal subintervals.
Solution: y’ =y - (2x/y), x0 = 0, y0 = 1, x1 = 0.1, x2 = 0.2, h = 0.1.
The Improved Euler Method
M= 1 [(y - (2x /y )) + (y -
n n n t
xn yn yt = yn + 0.1(yn- 2 (2x yn+1 = yn + 0.1M
n+1 /y ))]
t
(2xn/yn))
0.2 1.1841
Midpoint Method
y ( x h) y ( x) hf ( x h2 , y ( x h2 ))
OR
= 1.2742
i i
RK 1st Order
k 1
a0t0 a0 hf ( xn , yn )
yn 1 yn a0 f ( xn , yn )h
1
y1 y0 (k1 2k 2 2k3 k 4 )
6
1
1 (0 2(0.25) 2(0.28125) 0.64025)
6
1.28379
k3 hf ( xn 12 h,yn 12 k 2 ) k 4 hf ( x0 1, y0 (1.5))
k 4 hf ( xn h,yn k3 ) (1)2(1)(2.5) 5
Copyright © Jones and Bartlett;滄海
Ch6_43
書局
Therefore,
1
y1 y0 (k1 2k 2 2k3 k 4 )
6
1
1 (0 2(1) 2(1.5) 5)
6
2.6667
1
y1 y0 (k1 2k 2 2k3 k 4 )
6
1
50 (80 2(16) 2(67.2) 27.52)
6
13.52
Therefore our estimate of the mass of unconverted substance
at t = 0.8 is 13.52gm.
y 2 x2
Solution: Here f (x, y) = y 2 x2
, x0 = 0, y0 = 1
y 2 x2
Take h = 0.2, x1 = 0.2 k1 hf ( x0 , y0 ) (0.2)(1) 0.2
By RK-4 Method,
k 2 hf ( x0 12 (0.2), y0 12 (0.2))
yn 1 yn 16 (k1 2k 2 2k3 k 4 )
0.2 f (0.1,1.1) (0.2)(1.2018) 0.1967
where
k3 hf ( x0 12 (1), y0 12 (0.1967))
k1 hf ( xn ,yn )
0.2 f (0.1,1.1891) (0.2)(0.9836) 0.1971
k 2 hf ( xn 12 h,yn 12 k1 )
k3 hf ( xn 12 h,yn 12 k 2 ) k 4 hf ( x0 0.2, y0 (0.1971))
k 4 hf ( xn h,yn k3 ) (0.2)(0.9457) 0.1891
Copyright © Jones and Bartlett;滄海
書局
Therefore,
1
y1 y0 (k1 2k 2 2k3 k 4 )
6
1
1 (0.2 2(0.1967) 2(0.1971) 0.1891)
6
1.196