1. Numerical solution of ordinary and
partial dierential Equations
Module 21: Finite dierence methods - I
Dr.rer.nat. Narni Nageswara Rao
£
August 2011
1 Introduction:
Consider the two point boundary value problem
yHH = f(t; y; yH); t P (a; b) (1)
where a prime denotes dierentiation with respect to t, with one of the fol-
lowing three boundary conditions.
Boundary conditions of
2. rst kind:
y(a) =
1; y(b) =
2 (2)
Boundary conditions of second kind
yH(a) =
1; yH(b) =
2 (3)
Boundary conditions of the thirdking (or mixed kind)
a0y(a) a1yH(a) =
1 b0y(b) + b1yH(b) =
2 (4)
where a0, b0, a1, b1,
1 and
2 are constants such that
a0a1 ! 0; ja0j+ ja1j T= 0
b0b1 ! 0; jb0j+ jb1j T= 0 and ja0j+ jb0j T= 0
£nnrao maths@yahoo.co.in
1
3. 2 Finite dierence methods
These are the explicit or implicit realtions between the derivatives and the
function values at the adjecent nodal points. The nodal points on an interval
[a; b] may be de
4. ned by
tj = a + jh; j = 1; 2; ¡¡¡ ; N
where t0 = a; tN+1 = b h =
b a
(N + 1)
The
5. nite dierence solution of a boundary value problem is obtained by
replacing the dierential equation at each nodal point by a dierence equa-
tion. Incorporating the boundary conditions in the dierence equations, the
resulting algebraic system of equations is solved. This gives the approximate
numerical solution of the boundary value problem.
3 Linear second order dierential equations
We consider the linear second order dierential equation
yHH + p(t)yH + q(t)y = r(t); a t b (5)
subject to the boundary conditions of the
6. rst kind
y(a) =
1; y(b) =
2 (6)
The exact value of y(t) at tj is denoted by Yj and its approximate value by
yj. Using Taylor series, we can have
yH(tj) =
y(tj+1) y(tj 1)
2h
+ y(h2) (7)
yHH(tj) =
y(tj+1) 2y(tj) + y(tj 1)
h2 + y(h2) (8)
Neglecting the y(h2) terms in (7) and (8) and substituting in (5). The
7. nite
dierence approximation of the dierential equation at t = tj is given by
yj+1 2yj + yj 1
h2
+p(tj)
yj+1 yj 1
2h
+q(tj)yj = r(tj); j = 1; 2; ¡¡¡ ; N
(9)
The boundary conditions (6) become
y0 =
1; yN+1 =
2 (10)
2
8. upon multiplication by h2
2 , (9) may be written in the form
Ajyj 1 + Bjyj + Cjyj+1 =
h2
2
r(tj); j = 1; 2; ¡¡¡ ; N (11)
where
Aj = 1
2
1 +
h
2
p(tj)
;
Bj = 1 +
h2
2
q(tj);
Cj = 1
2
1 h
2
p(tj)
The system (11) in matrix notation, after incorporating the boundary con-
ditions, becomes
Ay = b (12)
where
y = [y1; y2; ¡¡¡ ; yN]T
b =
h2
2
r(t1) 1A1r1
h2 ; r(t2); ¡¡¡ ; r(tN 1); r(tN) 2CNr2
h2
T
A =
0
BBBB@
B1 C1 0
A2 B2 C2
¡¡¡ ¡¡¡ ¡¡¡ ¡¡¡ ¡¡¡
AN 1 BN 1 CN 1
0 AN BN
1
CCCCA
The solution of the system of linear equations (12) gives the
9. nite dier-
ence solution of the dierential equation (5) satisfying the boundary condi-
tions (6).
3.1 Derivative boundary conditions
We now consider the boundary conditions of the third type
a0y(a) a1yH(a) =
1
b0y(b) + b1yH(b) =
2 (13)
The dierence approximation of the dierential equation (5) at the internal
nodes, j = 1; 2; ¡¡¡ ; N is given by (11), which has N + 2 unknowns in N
3
11. nd two more equations corresponding to the bound-
ary conditions (13).
Ignoring y(h2) terms in (7), the
12. nite dierence approximations of (13)
are
at t = t0,
a0y0 a1
y1 y 1
2h
=
1
or
y 1 = 2ha0
a1
y0 + y1 +
2h
a1
1 (14)
at t = tN+1,
b0yN+1 + b1
yN+2 yN
2h
=
2
or
yN+2 = yN 2hb0
b1
yN+1 +
2h
b0
2 (15)
where y 1 and yN+2 are the function values at t 1 and tN+2. The nodes t 1
and tN+2 outside the interval [a; b] and are called
13. ctitious nodes.
The values of y 1 and yN+2 may be eliminated by assuming that the
dierence equation (11) holds also for j = 0 and N + 1, i.e, at the boundary
points t0 and tN+1. Substituting the values of y 1 and yN+2 from (14) and
(15) into the equations (11) for j = 0 and j = N + 1, we obtained
(i)
B0 2ha0
a1
A0
y0 + (A0 + C0)y1 =
h2
2
r(t0) 2h
a1
1A0
(ii) (AN+1+CN+1)yN+
BN+1 2hb0
b1
CN+1
yN+1 =
h2
2
r(tN+1) 2h
b1
2CN+1
(16)
The equations (16)(i),(11), j = 1; 2; ¡¡¡ ; N and (16)(ii) form a tridiagonal
system of equations. Since the dierence approximation (11) for the dier-
ential equation (5) and the dierence approximations (16) for the bound-
ary conditions (13) are all of second order, the totality of the equations for
j = 0; 1; 2; ¡¡¡ ; N + 1 is also of second order.
Alternately, we may not use the
14. ctitious points y 1 and yN+1. In this
case, we may use the following approximations.
4
15. (a) (i) For j = 0 :
a0y0 a1
y1 y0
h
=
1
or
[a0h + a1]y0 a1y1 = h
1 (17)
(ii) For j = N + 1 :
b0yN+1 + b1
yN+1 yN
h
=
2
or
[b0h + b1]yN+1 b1yN = h
2 (18)
Since, the approximations (17) and (18) are of
16. rst order, the totality
of the equations (17), (11) and (18) for j = 0; 1; 2; ¡¡¡ ; N + 1, can not
retain the second order. These also form a tridiagonal system of equa-
tions.
(b) (i) For j = 0 :
a0y0 a1
1
2h
( 3y0 + 4y1 y2)
=
1
or
(2ha0 + 3a1)y0 4a1y1 + a1y2 = 2h
1 (19)
(ii) For j = N + 1 :
b0yN+1 + b1
1
2h
(3yN+1 4yN + yN 1)
=
2
or
b1yN 1 4b1yN + (2hb0 + 3b1)yN+1 = 2h
2 (20)
Since the approximations (19) and (20) are of second order, the to-
tality equations (19), (11), (20) for j = 0; 1; 2; ¡¡¡ ; N 1, are also of
second order. If we eliminate y2 from (19) using the
17. rst equation of
the set (11), and eliminate yN 1 from (20) using the last equation of
the set (11), then the resulting equations form a tridiagonal system of
equations.
5
18. 3.2 Solution of Tridiagonal System
The dierence approximations to the linear second order dierential equation
(5) and the boundary conditions (6) or (13) lead to the solution of a system
of algebraic equations in N or N + 2 unknowns whose coecients give rise
to a tridiagonal system. The system can be solved by Gaussian elimination.
3.3 Problems
Example: Solve the boundary value problem
yHH = y + t; y(0) = 0; y(1) = 0
with h = 1
4 by using the second order method.
Solution: Here a = 0, b = 1 h = b a
N+1 A N + 1 = 4 A N = 3
) tj = a + jh j = 0; 1; 2; 3; 4:
) The nodal points are t0 = 0(= a), t1 = 0:25, t2 = 0:5, t3 = 0:75, t4 = 1(= b)
The second order method gives the following system of equations
yj 1 2yj + yj+1
h2 = yj + tj; j = 1; 2; 3:
) yj 1 + 2yj yj+1 = h2(yj + tj) j = 1; 2; 3
For h = 1
4, we get
16yj 1 + 33yj 16yj+1 = tj
we have for j = 1 :
16y0 + 33y1 16y2 = t1 = 0:25
for j = 2 :
16y1 + 33y2 16y3 = 0:50
for j = 3 :
16y2 + 33y3 16y4 = 0:75
Using the boundary conditions y0 = 0, y4 = 0, we get the system of equations
0
@
33 16 0
16 33 16
0 16 33
1
A
0
@
y1
y2
y3
1
A =
0
@
0:25
0:5
0:75
1
A
6
19. which gives
y1 = 0:034885
y2 = 0:056326
y3 = 0:050037
Example: Solve the boundary value problem
yHH = ty
y(0) + yH(0) = 1
y(1) = 1
with h = 1
3 by using the second order method.
Solution: With h = 1
3, a = 0, b = 1
N + 1 =
b a
h
= 3 A N = 2
) The nodal points are t0 = 0, t1 = 1
3, t2 = 2
3, t3 = 1
The second order method gives the following system of equations
yj 1 2yj + yj+1 = h2tjyj; j = 0; 1; 2; 3
we have
for j = 0 : y 1 2y0 + y1 = 0
for j = 1 : y0 2y1 + y2 =
y1
27
for j = 2 : y1 2y2 + y3 =
2
27
y2
Since the method is of second order, we may replace yH(0) in the boundary
condition by the approximation
yH(0) = (y1 y 1)=2h
which is also of second order, thus, the boundary conditions become
y0 +
3
2
(y1 y 1) = 1 and y3 = 1
7
20. eliminating y 1, we get the equations
2y0 + 3y1 = 1
y0
55
27
y1 + y2 = 0
y1
56
27
y2 = 1
Solving the system of equations we get
y(0) % y0 = 0:9879518
y
1
3
% y1 = 0:3253012
y
2
3
% y2 = 0:3253012
8