Satish Shukla 1 of 20
Numerical Analysis
Syllabus. Numerical Solution of ODE & PDE: Eulers Method for Numerical
Solution of ODE; Modified Eulers Method; Runge-Kutta Method (RK2, RK4),
Error estimate; Multi-step Methods: Predictor-Corrector method, Adams-Moulton
Method; Boundary Value Problems and Shooting Method; finite difference meth-
ods, numerical solutions of elliptic, parabolic, and hyperbolic partial differential
equations.
Eulers method by geometric approach. Eulers method is one of the oldest and simplest
method used to solve the problem (1).
Suppose, we have to find the values of solution y at point x0 , x1 , , xn , where the
points are equally spaced, i.e., x1 = x0 + h, x2 = x1 + h, , xn = xn1 + h and h is the
interval. The values of y corresponding to these values are y0 , y1 , . . . , yn .
Suppose, the solution of problem (1) is y = g(x). Then, the slope of tangent at any
dy
point of this curve will be: = f (x, y).
dx
Y
x)
g(
=
y
y1
y10 J
y0 I
X
O x0 x1
Consider the line IJ, where the coordinates of the point J are (x1 , y1 ). Then, the slope
of line IJ will be:
y1 y0 y1 y0 y1 y0
tan = = = approximately.
x1 x 0 h h
y1 y0
Therefore, f (x0 , y0 ) = , i.e.,
h
y1 = y0 + hf (x0 , y1 ).
Dr. Satish Shukla 2 of 20
In general,
yi = yi1 + hf (xi1 , yi1 ), i = 1, 2, . . . , n.
The above formula is called the Eulers formula.
Remark 1. We use the value y1 for y1 in the above formula. It is obvious that, higher
is the difference h = x1 x0 , more is the difference y1 y1 , i.e., for large value of
h, y1 and y1 are quite different and there is a significant error in the approximation
of the value of y1 . Therefore, for batter results, the interval h should be takes as
small as possible.
Eulers method by Taylors series (analytic approach). By Taylors series we know that:
h2 00
y(x + h) = y(x) + hy 0 (x) + y (x) + .
2!
If h is sufficient small we can neglect the terms containing higher powers of h, and so, we
have
y(x + h) = f (x) + hy 0 (x) = f (x) + hf (x, y(x)).
Putting x = xi1 we obtain: y(xi1 + h) = y(xi1 ) + hf (xi1 , y(xi1 )), i.e.
dy
= xy 2 with y(2) = 1.
dx
hh
(0)
i
y1 = y0 + f (x0 , y0 ) + f x1 , y1 .
2
Similarly, y2 , y3 and other ordinates can be obtain.
dy
Example 2. Using Eulers modified method find y at x = 0.5 such that = x + y2,
dx
given y(0) = 1.
dy
Example 3. Solve by Eulers modified method = ln(x + y), given y(1) = 2 for
dx
x = 1.2 and x = 1.4.
Dr. Satish Shukla 4 of 20
Sol. Here f (x, y) = ln(x + y), x0 = 1 and y0 = 2. We have to find y(1.2) and y(1.4).
Suppose h = 0.2 so that x1 = 1.2 and x2 = 1.4. Thus, we have to find y(1.2) = y(x1 ) = y1
and y2 = y(x2 ) = y(1.4) By Eulers formula, we have
(0)
y1 = y0 + hf (x0 , y0 ) = 2 + h ln (x0 + y0 ) = 2 + 0.2 ln (1 + 2) = 2.2197.
By Eulers modified formula we have:
hh
(0)
i 0.2
y1 = y0 + f (x0 , y0 ) + f x1 , y1 =2+ [ln(1 + 2) + ln(1.2 + 2.2197)]
2 2
= 2.2328.
Again, by Eulers formula, we have
(0)
y2 = y1 + hf (x1 , y1 ) = 2.2328 + h ln (x1 + y1 ) = 2.2328 + 0.2 ln (1.2 + 2.2328) = 2.4794.
By Eulers modified formula we have:
hh
(0)
i 0.2
y2 = y1 + f (x1 , y1 ) + f x2 , y2 = 2.2328 + [ln(1.2 + 2.2328) + ln(1.4 + 2.4794)]
2 2
= 2.4917.
Thus, y(1.2) = 2.2328 and y(1.4) = 2.4917.
Therefore
1 1
y = (k1 + 2k2 + 2k3 + k4 ) = (0.1 + 2 0.11525 + 2 0.11686 + 0.1347) = 0.1165.
6 6
Therefore, y(0.1) = y1 = y0 + k = 1 + 0.1165 = 1.1165.
Step II: Now
Therefore
1 1
y = (k1 + 2k2 + 2k3 + k4 ) = (0.13466 + 2 0.15514 + 2 0.15758 + 0.18233) = 0.1571.
6 6
Therefore, y(0.2) = y2 = y1 + k = 1.1165 + 0.1571 = 1.2736.
Example 5. Apply Runge-Kutta fourth order method to find y when x = 0.4, where
dy yx
= , given y(0) = 1.
dx y+x
yx
Sol. Here f (x, y) = , x0 = 0, y0 = 1 and let h = 0.4. Therefore, x1 = x0 + h = 0.4,
y+x
and we have to find y1 = y(0.4). We have
y 0 x0
k1 = hf (x0 , y0 ) = (0.4) = 0.4
y 0 + x0
" #
y0 + k21 x0 + h2
h k1
k2 = hf x0 + , y0 + = (0.4) = 0.28571
2 2 y0 + k21 + x0 + h2
" #
y0 + k22 x0 + h2
h k2
k3 = hf x0 + , y0 + = (0.4) = 0.28085
2 2 y0 + k22 + x0 + h2
y0 + k3 x0 h
k4 = hf (x0 + h, y0 + k3 ) = (0.4) = 0.20962.
y0 + k3 + x0 + h
Therefore
1 1
y = (k1 + 2k2 + 2k3 + k4 ) = (0.4 + 2 0.28571 + 2 0.28085 + 0.20962) = 0.29046.
6 6
Therefore, y(0.4) = y1 = y0 + k = 1 + 0.29046 = 1.29046.
Remark 3. To apply Milnes method, first find the values of y1 , y2 , y3 and y10 , y20 , y30
by any other method (e.g., Taylor series). Now by Predictor formula find y4 and so
y40 , and then apply the corrector formula and find the corrected value of y4 . To find
the y5 , replace the subscript in the predictor and corrector formulae by 1.
dy
Example 7. Using Milnes method to find y(0.3) from = x2 + y 2 ; y(0) = 1. Find
dx
the initial values y(0.1), y(0.1) and y(0.2) from the Taylor series method.
Sol. Here f (x, y) = x2 + y 2 , h = 0.1, and so, x1 = 0.1, x1 = 0, x2 = 0.2, x3 = 0.3 and
y0 = y(x0 ) = 1 (given). We have to find the values of y at point x = 0.6. To find the
values of y1 , y1 and y2 we will use Taylor series:
(x x0 )2 00 (x x0 )3 000 (x x0 )4 iv (x x0 )5 v
y(x) = y0 +(xx0 )y00 + y0 + y0 + y0 + y0 + . (5)
2! 3! 4! 5!
Given that:
dy
y0 = = x2 + y 2 = y00 = x20 + y02 = 1
dx
y 00 = 2x + 2yy 0 = y000 = 2x0 + 2y0 y00 = 2
y 000 = 2 + 2yy 0 + 2(y 0 )2 = y0000 = 2 + 2y0 y00 + 2(y00 )2 = 8.
Exercise (Assignment)
dy
(Q.1) Apply Eulers method and solve for x = 0.6 from = 1 2xy, y(0) = 0, take
dx
h = 0.2.
Ans. y(0.6) = 0.5226.
(Q.2) Apply Eulers modified method to compute y for x = 0.3 correct up to four places
dy
of decimals. Given = x + y, x0 = 0, y0 = 1.
dx
Hint. Take h = 0.3 Ans. y(0.3) = 1.39.
(Q.3) Apply Eulers modified method to compute y for x = 0.1 correct up to four places
dy yx
of decimals. Given = , with y(0) = 1.
dx y+x
Hint. Take h = 0.1
dy
(Q.4) Apply Runge-Kutta method of fourth order to solve 10 = x2 + y 2 , with y(0) = 1
dx
for x = 0.1
dy x2 + y 2
Hint. Re-write the equation like: = = f (x, y) and take h = 0.1 Ans.
dx 10
1.0101345.
(Q.5) Apply Runge-Kutta method to obtain y when x = 1.1 given that y = 1.2 when
dy
x = 1 and = 3x + y 2 .
dx
Hint. Take h = 0.1 Ans. 1.727.
dy
(Q.6) The differential equation = 1 + y 2 satisfies the following set of values of x and
dx
y:
(i, j + 1) (i + 1, j + 1)
(i, j 1) (i, j) (i + 1, j)
(i 1, j 1) (i, j 1)
k
X
O
h
The points of intersection of the small squares are called the mesh points or nodal points
or grid points. Note that, the grid point (i, j) represent the point (xi , yj ) = (ih, jk). Since
h and k are constants, there is no harm in writing u(ih, jk) = u(i, j) = ui,j .
Keeping y constant and treating u(x, y) as a function of x only, by Taylors series we
know that:
u h2 2 u h3 3 u h4 4 u
u(x + h, y) = u(x, y) + h + + + + (7)
x 2! x2 3! x3 4! x4
Replace h by h in the above series we get:
u h2 2 u h3 3 u h4 4 u
u(x h, y) = u(x, y) h + + + (8)
x 2! x2 3! x3 4! x4
Similarly, keeping y constant and treating u(x, y) as a function of x only, by Taylors
series we know that:
u k2 2u k3 3u k4 4u
u(x, y + k) = u(x, y) + k + + + + (9)
y 2! y 2 3! y 3 4! y 4
Replace k by k in the above series we get:
u k2 2u k3 3u k4 4u
u(x, y k) = u(x, y) k + + + (10)
y 2! y 2 3! y 3 4! y 4
If the interval h is sufficient small, then neglecting h2 and other higher powers in (7) we
get:
u u(x + h, y) u(x, y)
=
x h
u ui+1,j ui,j
= = . (11)
x h
Dr. Satish Shukla 10 of 20
u
Equation (11) gives the forward difference approximation for .
x
Similarly, from equation (9) we obtain the the forward difference approximation for
u
given by:
y
u ui,j+1 ui,j
= . (12)
y k
Again, adding (7) and (8) and neglecting h4 and the other higher powers we get:
u
Remark 4. By subtracting (8) from (7), we obtain another approximation for
x
u ui+1,j ui1,j u ui,j+1 ui,j1
given by = . Similarly, = .
x 2h y 2k
Remark 5. In the problems, when we apply these formula then initially we have
to guess some values of u. We choose a formula from these two so that we have to
guess the minimum number of values of u, which gives more preciseness.
u1 u2
2000 500
u3 u4
2000 0
1000 0
500 0
Sol. First we find the value of u1 . Note that, if we apply the standard five point formula,
then we have to guess two values, namely, u2 and u3 . While, if we use the diagonal five
point formula, then we have to guess only one value, namely, u4 . Therefore, we calculate
(0)
the value of u1 by diagonal five point formula. Suppose, the initial guess u4 = 0. Then,
by diagonal five point formula we have
(1) 1
u1 = 1000 + 0 + 2000 + 1000 = 1000.
4
Since u1 and u4 are now known, to find the value of u2 we use standard five point formula:
(1) 1
u2 = 1000 + 500 + 1000 + 0 = 625.
4
Dr. Satish Shukla 12 of 20
u1 u2 u3
1000 1000
u4 u5 u6
2000 2000
u7 u8 u9
1000 1000
0 0
500 1000 500
Sol. In this problem, observe that the given values of u are symmetric about the central
horizontal and vertical lines. Therefore, due to this symmetry we can assume u1 =
u3 + u9 = u7 , u4 = u6 and u2 = u8 . Thus, the grid reduced into the following:
500 1000 500
0 0
u1 u2 u1
1000 1000
u4 u5 u4
2000 2000
u1 u2 u1
1000 1000
0 0
500 1000 500
First we find the value of u5 by standard five point formula. Then, by diagonal five point
formula we have
(1) 1
u5 = 1000 + 1000 + 2000 + 2000 = 1500.
4
Now by diagonal five point formula:
(1) 1 (1)
u1 = 0 + u5 + 1000 + 2000 = 1125.
4
By standard five point formula:
Now, we carry out the successive iterations, using the standard five point formulae:
Putting n = 5 we have:
(6) 1 (5) (5)
u1 = 500 + u4 + 1000 + u2 = 947
4
(6) 1 (5) (6) (6)
u2 = 1000 + u5 + u1 + u1 = 1010
4
(6) 1 (6) (6) (5)
u4 = u1 + u1 + 1000 + u5 = 1260
4
(6) 1 (6) (6) (6) (6)
u5 = u2 + u2 + u4 + u4 = 1135.
4
(8) (9) (8) (9) (8) (9)
Proceeding in similar manner, we get u1 = u1 = 938, u2 = u2 = 1001, u4 = u4 =
(8) (9)
1251 and u5 = u5 = 1126.
Sol. We first draw the square with given sides and u with given values as follows:
Y
0 0 0
0
u1 u2
0 0
(1, 2) (2, 2)
u3 u4
0 (1, 1) (2, 1) 0
X
0 0 0 0
Here h = k = 1 and f (x, y) = 10(x2 + y 2 + 10), therefore, the iteration scheme will be:
ui1,j + ui+1,j + ui,j1 + ui,j+1 4ui,j = h2 f (ih, jk). (19)
Since ui,j = u(i, j) and u1 = u(1, 2), therefore to find the value of u1 we put i = 1, j = 2
in equation (20) we get:
u0,2 + u2,2 + u1,1 + u1,3 4u1,2 = f (1, 2)
= 0 + u2 + u3 + 0 4u1 = 150
1
= u1 = [u2 + u3 + 150].
4
Dr. Satish Shukla 16 of 20
Since ui,j = u(i, j) and u2 = u(2, 2), therefore to find the value of u2 we put i = 2, j = 2
in equation (20) we get:
u1,2 + u3,2 + u2,1 + u2,3 4u2,2 = f (2, 2)
= u1 + 0 + u4 + 0 4u2 = 180
1
= u2 = [u1 + u4 + 180].
4
Since ui,j = u(i, j) and u3 = u(1, 1), therefore to find the value of u3 we put i = 1, j = 1
in equation (20) we get:
u0,1 + u2,1 + u1,0 + u1,2 4u1,1 = f (1, 1)
= 0 + u4 + 0 + u1 4u3 = 120
1
= u3 = [u1 + u4 + 120].
4
Since ui,j = u(i, j) and u4 = u(2, 1), therefore to find the value of u4 we put i = 2, j = 1
in equation (20) we get:
u1,1 + u3,1 + u2,0 + u2,2 4u2,1 = f (2, 1)
= u3 + 0 + 0 + u2 4u4 = 150
1
= u4 = [u2 + u3 + 150].
4
From the above relations we have u1 = u4 , and so, we have to find only u1 , u2 , u3 . Now,
we carry out the successive iterations, using the above formulae:
(n+1) 1 (n) (n)
u1 = u2 + u3 + 150
4
(n+1) 1 (n+1)
u2 = 2u1 + 180
4
(n+1) 1 (n+1)
u3 = 2u1 + 120 .
4
(1) (1)
Suppose, the initial guess u2 = u3 = 0. Putting n = 1 we have:
(2) 1 (1) (1)
u1 = u2 + u3 + 150 = 37.5
4
(2) 1 (2)
u2 = 2u1 + 180 = 63.75
4
(2) 1 (2)
u3 = 2u1 + 120 = 48.75.
4
Putting n = 2 we have:
(3) 1 (2) (2)
u1 = u2 + u3 + 150 = 65.63
4
(3) 1 (3)
u2 = 2u1 + 180 = 77.82
4
(3) 1 (3)
u3 = 2u1 + 120 = 62.82.
4
Putting n = 3 we have:
(4) 1 (3) (3)
u1 = u2 + u3 + 150 = 74.66
4
(4) 1 (4)
u2 = 2u1 + 180 = 81.33
4
(4) 1 (4)
u3 = 2u1 + 120 = 66.33.
4
Dr. Satish Shukla 17 of 20
Putting n = 4 we have:
(5) 1 (4) (4)
u1 = u2 + u3 + 150 = 74.42
4
(5) 1 (5)
u2 = 2u1 + 180 = 82.21
4
(5) 1 (5)
u3 = 2u1 + 120 = 67.21.
4
Putting n = 5 we have:
(6) 1 (5) (5)
u1 = u2 + u3 + 150 = 74.86
4
(6) 1 (6)
u2 = 2u1 + 180 = 82.43
4
(6) 1 (6)
u3 = 2u1 + 120 = 67.43.
4
Putting n = 6 we have:
(7) 1 (6) (6)
u1 = u2 + u3 + 150 = 74.97
4
(7) 1 (7)
u2 = 2u1 + 180 = 82.48
4
(7) 1 (7)
u3 = 2u1 + 120 = 67.49.
4
Therefore, u1 = u4 75, u2 82.5 and u3 67.5.
Solution of one dimensional heat equation (Difference scheme for heat diffusion
equation with rectangular meshes)
With the above formula we can find the various values of u given with some boundary
conditions.
A particular case: If h and k are chosen such that c2 k = h2 for some value of c, then we
kc2 1
have = 2 = . Therefore, the above formula reduced to:
h 2
1
ui,j+1 = (ui+1,j + ui1,j ) .
2
With the above formula we can find the various values of u given with some boundary
conditions.
k 1
A particular case: If h and k are chosen so that = = , then the above equation
h c
reduces into the following form:
Example 11. Evaluate the pivotal values of the equation utt = 16uxx taking h = 1
up to t = 1.25. The boundary conditions are u(0, t) = u(5, t) = 0, ut (x, 0) = 0 and
u(x, 0) = x2 (5 x).
Exercise (Assignment)
2u 2u
(Q.1) Solve the elliptic equation 2 + 2 = 0 for the square mesh with boundary values
x y
as shown in the figure:
60 60 60
60
u1 u2
40 50
u3 u4
20 40
0 10 20 30
0 0 1
u1 u2 u3
0 2
u4 u5 u6
0 A B 2
u7 u8 u9
0 2
0 0 1