Numerical - Solution - To - ODE - Part 2-1
Numerical - Solution - To - ODE - Part 2-1
P. Sam Johnson
May 3, 2020
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 1/55
Overview : Runge-Kutta Methods
These methods agree with Taylor’s series solution upto the terms of hr
where r is the order of the Runge-Kutta method.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 2/55
Overview : Predictor-Corrector Methods
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 3/55
Introduction
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 4/55
Introduction
In Modified Euler’s method, the slope of the solution curve has been
approximated with the slopes of the curve at the end points of the each
sub interval in computing the solution.
where h is the step length and yi and yi+1 are the values of y at xi and
xi+1 respectively.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 5/55
Introduction
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 7/55
The Butcher Tableau
r (number of stages)
ci ’s for 2 ≤ i ≤ r (coefficients for x)
aij ’s for 1 ≤ j < i ≤ r (coefficients for y )
Wi ’s for 1 ≤ i ≤ r (weights).
0
c2 a21
c3 a31 a32
.. .. .. ..
. . . .
cr ar 1 ar 2 ... arr −1
W1 W2 ... Wr −1 Wr
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 8/55
Runge-Kutta Method of Order 1
Consider
dy
= f (x, y ) given y (x0 ) = y0 .
dx
The Euler’s formula for first approximation to the solution of the above
differential equation is given by
Also
h2 00 h2
yi+1 = yi + hy 0 (xi ) +
y (xi ) + y 000 (xi ) + · · · .
2! 2!
Clearly the Euler’s method agrees with the Taylor’s series solution upto the
term in h.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 9/55
Runge-Kutta Method of Order 2
K1 = hf (xi , yi )
K2 = hf (xi + c2 h, yi + a21 K1 )
yi+1 = yi + (W1 K1 + W2 K2 ) for i = 0, 1, 2, . . . .
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 10/55
Runge-Kutta Method of Order 2
Also
K1 = hfi
K2 = hf (xi + c2 h, yi + a21 K1 ) = hf (xi + c2 h, yi + a21 hfi )
(c2 h)2 (a21 hfi )2
= h fi + c2 hfx + a21 hfi fy + fxx + fyy + (c2 h)(a21 hfi )fxy + O(h4 )
2! 2!
(by Taylor’s series expansion of two variables)
h3
yi+1 = yi + (W1 + W2 )hfi + h2 (W2 c2 fx + W2 a21 ffy ) + W2 (c22 a21 ffxy + a21
2 2
f fyy ) + O(h4 )
2
Since 2-stage RK method compares with Taylor series upto h2 for any
value of c2 , the 2-stage RK method is of order two and hence this scheme
is denoted in many text books as a second order RK method.
Generally the value of c2 is fixed such that the values of a21 , W2 , W1 are
integers or some real numbers which easy to remember.
1
Two of such cases, the values of c2 are 2 and 1 respectively.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 12/55
Runge-Kutta Method of Order 2
Let c2 = 1, a21 = 2, W2 = W1 = 12 .
K1 = hf (xi , yi )
K2 = hf (xi + h, yi + K1 )
K1 + K2
yi+1 = yi + for i = 0, 1, 2, . . . .
2
or equivalently
h
yi+1 = yi + f (xi , yi ) + f (xi + h, yi + hf (xi , yi )) for i = 0, 1, 2, . . .
2
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 13/55
Butcher Tableau for Runge-Kutta Method of Order 2
Here are three methods based on convenient choices of c2 . Note that the
first two methods are due to Runge.
0 0 0
1 1 2 2
2 2 1 1 3 3
1 1 1 3
0 1 2 2 4 4
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 14/55
Runge-Kutta Method of Order 3
where
K1 = hf (xi , yi )
h K1
K2 = hf (xi + , yi + )
2 2
K3 = hf (xi + h, yi − K1 + 2K2 )
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 15/55
Butcher Tableau for Runge-Kutta Method of Order 3
0 0 0
1 1 1 1
2 2 1 1 3 3
1 1 1
1 -1 2 2 4 4 1 −1 2
1 2 1 1 1 2 3 1
6 3 6 6 6 3 0 4 4
0 0 0
2 2 2 2 2 2
3 3 3 3 3 3
2 2 2 1 1
3 0 3 3 3 3 0 −1 1
1 3 3 1 3 3 1
4 8 8 4 0 4 0 4 4
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 16/55
Runge-Kutta Method of Order 4
where
K1 = hf (xi , yi )
h K1
K2 = hf (xi + , yi + )
2 2
h K2
K3 = hf (xi + , yi + )
2 2
K4 = hf (xi + h, yi + K3 )
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 17/55
Runge-Kutta Method of Order 4
From these derivatives the final function value yn+1 (shown as a filled dot)
is calculated.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 18/55
Butcher Tableau for Runge-Kutta Method of Order 4
1 1 1 1 1 2 1 1 2 1 1
6 3 3 6 6
0 3 6 12 3 12 6
0 0 0
1 1 2 2
1 1 3 3 3 3
1 3 1 2 −1 1 1 1
2 8 8 3 3
1 3 12 4
1 −2 −1 4 1 1 −1 1 1 − 54 1
4
2
1 1 2 1 1 3 3 1 1 3 3 1
6 12 3 12 8 8 8 8 8 8 8 8
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 19/55
Working Rule
For a given point (x0 , y0 ) in the (unknown) solution curve, we are going to
find the ordinate of given x.
dy 1
= , y (0) = 1.
dx x +y
3 Given y 0 = x 2 − y , y (0) = 1, find y (0.1) using Runge-Kutta method
of fourth order.
4 Using 4th order Runge-Kutta method, find y (0.1), y (0.2) and y (0.3),
given that
dy
= 1 + xy , y (0) = 2.
dx
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 21/55
Exercises
dy y2 − x2
= 2
dx y + x2
with y (0) = 1 at x = 0.2, 0.4.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 22/55
Exercises
11 Given
dy
= 1 + y2
dx
where y (0) = 0, find y (0.2), y (0.4) and y (0.6) by Runge-Kutta fourth
order formula.
12 Taking h = 0.5, solve the initial value problem for x = 0.05 of the
differential equation
dy y
= 3x + , y (0) = 1.
dx 2
I Euler’s method
I Modified Euler’s method
I Runge-Kutta method of order 4.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 24/55
Solving Simultaneous First Order Differential Equations :
Runge-Kutta Methods
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 25/55
Starting at (xi , yi , zi ) and taking the step-sizes for x, y , z to be h, k, `
respectively, we have the following for the Runge-Kutta methods of fourth
order.
K1 = h f (xi , yi , zi ) J1 = h g (xi , yi , zi )
h K1 J1 h K1 J1
K2 = h f (xi + , yi + , zi + ) J2 = h g (xi + , yi + , zi + )
2 2 2 2 2 2
h K2 J2 h K2 J2
K3 = h f (xi + , yi + , zi + ) J3 = h g (xi + , yi + , zi + )
2 2 2 2 2 2
K4 = h f (xi + h, yi + K3 , zi + J3 ) J4 = h g (xi + h, yi + K3 , zi + J3 )
1
yi+1 = yi + K1 + 2K2 + 2K3 + K4 for i = 0, 1, 2, . . . ,
6
and
1
zi+1 = zi + J1 + 2J2 + 2J3 + J4 for i = 0, 1, 2, . . . .
6
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 26/55
Exercises
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 27/55
Solving Second Order Differential Equations by
Runge-Kutta Methods
Let us describe the fourth order Runge-Kutta method for solving the
second order differential equation
d 2y
= y 00 = f (x, y , y 0 ). (3)
dx 2
If we put y 0 = z, then y 00 = z 0 . So the differential equation becomes
z 0 = f (x, y , z).
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 28/55
Exercises
15 Given
d 2y
− y 3 = 0, y (0) = 10, y 0 (0) = 5.
dx 2
Evaluate y (0.1) using Runge-Kutta method.
16 Use the Runge-Kutta method with fourth order accuracy to determine
the approximate value of y at x = 0.1 if y satisfies the differential
equation
d 2y dy
2
− x2 − 2xy = 1, y (0) = 1, y 0 (0) = 0.
dx dx
17 Using Runge-Kutta method, solve
2
d 2y dy
2
=x − y2
dx dx
for x = 0.2 correct to 4 decimal places. Initial conditions are
y (0) = 1, y 0 (0) = 0.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 29/55
Introduction : Predictor-Corrector Methods
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 30/55
Introduction : Predictor-Corrector Methods
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 31/55
Predictor-Corrector Methods
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 32/55
Predictor-Corrector Methods
The value of yi+1 is first estimated by (4) and this value is inserted on the
right side of (5) to get a better approximation for yi+1 .
This process is repeated until two consecutive values of yi+1 are almost
equal.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 33/55
Predictor-Corrector Methods
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 34/55
Milne’s Method
we get
x0 +4h
n(n − 1) 2
Z
y4 = y0 + f0 + n∆f0 + ∆ f0 + · · · dx.
x0 2!
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 35/55
Milne’s Method
Let x = x0 + nh. Therefore
Z 4 n(n − 1) 2
y4 = y0 + h f0 + n∆f0 + ∆ f0 + · · · dn
0 2!
20 2 8
= y0 + h 4f0 + 8∆f0 + ∆ f0 + ∆3 f0 + · · ·
3 3
0 0 20 2 8
= y0 + h 4y0 + 8(E − 1)y0 + (E − 2E + 1)y00 + (E 3 − 3E 2 + 3E − 1)y00
3 3
(neglecting fourth and higher order differences)
20 0 8
= y0 + h 4y00 + 8(y10 − y00 ) + (y2 − 2y10 + y00 ) + (y30 − 3y20 + 3y10 − y00 )
3 3
8 0 4 0 8 0
= y0 + h y − y2 + y3 .
3 1 3 3
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 36/55
Milne’s Method
Thus
4h 0
2y1 − y20 + 2y30 .
y4 = y0 +
3
If x0 , x1 , . . . , x4 are any 5 consecutive values of x, then the above equation
can be written as
4h 0 0
+ 2yn0 .
yn+1,p = yn−3 + 2yn−2 − yn−1
3
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 37/55
Milne’s Method
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 38/55
Milne’s Method
Thus
h 0
y0 + 4y10 + y20 .
y2 = y0 +
3
This is known Milne’s corrector formula where the suffix c stands for
corrector.
0
An improved value of yn+1 is computed and again the corrector formula is
applied until we get yn+1 to the derived accuracy.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 39/55
Adams-Bashforth Method
Consider
dy
= f (x, y ) with y (x0 ) = y0 .
dx
Newton’s backward interpolation formula can be written as
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 40/55
Adams-Bashforth Method
Substituting this
Z x0 +h
y1 = y0 + f (x, y )dx, (7)
x0
we get
Z x0 +h
n(n + 1) 2
y1 = y0 + f0 + n∇f0 + ∇ f0 + · · · dx
x0 2!
Z 1
n(n + 1) 2
= y0 + f0 + n∇f0 + ∇ f0 + · · · dn (putting x = x0 + nh)
0 2!
1 5 2 3
= y0 + h f0 + ∇f0 + ∇ f0 + ∇3 f0 + · · ·
2 12 8
That is,
n(n + 1) 2 n(n + 1)(n + 2) 3
f (x, y ) = f1 + n∇f1 + ∇ f1 + ∇ f1 + · · ·
2! 3!
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 42/55
Adams-Moulton Corrector Formula
Substituting this in (7), we get,
Z x1 n(n + 1) 2
y1 = y0 + f1 + n∇f1 + ∇ f1 + · · · dx
x0 2!
Z 0
n(n + 1) 2
= y0 + h f1 + n∇f1 + ∇ f1 + · · · dn (putting x = x1 + nh)
−1 2!
1 1 2 1 3
= y0 + h f1 − ∇f1 − ∇ f1 + ∇ f1 − · · ·
2 12 24
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 43/55
Adams-Moulton Corrector Formula
The subscript c indicates that the value obtained in the corrected value
and the superscripts p on the right indicates that the predicted value of
yn+1 should be used for computing the value of f (xn−1 , yn−1 ).
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 44/55
Important Note
If these values are not given, we can determine them by using Taylor’s
series, Euler’s or Runge-Kutta methods.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 45/55
Exercises
18 Given
dy 1
= , y (0) = 2.
dx x +y
If y (0.2) = 2.09, y (0.4) = 2.17 and y (0.6) = 2.24, find y (0.8) using
Milne’s method.
19 Using Milne’s predictor-corrector formula, find y (0.4), for the
differential equation
dy
= 1 + xy , y (0) = 2.
dx
20 Given
dy 1
= (1 + x 2 )y 2
dx 2
and y (0) = 1, y (0.1) = 1.6, y (0.2) = 1.12, y (0.3) = 1.21. Evaluate
y (0.4) by Milne’s predictor-corrector method.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 46/55
Exercises
y 0 = y − x 2, y (0) = 1,
y 0 − x 2y = x 2, y (1) = 1.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 47/55
Exercises
y 0 = 1 + xy , y (0) = 2.
y 0 = x − y 2, y (0) = 1.
5xy 0 + y 2 − 2 = 0
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 48/55
Exercises
27 Given
y 0 = x(x 2 + y 2 )e −x , y (0) = 1,
find y at x = 0.1, 0.2, and 0.3 by Taylor’s series method and compute
y (0.4) by Milne’s method.
28 Using Runge-Kutta method of order 4, find y for x = 0.1, 0.2, 0.3
given that
dy
= xy + y 2 , y (0) = 1.
dx
Continue the solution at x = 0.4 using Milne’s method.
29 If
dy
= 2e x y , y (0) = 2,
dx
find y (4) using Adams predictor-corrector formula by calculating
y (1), y (2) and y (3) using Euler’s modified formula.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 49/55
Exercises
30 Given
y 00 + xy 0 + y = 0, y (0) = 1, y 0 (0) = 0
obtain y for x = 0.1, 0.3 by any method. Further, continue the
solution by Milne’s method to calculate y (0.4).
31 Given
dy
= 1 + y2
dx
where y = 0 when x = 0. Find y (0.8) by Adams-Bashforth formula.
Find y (0.2), y (0.4), y (0.6) by fourth order Runge-Kutta-method.
32 Given
dy
= 1 + y2
dx
where y = 0 when x = 0. Find y (0.8) and y (1.0) by Milne’s formula.
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 50/55
Exercises
x y
-0.1 1.0900
0 1.0000
0.1 0.8900
0.2 0.7605
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 51/55
Exercises
x y
0 1
0.05 1.0526
0.1 1.1104
0.15 1.1737
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 52/55
Exercises
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 53/55
Exercises
P. Sam Johnson (NITK) Numerical Solution of Ordinary Differential Equations (Part - 2) May 3, 2020 55/55