Numerical Solution of
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‘ = f(x, y), y(x0) = y0
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
some domain. Thus y (x) satisfies initial value problem .
x0 h
y ( x0 h) y0
(k )
f [ x, y ( k 1)
( x)]dx
x0
Picard's Method of Successive Approximation
x
y1(x) = y0 + x0
f ( x, y0 )dx
x
y2(x) = y0 + x0
f ( x, y1 ( x))dx
.................................
.................................
x
yn+1(x) = y0 + x0
f ( x, yn ( x ))dx
Example 6 Find the Picard approximations y1, y2, y3 to the solution of
the initial value problem y‘ = y, y(0) = 2. Use y3 to estimate the value of
y (0.8) and compare it with the exact solution.
Solution: By, Picard's Method of Successive Approximation
x
y1(x) = y0 +
x0
f ( x, y0 )dx Let y0 = 2, the value of y1 is
x
y1= 2 + 0 2dx 2 2 x
x
y2(x) = y0 +
x0
f ( x, y1 )dx
x
y2 = 2+
0
(2 + 2x)dx = 2 + 2x + x 2
x
y3(x) = y0 +
x0
f ( x, y2 )dx
3
x x
y3 = 2 + 0 2
2
( 2 2 x x ) dx 2 2 x x
3
At x= 0.8
2 1
y3= 2 + 2(0.8) + (0.8) + (0.8)3 = 4.41
3
The solution of the initial-value problem, found by
separation of variables, is y = 2ex. At x = 0.8
y(0.8) = 2e0.8 = 4.45
Example 7 Find the Picard approximations y1, y2, y3 to the solution of
the initial value problem y‘ = x + y, y(0) = 1. Use y3 to estimate the value
of y (0.2) and compare it with the exact solution.
Solution: By, Picard's Method of Successive Approximation
x
y1(x) = y0 +
x0
f ( x, y0 )dx Let y0 = 1, the value of y1 is
x x2
y1= 1 + 0 ( x 1)dx 1 x
2
x
y2(x) = y0 +
x0
f ( x, y1 )dx
x x2 3
y2 = 1 + 0 (1 + 2x + )dx = 1+ x + x2 x
2 6
x
y3(x) = y0 +
x0
f ( x, y2 )dx
3 3 4
x x x x
y3 = 1 + 0 (1 2 x x 2
) dx 1 x x
2
6 3 24
At x= 0.2
3 4
0.2 0.2
y (0.2) 1 0.2 0.2 2 = 1.2427
3 24
The solution of the linear differential equation is,
y = - (x + 1) + 2ex.
y(0.2) = -1.2 + 2e0.2 = 1.243
Example 8 Solve the boundary value problem y’ = xy , y(1) = 1 by Computing
the first three steps using Picard’s Method.
Solution: By, Picard's Method of Successive Approximation
x
y1(x) = y0 +
x0
f ( x, y0 )dx Let y0 = 1, the value of y1 is
2
x 1
y1= 1 + 1 ( x)dx
x
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)
y2= y1 + h f(x1, y1) yi+1, Predicted value
Φ
.................... yi
h
...................., Step size
xi+1 x
xi
yn+1 = yn + h f(xn, yn)
Figure 2. General graphical interpretation of Euler’s method
Example 9 Given y’ = - y and y (0) = 1, determine the value of y at x = (0.01),
(0.02), (0.03), (0.04) by Euler’s method. Compare the answers with exact
solution.
Solution: y’ = - y, x0 = 0, y0 = 1, x1 = 0.01, x2 = 0.02, x3 = 0.03, x4 = 0.04.
We have to find y1, y2, y3, y4 which takes h = 0.01,
By Euler’s algorithm, yn+1 = yn + h f (xn, yn)
y1 = y0 + h f (x0, y0) = 1 + (0.01) (-1) = 0.99
y2 = y1 + h f (x1, y1) = 0.99 + (0.01) (-y1) = 0.99 + (0.01) (-0.99) = 0.9801
y3 = y2 + h f (x2, y2) = 0.9801 + (0.01) (-0.9801) = 0.9703
y4 = y3 + h f (x3, y3) = 0.9703 + (0.01) (-0.9703) = 0.9606
The exact solution of the problem is, y = e-x.
y(0.01) = e-0.01 = 0.99005, y(0.04) = e-0.04 = 0.960789
Example 10 Solve y’ = 2x + 3y, y(0) = 1 by Euler’s method for
y (0.1), y (0.2) & y (0.3). Compare the answer with exact solution.
Solution: y’ = 2x + 3y, x0 = 0, y0 = 1, x1 = 0.1, x2 = 0.2, x3 = 0.3.
We have to find y1, y2, y3, which takes h = 0.1,
By Euler’s algorithm, yn+1 = yn + h f (xn, yn)
y1 = y0 + h f (x0, y0) = 1 + (0.1) (2x0 + 3y0) = 1 + (0.1) (3) = 1.3
y2 = y1 + h f (x1, y1) = 1.3 + (0.1) (2x1 + 3y1) = 1.3 + (0.1) (4.1) = 1.71
y3 = y2 + h f (x2, y2) = 1.71 + (0.1) (5.53) = 2.263
The exact solution of the problem is, y = (-2/3)x – (2/9) + (11/9)e3x.
y(0.1) = 1.361, y(0.3) = 2.584
Example 11 Solve y’ = 2x + y, y(0) = 1 by 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.
By Euler’s algorithm, yn+1 = yn + h f (xn, yn)
xn yn yn+1 = yn+ 0.1(2xn+yn)
0 1.0 y1 = 1.0 + 0.1[2(0)+1.0] = 1.1
0.1 1.1 y2 = 1.1 + 0.1[2(0.1)+1.1] = 1.23
0.2 1.23 y3 = 1.23 + 0.1[2(0.2)+1.23] = 1.39
0.3 1.39 y4 = 1.39 + 0.1[2(0.3)+1.39] = 1.59
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
Euler’s Euler’s truncation error
O(x2) per step
Methods Improving Euler
Motivated by
Geometric Interpretation
Copyright © Jones and Bartlett;滄海
Ch6_26
書局
Improved Euler’s Method
f ( xn , yn ) f ( xn1 , y ) *
• yn1 yn h n 1
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.
Copyright © Jones and Bartlett;滄海
Ch6_27
書局
Example 12 Solve y’ = 2x + y, y(0) = 1 by Improved Euler’s method for y
(0.4). Compare the answer with exact solution.
Solution: y’ = 2x + y, x0 = 0, y0 = 1, x1 = 0.4, h = 0.4.
By Improved Euler’s algorithm, yn+1 * = yn + h f (xn, yn)
y1 * = y0 + h f (x0, y0) = 1 + (0.4) (2x0 + y0) = 1 + (0.4) (1) = 1.4
f ( xn , yn ) f ( xn1 , y )
*
yn1 yn h n 1 1
M = [f(0,1) + f(0.4,1.4)]
2 2
1
= 2 [(2(0)+1)+(2(0.4)+1.4)]=1.6
y1= y(0.4) = 1+ 0.4(1.6) = 1.64
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 1 1.1 1.15 1.115
0.1 1.115 1.247 1.481 1.263
0.2 1.263 1.429 1.846 1.448
0.3 1.448 1.653 2.250 1.673
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 1 1.1 0.95901 1.09591
0.1 1.09591 1.1953 0.8819 1.1841
0.2 1.1841
Midpoint Method
y( x 2x ) y( x) f ( x, y( x)) 2x
y( x x) y( x) f ( x 2x , y( x 2x )) x
Euler’s Modified Method
y ( x ) y ( x) f ( x, y ( x))
h
2
h
2
y ( x h) y ( x) hf ( x h2 , y ( x h2 ))
OR
yn+1 =yn + h[f(xn+ h/2, yn + h/2 f (xn, yn))
Example 15 Compute y at x = 0.25 by modified Euler method given
y’ = 2xy, y (0) = 1. Compare the result with exact solution.
Solution: Here f (x, y) = 2xy, x0 = 0, y0 = 1
Take h = 0.25, x1 = 0.25
h h
By modified Euler method, y1 = y0 + h x
[f 0 2 0 2
, y + f (x 0 , y 0 ]
)
f (x0, y0) = f (0, 1) = 2 (0) (1) = 0
y1 = 1 + 0.25 [f (0.125, 1)] = 1 + 0.25 [2 0.125 1] = 1.0625
The exact solution of the problem is, y = ex^2, y(0.25) = 1.0645
Example 16 Compute y at x = 0.5 by modified Euler method given
y’ = 2xy, y (0.25) = 1.0625 Compare the result with exact solution.
Solution: Here f (x, y) = 2xy, x0 = 0.25, y0 = 1.0625
Take h = 0.25, x1 = 0.5
h h
By modified Euler method, y1 = y0 + h x
[f 0 2 0 2
, y + f (x 0 , y 0 ]
)
f (x0, y0) = f (0.25, 1.0625) = 2 (0.25) (1.0625) = 0.53125
y1 = 1.0625 + 0.25 [f (0.375, 1.1289)] = 1.0625 + 0.25 [2 0.375 1.1289]
= 1.2742
The exact solution of the problem is, y = ex^2, y(0.5) = 1.284
Example 17 Compute y at x = 0.5 by modified Euler method given
y’ = 2xy, y (0) = 1. Compare the result with exact solution.
Solution: Here f (x, y) = 2xy, x0 = 0, y0 = 1
Take h = 0.5, x1 = 0.5
h h
By modified Euler method, y1 = y0 + h x
[f 0 2 0 2
, y + f (x 0 , y 0 ]
)
f (x0, y0) = f (0, 1) = 2 (0) (1) = 0
y1 = 1 + 0.5 [f (0.25, 1)] = 1 + 0.5 [2 0.25 1] = 1.25
The exact solution of the problem is, y = ex^2, y(0.5) = 1.284
Runge-Kutta Methods
• The method doesn’t rely on polynomial approximation.
• Solution can be presented by a finite Taylor series of the
form:
2 k
h h (k )
yn 1 yn hy 'n y ' 'n yn
2! k!
yn 1 yn h{a0 f ( xn , yn ) a1 f [( xn 1h), ( yn b1h)]
ak f [( xn k h), ( yn bk h)}
Combine the above two equations
y n 1 yn 0t0 1t1 k t k
Runge-kutta Methods
y n 1 yn 0t0 1t1 k t k
where
t 0 hf ( xn , yn )
t1 hf [( xn 1h), ( yn 1, 0t0 )]
t 2 hf [( xn 2 h), ( yn 2, 0t0 2,1t1 )]
t k hf [( xn k h), ( yn k , 0t0 k ,1t1 k ,k 1t k 1 )]
y( xi h) yi f i h [ fx fy f i ] h2 O(h3 )
2
i i
RK 1st Order
k 1
a0t0 a0 hf ( xn , yn )
yn 1 yn a0 f ( xn , yn )h
Compare with Taylor's expantion
a0 1
yn 1 yn f ( xn , yn )h Euler' s method
Runge-Kutta 2nd Order Method
For k 2 yn 1 yn (a1k1 a2 k 2 )h
yn 1 yn 0.5t0 0.5t1 yn 1 yn f ( xn 12 h, yn h2 f ( xn , yn ))h
yn 1 yn (a1k1 a2 k 2 )h yn 12 (k1 k 2 )h
t0 hf[(xn , yn )]
k1 f ( xn , yn ), k 2 f ( xn h, yn f n h)
t1 hf[(xn h),(yn t0 )] ork 2 f ( xn h, yn k1h)
So, the Runge – kutta method of second order is nothing but the
modified Euler method.
Runge-Kutta 4th Order Method
For k 4 yn 1 yn 6 (k1 2k 2 2k3 k 4 )
1
yn 1 yn (t0 2t1 2t 2 t3 ) / 6 where,
t0 hf[(xn , yn )] k1 hf ( xn ,yn )
t1 hf[(xn 0.5h),(yn 0.5t0 )] k 2 hf ( xn 12 h,yn 12 k1 )
t 2 hf[(xn 0.5h),(yn 0.5t1 )] k3 hf ( xn 12 h,yn 12 k 2 )
t3 hf[(xn h),(yn t 2 )] k 4 hf ( xn h,yn k3 )
Example 18 Use the RK4 method with h = 0.5 to obtain y(0.5) for the
solution of y’ = 2xy, y(0) = 1. Compare the answer with exact solution.
Solution: Here f (x, y) = 2xy, x0 = 0, y0 = 1
Take h = 0.5, x1 = 0.5 k1 hf ( x0 , y0 ) (0.5)2 x0 y0 0
By RK4 Method,
k 2 hf ( x0 12 (0.5), y0 12 (0))
yn 1 yn 16 (k1 2k 2 2k3 k 4 )
(0.5) f (0.25,1) 0.5(2(0.25)(1)) 0.25
where
k3 hf ( x0 12 (0.5), y0 12 (0.25))
k1 hf ( xn ,yn )
(0.5)2(0.25)(1.125) 0.28125
k 2 hf ( xn h,yn k1 )
1
2
1
2
k3 hf ( xn 12 h,yn 12 k 2 ) k 4 hf ( x0 0.5, y0 (0.28125))
k 4 hf ( xn h,yn k3 ) (0.5)2(0.5)(1.28125) 0.640625
Copyright © Jones and Bartlett;滄海
Ch6_41
書局
Therefore,
1
y1 y0 (k1 2k 2 2k3 k 4 )
6
1
1 (0 2(0.25) 2(0.28125) 0.64025)
6
1.28379
The exact solution of the problem is, y = ex^2, y(0.5) = 1.284
Copyright © Jones and Bartlett;滄海
Ch6_42
書局
Example 19 Use the RK-4 method with h = 1 to obtain y(1) for the
solution of y’ = 2xy, y(0) = 1. Compare the answer with exact solution.
Solution: Here f (x, y) = 2xy, x0 = 0, y0 = 1
Take h = 1, x1 = 1 k1 hf ( x0 , y0 ) (1)2 x0 y0 0
By RK-4 Method,
k 2 hf ( x0 12 (1), y0 12 (0))
yn 1 yn 16 (k1 2k 2 2k3 k 4 ) (1)2(0.5)(1) 1
where
k3 hf ( x0 12 (1), y0 12 (1))
k1 hf ( xn ,yn )
(1)2(0.5)(1.5) 1.5
k 2 hf ( xn h,yn k1 )
1
2
1
2
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
The exact solution of the problem is, y = ex^2, y(1) = 2.7183
Copyright © Jones and Bartlett;滄海
Ch6_44
書局
Example 20 A certain chemical reaction takes place such that the time-rate of
change of the amount of the unconverted substance q is equal to -2q. If the
initial mass is 50 grams, use the RK method to estimate the amount of
unconverted substance at t = 0.8 sec.
dq
Solution: The initial-value problem is = -2q, q(0) = 50
dt
Here f (x, y) = -2y, x0 = 0, y0 = 50, h = 0.8, x1 = 0.8
By RK-4 Method, k1 hf ( x0 , y0 ) (0.8)(2 y0 ) 80
yn 1 yn 16 (k1 2k 2 2k3 k 4 )
k 2 hf ( x0 12 (0.8), y0 12 (80))
where
(0.8)(2(10)) 16
k1 hf ( xn ,yn )
k3 hf ( x0 12 (0.8), y0 12 (16))
k 2 hf ( xn 12 h,yn 12 k1 )
(0.8)(2(42) 67.2
k3 hf ( xn 12 h,yn 12 k 2 )
k 4 hf ( x0 0.8, y0 (67.2))
k 4 hf ( xn h,yn k3 )
Copyright © Jones and Bartlett;滄海
(0.8)(2(17.2)) 27.52
Ch6_45
書局
Therefore,
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.
Copyright © Jones and Bartlett;滄海
Ch6_46
書局
Example 21 Use the RK-4 method to obtain y(0.2) for the solution of
y’ = y x , y(0) = 1.
2 2
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
Copyright © Jones and Bartlett;滄海
Ch6_48
書局