Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

The Copperbelt University

School of Mathematics And Natural Sciences

Department of Mathematics

MA411: Numerical Computing and Statistics

LECTURE NOTES
August 7, 2020

Lecturer; Mr. J.Kalunga term two/ three notes

LAGRANGE’S INTERPOLATION FOR UNEQUAL INTERVALS

Let y = f (x) be a function which takes the values y0 , y1 , y2 , · · · , yn when x


assumes the values x0 , x1 , x2 , · · · , xn respectively. If the values of x are at equal
intervals, we use Newton’s forward or backward formula. If the values of x are
not equal intervals, we use the following formula;

1
(x − x1 )(x − x2 )(x − x3 ) · · · (x − xn )
f (x) = y0
(x0 − x1 )(x0 − x2 )(x0 − x3 ) · · · (x0 − xn )
(x − x0 )(x − x2 )(x − x3 ) · · · (x − xn )
+ y1
(x1 − x0 )(x1 − x2 )(x1 − x3 ) · · · (x1 − xn )
(x − x0 )(x − x1 )(x − x3 ) · · · (x − xn )
+ y2 (1)
(x2 − x0 )(x2 − x1 )(x2 − x3 ) · · · (x2 − xn )
..........................................................................
..........................................................................
(x − x0 )(x − x1 )(x − x2 ) · · · (x − xn−1 )
+ yn
(xn − x0 )(xn − x1 )(xn − x2 ) · · · (xn − xn−1 )
This is called the Lagrange’s interpolation formula for unequal intervals.

Example 1
Using Lagrange’s interpolation formula, find the values of y when x = 10, from
the following table:
x 5 6 9 11
y 12 13 14 16

Solution

Here the interval of differencing is not the same as for Newton’s Forward
and Backward Interpolation and so we have;

x0 = 5, x1 = 6, x2 = 9, x3 = 11
y0 = 12, y1 = 13, y2 = 14, y3 = 16

Using the formula in (1) above we obtain

(10 − 6)(10 − 9)(10 − 11) (10 − 5)(10 − 9)(10 − 11)


f (10) = (12) + (13)
(5 − 6)(5 − 9)(5 − 11) (6 − 5)(6 − 9)(6 − 11)
(10 − 5)(10 − 6)(10 − 11) (10 − 5)(10 − 6)(10 − 9)
+ (14) + (16)
(9 − 5)(9 − 6)(9 − 11) (11 − 5)(11 − 6)(11 − 9)
(4)(1)(−1) (5)(1)(−1) (5)(4)(−1) (5)(4)(1)
= (12) + (13) + (14) + (16)
(−1)(−4)(−6) (1)(−3)(−5) (4)(3)(−2) (6)(5)(2)
13 35 16
=2− + +
3 3 3
2
= 14 .
3

2
Example 2
Using Lagrange’s formula, find the form of the function f (x) given that ;

x 0 2 3 6
f (x) 659 705 729 804

Solution

Take x0 = 0, x1 = 2, x2 = 3, x3 = 6
y0 = 659, y1 = 705, y2 = 729, y3 = 804

Using the Lagrange for unequal formula,

(x − x1 )(x − x2 )(x − x3 ) (x − x0 )(x − x2 )(x − x3 )


f (x) =y0 + y1
(x0 − x1 )(x0 − x2 )(x0 − x3 ) (x1 − x0 )(x1 − x2 )(x1 − x3 )
(x − x0 )(x − x1 )(x − x3 ) (x − x0 )(x − x1 )(x − x2 )
+ y2 + y3
(x2 − x0 )(x2 − x1 )(x2 − x3 ) (x3 − x0 )(x3 − x1 )(x3 − x2 )

and so this becomes;

(x − 2)(x − 3)(x − 6) (x − 0)(x − 3)(x − 6)


f (x) = (659) + (705)
(0 − 2)(0 − 3)(0 − 6) (2 − 0)(2 − 3)(2 − 6)
(x − 0)(x − 2)(x − 6) (x − 0)(x − 2)(x − 3)
+ (729) + (804)
(3 − 0)(3 − 2)(3 − 6) (6 − 0)(6 − 2)(6 − 3)
659 3 2 705 3 67
=− (x − 11x + 36x − 36) + (x − 9x2 + 18x) − 81(x3 − 8x2 + 12x) + (x3 − 5x2 + 6x)
36 8 6
1 3 2
= (−x + 29x + 1602x + 47448),
72
on simplification.

Practice Exercise
1. Given the following values:

x 0 2 3 6
f (x) -4 2 14 158

Using Lagrange’s formula for interpolation, find the value of f (4).

2. State the Lagrange’s formula for interpolation. Use this formula to make
y as the function of x, when x = 5, if the following values of x and y are
given:

x 1 2 -4
y 3 -5 4

3
NEWTON’S DIVIDED DIFFERENCE FORMULA
Let f (x0 ), f (x1 ), f (x3 ), · · · , f (xn ) be the values of the function f (x)
corresponding to the argument x0 , x1 , x2 , · · · , xn . The first divided difference
f (x1 ) − f (x0 )
for the arguments x0 , x1 is defined as and is denoted by f (x0 , x1 )
x1 − x0
f (x1 ) − f (x0 )
or ∆f (x0 ) or [x0 , x1 ]. Thus f (x0 , x1 ) = ∆f (x0 ) =
x1 x1 x1 − x0
f (x2 ) − f (x1 )
Similarly, f (x1 , x2 ) = ∆f (x1 ) =
x2 x2 − x1
f (x3 ) − f (x2 )
f (x2 , x3 ) = ∆f (x2 ) = etc.
x3 x3 − x2
The second divided difference for the arguments x0 , x1 , x2 is defined as

f (x1 , x2 ) − f (x0 , x1 )
f (x0 , x1 , x2 ) = ∆2 f (x0 ) = .
x1 ,x2 ,x3 x2 − x0
The third divided difference for the arguments x0 , x1 , x2 , x3 is defined as

f (x1 , x2 , x3 ) − f (x0 , x1 , x2 )
f (x0 , x1 , x2 , x3 ) = ∆3 f (x0 ) =
x1 ,x2 ,x3 x3 − x0
and so on.

Newton’s Divided Difference Formula


Newton’s Divided Difference formula is given by

f (x) = f (x0 ) + (x − x0 )∆f (x0 ) + (x − x0 )(x − x1 ) ∆2 f (x0 )+


x1 x1 ,x2
(2)
.... + (x − x0 )(x − x1 )....(x − xn−1 ) ∆n f (x0 )
x1 ,....,xn

EXAMPLE 1
Using Newton’s divided difference formula, evaluate f (8) and f (15), given by

x 4 5 7 10 11 13
f (x) 48 100 294 900 1210 2028

Solution

x f (x) ∆f (x) ∆2 f (x) ∆3 f (x)


4 48 ∆f (4) = 100−48
5−4 = 52 ∆2 f (4) = 97−52
7−4 ∆3 f (4) = 1
5 5,7 5,7,10
294−100 202−97
5 100 ∆f (5) = 7−5 = 97 ∆2 f (5) =
10−5 = 21 ∆3 f (5) = 1
7 7,10 7,10,11
900−294 2 310−202
7 294 ∆f (7) = 10−7 = 202 ∆ f (7) = 11−7 = 27 ∆3 f (7) = 1
10 10,11 10,11,13
10 900 ∆f (10) = 1210−900
11−10 = 310 ∆2 f (11) = 409−310
13−10 = 33
11 11,13
11 1210 ∆f (11) = 2028−1210
13−11 = 409
13
13 2028

4
Newton’s divided difference formula is ;

f (x) = f (4) + (x − 4)∆f (4) + (x − 4)(x − 5)∆2 f (4) + (x − 4)(x − 5)(x − 7) ∆3 f (4) + ...
5 5,7 5,7,10

And putting x = 8 we obtain f (8) = 448 and putting x = 15 we obtain


f (15) = 3150.

Practice Exercise
1. Use Newton’s Divided Difference Formula to find f (x) given the following
data;

x 0 1 2 4 5 6
f (x) 1 14 15 5 6 19

2. Use Newton’s Divided Difference formula to find f (7) given the following
; f (3) = 24, f (5) = 120, f (8) = 504, f (9) = 720, and f (12) = 1716

3. Given the following data , find g(x) as a polynomial in powers of (x − 5);

x 0 2 3 4 7 9
g(x) 4 26 58 112 466 922

4. Use Newton’s Divided Difference formula to find y when x = 3.5 from the
table below;

x 1 3 5
y 1.5708 1.5719 1.5738

♠ The Next Topic is on Numerical Differentian and Intergration ♠

5
Numerical Differentiation
(i) Forward Differences Newton’s forward interpolation formula is

x(x − 1) 2 x(x − 1)(x − 2) 3


f (a + xh) = f (a) + ∆f (a) + ∆ f (a) + ∆ f (a)+
2! 3!
x(x − 1)(x − 2)(x − 3) 4
∆ f (a) + · · ·
4!
x2 − x 2 x3 − 3x2 + 2x
= f (a) + x∆f (a) + ∆ f (a) + ∆f (a)+
2 6
4 3 2
x − 6x + 11x − 6x 4
∆ f (a) + · · ·
24

Differentiating w.r.t x, we obtain

2x − 1 2 3x2 − 6x + 2 3 x4 − 18x2 + 22x − 6 4


hf 0 (a + xh) = ∆f (a) + ∆ f (a) + ∆ f (a) + ∆ f (a) + · · ·
2 6 24
Differentiating again w.r.t, x we get

2 2 6x − 6 3 12x2 − 36x + 22 4
h2 f 00 (a + xh) = ∆ f (a) + ∆ f (a) + ∆ f (a) + · · ·
2 6 24
Differentiating again w.r.t, x
6 3 24x − 36 4
h3 f 000 (a + xh) = ∆ + ∆ + ···
6 24
Putting x = 0 and simplifying we obtain
1 1 1
hf 0 (a) = ∆f (a) − ∆2 f (a) + ∆3 f (a) − ∆4 f (a) + · · ·
2 3 4
11 4
h2 f 00 (a) = ∆2 f (a) − ∆3 f (a) + ∆ f (a) − · · ·
12
3
h3 f 000 (a) = ∆3 f (a) − f (a) + · · ·
2
Similarly we can find the formula for high order derivatives.

(ii) Backward Differences Newton’s Backward interpolation formula is

x(x − 1) 2 x(x − 1)(x − 2) 3


f (a − xh) = f (a) − x∇f (a) + ∇ f (a) − ∇ f (a)+
2! 3!
x(x − 1)(x − 2)(x − 3) 4
+ ∇ f (a) − · · ·
4!

Differentiating w.r.t, x we obtain

2x − 1 2 x3 − 6x2 + 2 3 x4 − 6x3 + 11x2 − 6x 4


−hf 0 (a − xh) = −∇f (a) + ∇ f (a) − ∇ f (a) + ∇ f (a) + · · ·
2 6 24

6
Figure 1: Differencing table
Differentiating again w.r.t, x , we get

2 2 6x − 6 3 12x2 − 36x + 22 4
h2 f 00 (a − xh) = ∇ f (a) − ∇ f (a) + ∇ f (a) + · · ·
2 6 24
putting x = 0 and simplifying we get;
1 1 1
hf 0 (a) = ∇f (a) + ∇2 f (a) + ∇3 f (a) + ∇f (a) + · · ·
2 3 4
11 4
h2 f 00 (a) = ∇2 f (a) + ∇ f (a) + · · ·
12

Example 1

Find the first, second and third derivatives of the function tabulated below,
at the point x = 1.5.

x 1.5 2.0 2.5 3.0 3.5 4.0


f (x) 3.375 7.0 13.625 24.0 38.875 59.0

Solution

The forward difference table is shown above (Figure 1: Differencing table)

Here a = 1.5, h = 0.5

The first derivative of f (x) at x = a


1 1 1
hf 0 (a) = ∆f (x) = ∆f (x) − ∆2 f (x) + ∆3 f (x) − ∆4 f (x)
2 3 4

1 1
=⇒ (0.5)f 0 (1.5) = 3.625 − (3) + (0.750) = 3.625 − 1.500 + 0.250 = 2.375
2 3
Thus, f 0 (1.5) = 2 × 2.375 = 4.750

The second derivative of f (x) at x = a is given by


11 4
h2 f 00 (a) = ∆2 f (x) − ∆3 f (x) + ∆ f (x)
12

7
Figure 2: forward difference table

=⇒ (0.5)2 f 00 (1.5) = 3 − 0.750 = 2.250


Thus f 00 (1.5) = 4 × 2.250 = 9

The third derivative of f (x) at x = a is given by


3
h3 f 000 (a) = ∆3 f (x) − ∆4 f (x) =⇒ (0.5)3 f 000 (1.5) = 0.750.
2
Thus f 000 (1.5) = 8 × 0.750 = 6.0000

Example 2

A slider in a machine moves along a fixed straight rod. Its distance xcm
along the rod is given below for various of the time t sec. Find the velocity and
acceleration of the slider when t = 0.3sec

t 0.2 0.3 0.4 0.5 0.6


x 32.87 33.64 33.95 33.81 33.24

Solution

Velocity at t = 0.3 is f 0 (0.3) and acceleration at t = 0.3 is f 00 (0.3), where


x = f (t). We use the values of x from t = 0.2 and t = 0.6. The forward
difference table is given (Figure 2 : forward difference table)

Here a = 0.2, h = 0.1 and thus a + th = 0.3 =⇒ t = 1

The newton’s Interpolation formula is

t(t − 1) 2 t(t − 1)(t − 2) 3 t(t − 1)(t − 2)(t − 3) 4


f (a + th) = f (a) + t∆f (a) + ∆ f (a) + ∆ f (a) + ∆ f (a)
2! 3! 4!
t2 − t 2 t3 − 3t2 + 2t 3 t4 − 6t3 + 11t2 − 6t 4
= f (a) + ∆f (a) + ∆ f (a) + ∆ f (a) + ∆ f (a)
2 6 24
Differentiating w.r.t, x, we get

2t − 1 2 3t2 − 6t + 2 3 4t3 − 18t2 + 22t − 6 4


hf 0 (a + th) = ∆f (a) + ∆ f (a) + ∆ f (a) + ∆ f (a)
2 6 24

8
Differentiating again w.r.t, x we obtain

2 2 6t − 6 3 12t2 − 36t + 22 4
hf 00 (a + th) = ∆ f (a) + ∆ f (a) + ∆ f (a)
2 6 24
Substituting the values , we get

1 1 1
(0.1)f 0 (0.3) = 0.77 + (−0.46) − (0.01) + (0.01)
2 6 12
=⇒ f 0 (0.3) = 10[0.77 − 0.23 − 0.0017 + 0.0008] = 10 × 0.5391 = 5.34

Thus velocity when t = 0.3 is 5.34cm/sec. Also


1
(0.1)2 f 00 (0.3) = −0.46 + 0 − (0.01)
12
=⇒ f 00 (0.3) = 100[−0.46 − 0.0008] = −46.08
Thus acceleration when t = 0.3 is −46.08cm/sec2

Practice Questions

(i) A rod is rotating in a plane about one of its end. If the following table
gives the angle θ in radians through which the rod has turned for different
values of time t second. Find its angular velocity and angular acceleration
when t = 0.7seconds. You can either use the forward or Backward inter-
polation for numerical differentiation

t seconds 0.0 0.2 0.4 0.6 0.8 1.0


θ radians 0.0 0.12 0.48 1.10 2.0 3.20

dy
(ii) From the following data below evaluate dx at x = 0.0
x 0.0 0.05 0.10 0.15 0.20 0.25
y 0.000000 0.10017 0.20134 0.30452 0.41075 0.52110

dy d2 y
(iii) From the following table below, calculate and at x = 1.35
dx dx2
x 1.1 1.2 1.3 1.4 1.5 1.6
y -1.62628 0.15584 2.45256 5.39168 9.12500 13.83072

9
Figure 3:
Numerical Integration
Rb
The process of computing the value of a definite integral a y dx from a set
of numerical values of the integrand y is called Numerical Integration. As in nu-
merical differentiation, the function y = f (x) is represented by an interpolating
polynomial of certain degree [nth degree polynomial if there are (n+1) entries]
which is integrated within the desired limits to get an approximate value of the
definite integral. Now we derive a general formula for numerical integration by
using Newton’s forward interpolation formula. See figure 3.
Rb
(i) Newton-Cote’s Quadrature Formula Let I = a y dx where y takes
the values y0 , y1 , y2 , · · · , yn for x = x0 , x1 , · · · , xn . Let the interval of
integration (a, b) be divided into n equal sub-interval, each of width
b−a
h= so that
n
x0 = a, x1 = x0 + h, x2 = x0 + 2h, · · · , xn = x0 + nh = b.
Z x0 +nh
Thus I = f (x) dx. Since any x is given by x0 + rh and dx = hdr.
x0
Therefore
Z n
I=h f (x0 + rh) dr
0
Z nh
r(r − 1) 2 r(r − 1)(r − 2) 3 i
=h y0 + r∆y0 + ∆ y0 + ∆ yo + · · · dr
0 2! 3!
2 3 2 4 in
h r 1 r
 r 1 r
 
= h ry0 + ∆y0 + − ∆2 + − r 3 + r 2 ∆3 y 0 + · · ·
2 2 3 2 6 4 0
h n n(2n − 3) 2 n(n − 2)2 3 i
= nh y0 + ∆y0 + ∆ y0 + ∆ y0 + · · ·
2 12 24
(3)

10
This is a general quadrature formula and is known as Newton’s-Cote’s
quadrature formula. A number of important deductions that is Trape-
zoidal rule, Simpson’s one third and three- eight rules, Weddle’s rules
can be immediately deduced by putting n = 1, 2, 3 and 6 respectively in
formula (3).
(ii) Trapezoidal Rule (n = 1) Putting n = 3 in the formula (3) and taking
the curve through (x0 , y0 ) and (x1 , y1 ) as a polynomial of degree one so
that differences of order higher than one vanish, we get

Z x0 +h  1  hh i h
f (x) dx = h y0 + ∆y0 = 2y0 + (y1 − y0 ) = (y0 + y1 )
x0 2 2 2

Similarly, for the next sub- interval (x0 + h, x0 + 2h), we get


Z x0 +2h
h
f (x) dx = (y1 − y2 )
x0 +h 2
..........................
..........................
Z x0 +nh
h
f (x) dx = (yn−1 + yn )
x0 +(n−1)h 2
Adding the above integrals, we get
Z x0 +nh=b
hh i
f (x) dx = (y0 + yn ) + 2(y1 + y2 + · · · + yn−1 )
x0 =a 2

(iii) Simpson’s one-third rule(n = 2)


Putting n = 3 in the formula (3) and taking the curve through (x0 , y0 ), (x1 , y1 )and
(x2 , y2 ) as a polynomial of degree two so that differences of order higher
than two vanish, we get;
Z x0 +2h h 1 i
f (x) dx = 2h y0 + ∆y0 + ∆2 y0
x0 6
2h h i
= 6y0 + 6(y1 − y0 ) + (y2 − 2y1 + y0 )
6
h
= (y0 + 4y1 + y2 )
3
Similarly
Z x0 +4h
h
f (x) dx = (y2 + 4y3 + y4 )
x0 +2h 3
.....................
......................
Z x0 +nh
h 
f (x) dx = yn−2 + 4yn−1 + y − n
x0 +(n−2)h 3
Adding the above integrals, we get

Z x0 +nh
hh i
f (x)dx = (y0 +yn )+4(y1 +y3 +· · ·+yn−1 )+2(y2 +y4 +· · ·+yn−2 )
x0 3

11
Which is known as Simpson’s one -third rule. While using this formula,
the given interval of integration must be even number of sub- intervals,
since we find the area over two sub-intervals at a time.
(iv) Simpson’s three-eighth rule (n = 3)
Putting n = 3 in formula (3) and taking the curves through (x0 , y0 ), (x1 , y1 ), (x2 , y2 )
and x3 , y3 as a polynomial of degree three so that differences of order
higher than three vanishes, we get

Z x0 +3h  3 3 1 
f (x) dx = 3h y0 ∆y0 + ∆2 y0 + ∆3 y0
x0 2 4 8
3h h i
= 8y0 + 12(y1 − y0 ) + 6(y2 − 2y1 + y0 ) + (y3 − 3y2 + 3y1 − y0 )
8
3h h i
= y0 + 3y1 + 3y2 + y3
8
Similarly,

Z x0 +6h
3h h i
f (x) dx = y3 + 3y4 + 3y5 + y6
x0 +3h 8
................
................
Z x0 +nh
3h h i
f (x) dx = yn−3 + 3yn−2 + 3yn−1 + yn
x0 +(n−3)h 8
Adding the above integrals, we get
Z x0 +nh
3h h i
f (x) dx = (y0 + yn ) + 3(y1 + y2 + y4 + y5 + · · · + yn−2 + yn−1 ) + 2(y3 + y6 + · · · + yn−3 )
x0 8
which is known as Simpson’s three-eight rule. While using this formula,
the given interval of integration must be divided into sub-intervals whose
number n is a multiple of 3.

(v) Weddle’s Rule (n = 6) Try to derive the formula from equation (3) and
you have to end with
Z x0 +nh
3h h
f (x) dx = y0 + 5y1 + y2 + 6y3 + y4 + 5y5 + 2y6 + 5y7 + y8 + 6y9 + y10 + 5y11 + 2y12 + · · ·
x0 8
which is known as Weddle’s rule. Here n must be a multiple of 6.

Z 1
Example 1 Use trapezoidal rule to evaluate x3 dx considering five sub-
0
intervals.

Solution

Dividing the interval (0, 1) into five equal parts, each of width
1−0
h= = 0.2, the value of f (x) = x3 are given below
5

x 0 0.2 0.4 0.6 0.8 1.0


f (x) 0 0.008 0.064 0.216 0.512 1.000

12
By trapezoidal rule, we have
Z 1
hh i
x3 dx = (y0 + y5 ) + 2(y1 + y2 + y3 + y4 )
0 2
0.2 h i
= (0 + 1.000) + 2(0.008 + 0.064 + 0.216 + 0.512)
2
= 0.1 × 2.6
= 0.26

Example 2
Z 1
dx
Evaluate using
0 1 + x2
1 1 3 1
(i) Simpson’s rule taking h = (ii) Simpson’s rule taking h =
3 4 8 6
1
(ii) Weddle’s rule taking h =
6

Solution
1 1 2 3
(i) The value of f (x) = at x = 0, , , , 1 are given below;
1 + x2 4 4 4

1 1 3
x 0 1
4 2 4
f (x) 1 0.9412 0.8000 0.6400 0.5000

1
By Simpson’s rule,
3
Z 1
dx hh i
2
= (y0 + y4 ) + 4(y1 + y3 ) + 2y2
0 1+x 3
1h i
= 1 + 0.5000 + 4(0.9412 + 0.6400) + 2(.8000)
12
= 0.7854

Also Z 1 i1
dx π
2
= tan−1 x = tan−1 1 =
0 1+x 0 4
π
Thus = 0.7854 =⇒ π = 3.1416
4

3h
By Simpson’s ,
8

Z 1
dx 3h h i
= (y0 + y 6 ) + 3(y1 + y 2 + y 4 + yy 5
) + 22y3
0 1 + x2 8
1h i
= (1 + 0.5000) + 3(0.9730 + 0.9000 + 0.6923 + 0.5902) + 2(0.8000)
16
= 0.7854

13
Also Z 1 i1
dx π
2
= tan−1 x = tan−1 1 =
0 1+x 0 4
π
Thus = 0.7854 =⇒ π = 3.1416
4
(iii) By Weddle’s rule,
Z 1
dx 3h h i
2
= y0 + 5y1 + y2 + 6y3 + y4 + 5y5 + y6
0 1+x 10
1h i
= 1 + 5(0.9730) + 0.9000 + 6(0.8000) + 0.6923 + 5(0.5902) + 0.5000
20
= 0.7854

Also Z 1 i1
dx −1 π
= tan x = tan−1 1 =
0 1 + x2 0 4
π
Thus = 0.7854 =⇒ π = 3.1416
4

Practice Questions
(i) The speed, v meters per second, of a car, i seconds after it starts, is shown
in the table below:

t 0 12 24 36 48 60 72 84 96 108 120
v 0 3.60 10.08 18.90 21.60 18.54 10.26 5.40 4.50 5.40 9.00

Using Simpson’s rule, find the distance travelled by the car in 2 minutes.
Z 8
dx
(ii) Use trapezoidal rule to evaluate using four sub-intervals
4 x

(iii) Apply (i) trapezoidal rule (ii) Simpson’s 31 rule, to find an approximate
Z 3
value of x4 dx by taking six equal sub-intervals. Compare it with the
−3
exact value.
(iv) Use Simpson’s rule , taking five ordinates, to find an approximate value
Z 2 r
1
of x− dx to two decimals places.
1 x
Z π2
1
(v) Calculate the value of sin x dx by Simpson’s rule rule, using 11
0 3
ordinates

♠ The Next Topic is on Difference Equations ♠

14
DIFFERENCE EQUATIONS
 
An equation of the form a0 E r +a1 E r−1 +a2 E r−2 +· · ·+ar−1 E +ar yn = f (n)
here a0 , a2 , cdots, ar−1 , ar are constants, is called a linear difference equation
of order r, with constants coefficients. In symbolic form, it is written as

φ(E)yn = f (n) (4)

A function of n which satisfies (4) is called its solution.

SOLUTION OF A DIFFERENCE EQUATION


(i) Let φ(E)yn = f (n) the symbolic form of a difference equation. Note:
If the difference equation involves ∆ instead of E, use ∆ = E − 1. If it
involves yn+r instead of yn , use yn+r = E r yn

(ii) To solve equation (4), we first solve

φ(E) = 0 (5)

which is called auxiliary equation(A.E). A solution of (5) which


involves as many arbitrary constants as the order of (5) is called
complementary function(C.F.)

1
(iii) Particular Integral P.I = f (n) is a particular solution of (4), not
φ(E)
containing any arbitrary constant.
(iv) The complete solution of (4) is given by yn = C.F + P.I
Note If f (n) = 0 complete solution is yn = C.F

RULES FOR FINDING THE COMPLEMENTARY


FUNCTION
Let the roots of the auxiliary equation φ(E) = 0 be E = m1 , m2 , m3 , · · ·
(i) If m1 , m2 , m3 , · · · are real and distinct then,
C.F = c1 (m1 )n + c2 (m2 )n + c3 (m3 )n + · · ·

(ii) If two roots m1 and m2 are real and each equal to m then,

C.F = (c1 + c2 n)mn + c3 (m3 )n + · · ·

(iii) If the roots, m1 , m2 , m3 , · · · are real and equal,each equal to m then,


C.F = (c1 + c2 n + c3 n2 )mn + c4 (m4 )n + · · ·

(iv) If two roots m1 and m2 are conjugate complex numbers, say p α + iβ then
C.F = rn (c1 cos nθ + c2 sin nθ) + c3 (m3 )n + · · · where r = α2 + β 2 and
β
θ = tan−1 .
α

15
Example 1
Solve the following difference equations
(i) (∆2 − 3∆ + 2)yx = 0 (ii) Un+3 − 3Un+2 + 4Un = 0
(iii) ∆3 yn − 5∆yn + 4yn

Solution
(i) Putting ∆ = E − 1, the given equation becomes

[(E − 1)2 − 3(E − 1) + 2]yx = 0


or
(E 2 − 5E + 6)yx = 0
Thus A.E is
E 2 − 5E + 6 = 0
or
(E − 2)(E − 3) = 0
Therefore
E = 2, 3
The complete solution is yx = c1 .2x + c2 .3x

(ii) Since Un+3 = E 3 Un , Un+2 = E 2 Un , the given equation becomes (E 3 −


3E 2 + 4)Un = 0. A.E is given as
E 3 − 3E 2 + 4 = 0
or
(E + 1)(E − 2)2 = 0
Thus we have

E = −1, 2, 2
Thus complete solution is Un = c1 (−1)n + (c2 + c3 .n).2n

(iii) Putting ∆ = E − 1, the given equation becomes


[(E − 1)3 − 5(E − 1) + 4]yn = 0
or
(E 3 − 3E 2 − 2E + 8)yn = 0.
Thus A.E is
E 3 − 3E 2 − 2E + 8 = 0
or
(E − 2)(E 2 − E − 4) = 0.
And so √
1± 17
E = 2,
2
Thus the complete solution is given by
√ !n √ !n
1 + 17 1 − 17
yn = c1 .2n + c2 + c3
2 2

16
Example 2
Solve the following difference equations:

1+ 3
(i) yn+2 − yn+1 + yn = 0 given that y0 = 1 and y1 = .
2
(ii) yn+1 − 2yn cos α + yn−1 = 0

Solution
(i) Since yn+2 = E 2 yn , yn+1 = Eyn , the given equation becomes

(E 2 − E + 1)yn = 0. Thus A.E is E 2 − E + 1 = 0 and so


√ √
1±i 3 1 3
E= = ±i (= α + iβ)
2 2 2
The complete solution is yn = rn (c1 cos nθ + c2 sin nθ) where
p
r= α2 + β 2
√ !2
v
u 1 2
u !
3
= t +
2 2
=1

and
β √ π
θ = tan−1 = tan−1 3 =
α 3
Therefore
nπ nπ
yn = c1 cos + c2 sin
3 3
and putting n = 0, y0 = c1 but y0 = 1(given) and again putting n = 1, we
obtain
π π
y1 = c1 cos + c2 sin
3 3
or √ √
1+ 3 1 3
= + c2
2 2 2
Thus c2 = 1. Hence the particular solution is yn = cos nπ nπ
3 + sin 3 .

(ii) The given equation is yn+1 − 2yn cos α + yn−1 = 0. Since it involves yn−1 ,
we operate both sides with E. Thus

yn+2 − 2yn+1 cos α + yn = 0

or
(E 2 − 2E cos α + 1)yn = 0
A.E is E 2 − 2E cos α + 1 = 0 and solving yields. Therefore

2 cos α ± 4 cos2 α − 4 p
E= = cos α± − sin2 α = cos α±i sin α(= a±ib)
2
Thus the complete solution is yn = c1 cos nθ + c2 sin nθ

17
Rules for finding the particular integral
Let φ(E)yn = f (n), be the given difference equation, then
1
P.I = f (n).
φ(E)
1 n 1 n
(i) Case I. If f (n) = an , then P.I = a = a , provided φ 6= 0(i.e
φ(E) φ(a)
replace E by a ). If φ(a) = 0, then (E-a) must be a factor of φ(E) and we
operate as follows
1
an = nan−1
E−a
1 n(n − 1)an−2
2
an =
(E − a) 2!
1 n n(n − 1)(n − 2)an−3
a =
(E − a)3 3!
and so on.
(ii) Case II. If f (n) = np , then
1 1
P.I = np = np
φ(E) φ(1 + ∆)

[i.e replace E by 1 + ∆, arrange in ascending powers of ∆ after making


first term unity ]. Expand[φ(1 + ∆)]−1 in ascending powers of ∆ up to
the term ∆p by Binomial theorem operate on np (after expressing it in
factorial notation) which each term of the expansion.
(iii) Case III. If f (n) = sin kn or cos kn. Assume that P.I is yn = A cos kn +
B sin kn substitute in the given equation and find A and B by comparing
the coefficients of cos kn and sin kn on both sides.

Second Method

eiθ + e−iθ eiθ − e−iθ


Use cos θ = and sinθ = and use case I.
2 2
(iv) case(iv) If f (n) = an F (n), where F (n) is a polynomial of degree p in n.
1 n 1
Then P.I = a F (n) = an F (n). Now proceed with case II
φ(E) φ(aE)

Example 1
Solve the following difference equations;
(i) Un+2 − 7Un+1 + 10Un = 12e3n + 4n (ii) Yn+2 − 4Yn = 2n
(iii) Yn+2 − 3Yn+1 − 4Yn + 6 = 0

Solution

(i) (E 2 − 7E + 10)Un = 12e3n + 4n . The Auxiliary Equation(A.E) becomes


E 2 − 7E + 10 = 0 0r(E − 2)(E − 5) = 0. Thus E = 2, 5.

18
Thus the complementary Function (C.F) is C.F = c1 .2n + c2 .5n and so the
particular integral is given as
1
P.I = (12e3n + 4n )
E 2 − 7E + 10
1 1
= 12. 2 (e3 )n + 2 (4)n
E − 7E + 10 E − 7E + 10
1 1
= 12. 3 2 3
(e3 )n + 2 4n
(e ) − 7(e ) + 10 (4 ) − 7(4) + 10
12e3n  4n 
= 6 + −
e − 7e3 + 10 2
12e3n 4n
= 6 −
e − 7e3 + 10 2
Therefore the complete solution is
12e3n 4n
Un = c1 .2n + c2 .5n + −
e6 − 7e3 + 10 2
(ii) (E 2 − 4)Yn = 2n . Thus A.E is E 2 − 4 = 0 =⇒ E = −2, 2. Therefore
C.F = c1 (−2)n + c2 2n . Thus
1
P.I = 2n
E2 − 4
1  1 
= 2n
E−2 E+2
1 1 n
= . 2
E−2 2+2
1 1
= 2n
4E−2
= n2n−1

Therefore Yn = C.F + P.I = c1 (−2)n + c2 .2n + 14 n2n−1


(iii) (E 2 − 3E − 4)Yn = −6. Thus A.E is E 2 − 3E − 4 = 0 =⇒ E = 4, −1.
Thus C.F = c1 4n + c1 (−1)n . Hence
1
P.I = (−6)
E 2 − 3E − 4
1
= −6. 2 (1)n
E − 3E − 4
1
= −6( )=1
−6
Therefore the complete solution is given us Yn = c1 4n + c2 (−1)n + 1.

Practice Exercise
Find the complete solution for following differencing equation
(i) (E 2 − 5E + 6)Yx = x + 2x (ii) Un+2 − 4Un = 9n2 (iii) (∆2 + ∆ + 1)y = x2
(iv) Un+2 − 16Un = cos n2 (v) Un+2 − 7Un+1 + 12Un = cos n
(vi) un+2 − 2un+1 + un = n .2n (vii)yn+1 − 3yn = n, given that y0 = 1
2

next topic will be on Numerical Solution of Ordinary Differential


Equations

19
Numerical Solution of Ordinary Differential
Equations
An ordinary differential equation of n th order is of the form
 dy d2 y dn y 
F x, y , 2 , · · · , n = 0
dx dx dx
. The general solution of this equation contains n arbitrary constants or pa-
rameters. Thus the general solution is of the form f (x, y, c1 , c2 , · · · , cn ) = 0.
If particular values are given to the constants c1 , c2 , · · · , cn , then the resulting
solution is called a particular solution. To get a particular solution we must be
given n conditions(e.g the values of y or its derivatives for some specific value of
x) to determine the n constants. If all the n conditions are specified at the same
initial point x0 then the problem is called an initial value problem. When the
conditions are specified at two or more values of x, then the problem is called a
boundary value problem.
Many ordinary differential equations can be solved by analytical methods
discussed earlier giving closed form solutions. i.e expressing y in terms of x.
However, a majority of differential equations appearing in physical problems
cannot be solved analytically. Thus it becomes imperative to discuss their so-
lutions by numerical methods.
In this chapter , we shall discuss some of the methods for obtaining numerical
dy
solution of first order and first degree ordinary differential equation = f (x, y)
dx
subject of the condition y(x0 ) = y0 .

PICARD’S METHOD OF SUCCESSIVE


APPROXIMATIONS
dy
Consider the equation = f (x, y) given y(x0 ) = y0 . It can be written as
dx
dy = f (x, y)dx integrating on between the corresponding limits for x and y, we
get
Z y Z x Z x
dy = f (x, y)dx =⇒ y − y0 = f (x, y)dx
y0 x0 x0
Thus Z x
y = y0 + f (x, y)dx (6)
x0
Equation(6) is known as an integral equation since it contains y under the
integral sign. The integral on the right hand side can be evaluated if we know
y in terms of x. This is not known. what we know is the function of y at x0 .
In the integrand f (x, y) in the R.H.S of (6), we replace y by its initial value y0 .
Thus, we get a first approximation y (1) for y so that
Z x
y (1) = y0 + f (x, y0 )dx (7)
x0

The integrand in (7) is now a function of x alone and can be evaluated in gen-
eral. In the integrand f (x, y) in the R.H.S of (7) we replace y by itsRfirst
x
approximation y (1) . Thus , we get a second approximation y (2) = y0 + x0 f (x, y (1) )dx.

20
Similarly a third approximation is
Z x
y (3) = y0 + f (x, y (2) )dx
x0

and the n th approximation is


Z x
y (n) = y0 + f (x, y (n−1) )dx
x0

Thus we obtain a sequence of approximate solution


y (1) , y (2) , y (3) , · · · y (n) , · · · each giving a better approximation than the
preceding one.

Example 1
Obtain Picard’s second approximate solution of the initial value problem
dy x2
= 2 , y(0) = 0
dx y +1

Solution

x2
Here x0 = 0, y0 = 0, f (x, y) = . Thus
y2
+1
Z x
y = y0 + f (x, y)dx
x0

becomes x
x2
Z
y= dx
0 y2 + 1
putting y = 0 in the integrand in the equation above, we get the first approxi-
mation
Z x
x3
y (1) = x2 dx =
0 3
x3
putting y = y (1) = in the integrand we get the second approximation
3
Z x
x2
y (2) = x6
0 9 +1
Z x33
dt x3
= , where t =
0 t2 + 1 3
Z x33

= (1 + t2 )−1 dt
0
Z x3
3
= (1 − t2 + t4 − · · · )dt
0
3
t3 t5 i x3
= t − + − ···
3 5 0
x3 x9 x15
= − + − ···
3 81 1215
Note: Picard’s method can be used with ease only when it does not pose
any difficulty in performing the necessary integration in the course of obtaining
various approximation.

21
Example 2
dy
Given the differential equation dx = x − y with the condition that y = 1 when
x = 0. Use Picard’s method to obtain y for x = 0.2 correct to five places of
decimal. Check your answer by comparing the result with the exact particular
solution.

Solution

Here x0 = 1, y0 = 1, f (x, y) = x − y. Therefore


Z x
y = y0 + f (x, y) dx
x0

becomes Z x
y =1+ (x − y) dx
0
putting y = y0 = 1 in the integrand, first approximation
Z x
x2
y (1) = 1 + (x − 1) dx = 1 − x +
0 2

x2
putting y = y (1) = 1 − x + in the integrand, second approximation
2
Z x
x2  x3
y (2) =1+ x−1+x− dx = 1 − x + x2 −
0 2 6

putting y = y (2) in the integrand , third approximation


Z x
(3) x3  x3 x4
y =1+ x − 1 + x − x2 + dx = 1 − x + x2 − +
0 6 3 4

putting y = y (3) in the integrand , fourth approximation


Z x
(4) x3 x4  x3 x4 x5
y =1+ x − 1 + x − x2 + − dx = 1 − x + x2 − + −
0 3 24 3 12 120

putting y = y (4) in the integrand , fifth approximation


Z x
x3 x4 x5  x3 x4 x5 x6
y (5) = 1+ x−1+x2 + − + dx = 1−x+x2 − + − +
0 3 12 120 3 12 60 720

When x = 0.2, the various approximation of y are given by y (1) = 0.82,


y (2) = 0.83867, y (3) = 0.83740, y (4) = 0.83746, y (5) = 0.83746. Hence upto five
decimal, the value of y is given by y = 0.83746.
dy dy
Now = x − y or + y = x is a linear differential equation
dx R dx
1 dx
where I.F = e = ex and the solution is
Z
y.ex = xex dx + c = (x − 1)ex + c

Therefore y = x − 1 + ce−x , since y = 1 when x = 0 thus c=2. The particular


solution is y = x − 1 + 2e−x .

When x = 0.2, y = 0.83746 upto five decimal places of decimal. This value
is exactly the same as the value obtained by Picard’s method

22
Practice Exercise
(i) Employ Picard’s method to obtain correct to four places of decimal the
dy
solution of the equation = x2 + y 2 for x = 0.1 given that y = 0 when
dx
x = 0.

(ii) Find the value of y for x = 0.1 by Picard’s method given that

dy y−x
= , y(0) = 1.
dx y+x

dy
(iii) Find an approximate value of y when x = 0.1, if = x − y 2 and y = 1
dx
at x = 0, using Picard’s method.

dy
(iv) Solve numerically = 2x − y, y(0) = 0.9 at x = 0.4 by Picard’s method
dx
with three iterations and compare the result with the exact value.

TAYLOR SERIES METHOD


dy
Consider the equation = f (x, y) given
dx
y(x0 ) = y0 (8)

The Taylor’s expansion of the function y(x) in the neighborhood of (x0 , y0 ) is


given by

(x − x0 )2 00 (x − x0 )3 y 000 (0)
y(x) = y0 + (x − x0 )y 0 (0) + y (0) + + ··· (9)
2! 3!
Where dashes denote differentiation w.r.t. x Differentiating (1) successively
w.r.t. x we get
∂f ∂f dy ∂f ∂f  ∂ ∂ 
y 00 = + = +f = +f f
∂x ∂y dx ∂x ∂y ∂x ∂y

d  d2 y   ∂ ∂  ∂f ∂f 
y 000 = = + f + f
dx dx2 ∂x ∂y ∂x ∂y
∂2f ∂f ∂f ∂2f ∂2f ∂f ∂f 2
2∂ f
= + + f + f + f + f
∂x2 ∂x ∂y ∂x∂y ∂y∂x ∂y ∂y ∂y 2
and so on
putting x = x0 and y = y0 in the expressions for y 0 , y 00 , y 000 , · · · and substi-
tuting them in equation(9), we get a power series for y(x) in powers of (x − x0 ).

23
Example 1

Employ Taylor’s method to obtain approximately value of y at x = 0.2 for


the differential equation
dy
= 2y + 3ex , y(0) = 0
dx
compare the numerical solution obtained with exact solution.

Solution Given the equation y 0 = 2y + 3ex and differentiating with respect


to x, we get y 00 = 2y 0 + 3ex , y 000 = 2y 00 + 3ex , y iv + 2y 000 = 3ex and so on.
At x = 0, y = 0, so we have
y 0 (0) = 2y(0) + 3e0 = 2 × 0 + 3 = 3

y 00 (0) = 2y 0 (0) + 3e0 = 2 × 3 + 3 = 9

y 000 (0) = 2y 00 (0) + 3e0 = 2 × 9 + 3 = 21

y iv (0) = 2y 000 (0) + 3e0 = 2 × 21 + 3 = 43 The Taylor series for y(x) near
x = 0 is given by

x2 00 x3 x4
y(x) = y0 + xy 0 (0) + y (0) + y 000 (0) + y iv (0) + · · ·
2! 3! 4!
9x2 21x3 45x4
= 0 + 3x + + + + ···
2 3×2 4×3×2
9 7 15
= 3x + x2 + x3 + x4 + · · ·
2 2 8
Putting x = 0.2 in the above series, we have
9 7 15
y(0.2) ≈ 3(0.2) + (0.2)2 + (0.2)3 + (0.2)4
2 2 8
≈ 0.8110
dy dy
R
Now dx = 2y + 3ex or dx − 2y = 3ex in a linear differential equation I.F =
−2dx −2x
e =e and the solution is
Z
−2x
y.e = 3ex + e−2x dx = −3e−x + c

∴ y = −3ex + ce2x ∴ The particular solution is y = −3ex + 3e2x when x = 0.2,


y = −3 × 1.2214 + 1.4918 = 0.8112

Practice Questions
dy
(i) Using Taylor series method, compute the solution of = x + y, y(0) = 1
dx
at the point x = 0.2 correct to three decimal places.

(ii) find by Taylor series method the value of y at x = 0.1 and x = 0.2 to five
dy
places of decimals from = x2 y − 1, y(0) = 1
dx

(iii) Solve y 0 = y 2 + x, y(0) = 1 using Taylor series method and compute y(0.1)
and y(0.2)

24
Euler’s Method

Consider the equation


dy
= f (x, y), y(x0 ) = y0 (10)
dx
Let y = g(x) be the solution of equation(10). Let x0 , x1 = (x0 + h)
x2 = (x0 + 2h),... be equidistant value of x.
In a small interval, a curve is nearly a straight line. This is the property
used in Euler’s Method.
The equation of the tangent of P0 (x0 , y0 ) is
 dy 
y − y0 = (x − x0 )
dx P0

or
y = y0 + f (x0 , y0 )(x − x0 ) (11)
h dy i
∴ = f (x, y)
dx
This gives the y− coordinate of any point on the tangent since the curve is
approximately by the tangent in the interval (x0 , x1 ) the value of y on the curve
corresponding to x = x1 is given by the above value of y in (11) approximately.
∴ putting x = x1 = x0 + h in (11) we have y1 = y0 + hf (x0 , y0 ). Thus Q1
is (x1 , y1 ). Similarly approximating the curve in the next interval (x1 , x2 ) by a
dy
line through Q1 (x1 , y1 ) whose slope is = f (x1 , y1 ) we get
dx
y2 = y1 + hf (x1 , y1 )

Repeating this process we have

y3 = y2 + hf (x2 , y2 )

y4 = y3 + hf (x3 , y3 )
In general,
yn+1 = yn + hf (xn , yn )
This is called Euler’s algorithm.

Note 1. In Euler’s method, the curve of actual solution y = g(x) is ap-


proximated by a sequence of short lines. The process is very slow. if h is not
properly chosen, the curve P0 Q1 Q2 ..... of short lines representing numerical
solution deviates significantly from the curve of actual solution. Hence there is
an improvement of the method called Modified Euler’s Method.

Note 2. The practical value of the Euler’s method is limited, but since it is
helpful for understanding the basic idea of the method in this section.

MODIFIED EULER’S METHOD

In each step of this method, we first compute the auxiliary value



yn−1 = yn + hf (xn , yn )

and then the new value


1  ∗

yn+1 = yn + h f (xn , yn ) + f (xn+1 , yn+1 )
2

25
In fact, we approximate the  solution y by the straight line (xn , yn ) with slope
(xn , yn ) interval xn , xx + 12 h and then we continue alone the straight line with
slope f (xn+1 , yn+1 ) until x reaches xn+1 . (in the figure,n=0)...... The modified
method is a predictor-corrector method, because in each step we first predict a
value by (1) and then correct it by (2).
dy
Example 1. Using Euler’s method, solve for y at x = 0.1 from dx = x+y+xy
y(0) = 1 taking step size h = 0.025
dy
Sol.The given differential equations is dx = x + y + xy, y(0) = 1.
Hence
f (x, y = x + y + xy)
The initial condition is xo = 0, yo = 1. Also h = 0.025
Euler’s algorithm is
yn+1 = yn + hf (xn , yn ) (12)
From (12), for n = 0, we have y1 = y0 + 0.025f (x0 , y0 )

= 1 + 0.025f (0, 1) = 1 + 0.025(0 + 1 + 0 × 1) = 1.0518

Next, we have x1 = x0 + h = 0 + 0.025 = 0.025


∴ From (12), for n = 1, we have y2 = y1 + 0.025f (x1 , y1 )

= 1.025 + 0.025f (0.025, 1.025)

= 1.025 + 0.025(0.025 + 1.025 + 0.025 × 1.025) = 1.0518


Next, we have x2 = x1 + h = 0.025 + 0.025 = 0.05
∴ From (12), for n = 2, we have y3 = y2 = 0.025f (x2 , y2 )

= 1.0518 + 0.025f (0.05, 1.0518)

= 1.0518 + 0.025(0.05 + 1.0518 + 0.05 × 1.0518) = 1.0806


Next, we have x3 = x2 + h = 0.05 + 0.025 = 0.075
∴ From (12), for n = 3, we have y4 = y3 + 0.025f (x3 , y3 )

= 1.0806 + 0.025f (0.075, 1.0806) = 1.0806 + 0.025

= (0.075 + 1.0806 + 0.075 × 1.0806) = 1.1115


Next,we have x4 = x3 + h = 0.075 + 0.025 = 0.1 When x = x4 , y = 04
∴ y = 1.1115, when x = 0.1
The computation work can be conveniently carried out in the table form as
follows

26
dy
Example. Given that dx = x + y 2 and y = 1 at x = 0. find an approximate
value of y at x = 0.5by modified Euler’s method.

S0l. Here f (x, y) = x + y 2 , x0 = 0, y0 = 1 Take h=0.1


Euler’s modified formula is
1  ∗

yn+1 = yn + h f (xn , yn ) + f (xn+1 , yn+1 ) (13)
2

Where yn+1 = yn + hf (xn , yn ). From (13), for n = 0, we have
y1∗ = y0 + hf (x0 , y0 )
= 1 + 0.1f (0, 1) = 1 + 0.1(0 + 12 = 1.1)
1
y1 = y0 + × 0.1 f (x0 , y0 ) + f (x1 , y1∗ )
 
2  
= 1 + 0.05 f (0, 1) + f (0.1, 1.1) (∴ x1 = x0 + h = 0.1)
= 1 + 0.05 0 + 12 + 0.1 + (1.1)2 = 1.1155
 

From (13), for n = 1, we have


y2∗ = y1 + hf (x1 , y1 )
= 1.1155 + 0.1f (0.1, 1.1155)
= 1.1155 + 0.1 0.1 + (1.1155)2 = 1.2499
 

1
y2 = y1 + × 0.1 f (x1 , y1 ) + f (x2 , y2∗ )
 
2  
= 1.1155 + 0.05 f (0.1, 1.1155) + f (0.2, 1.2499)
= 1.1155 + 0.05 0.1 + (1.1155)2 + 0.2 + (1.2499)2 = 1.2708
 

From (13), for n = 2, we have


y3∗ = y2 + hf (x2 , y2 ) = 1.2708 + 0.1f (0.2, 1.2708)
= 1.2708 + 0.1 0.2 + (1.2708)2 = 1.4522
 

1
y3 = y2 × 0.1 f (x2 , y2 ) + f (x3 , y32 )
 
2
= 1.2708 + 0.05 0.2 + (1.2708)2 + 0.3 + (1.4522)2 = 1.4819
 

From (13), for n = 3, we have


y4∗ = y3 + hf (x3 , y3 ) = 1.4819 + 0.1f (0.3, 1.4819)
= 1.4819 + 0.1 0.3 + (1.4819)2 = 1.7315
 

1  
y4 = y3 + × 0.1 f (x3 , y3 ) + f (x4 , y4 )
2  
= 1.4819 + 0.05 f (0.3, 1.4819) + f (0.4, 1.7315)
= 1.4819 + 0.05 0.3 + (1.4819)2 + 0.4 + (1.7315)2 = 1.7766
 

From (13), for n = 4, we have


y5∗ = y4 + hf (x4 , y4 ) = 1.7766 + 0.1f (0.4, 1.7766)
= 1.776 + 0.1 0.4 + (1.7766)2 = 2.1322
 

1
y5 = y4 + × 0.1 f (x4 , y4 ) + f (x5 , y5∗ )
 
2  
= 1.7766 + 0.05 f (0.4, 1.7766) + f (0.5, 2.1322)
= 1.7766 + 0.05 0.4 + (1.7766)2 + 0.5 + (2.1322)2 = 2.2067
 

When x = 0.5 = x5 , y = y5
∴ y = 2.2067 when x = 0.5

27
Practice Questions

(1) Using Euler’s method find an approximate value of y corresponding to


dy
x = 1, given that = x + y and y = 1 when x = 0
dx
(2) Apply Euler’s method to solve y 0 = x + y, y(0) = 0, choosing the step
length 0.2
dy √
(3) Given that = 2 + xy and y = 1 when x = 1. Find approximate value
dx
of y at x = 2 in steps of 0.2, using Euler’s method.

RUNGE’S METHOD

Consider the differential equation


dy
= f (x, y), y(x0 ) = y0 (14)
dx
Integrating both sides of (14) from (x0 , y0 ) to (x1 , y1 ), where x1 = x0 + h, we
get
Z y1 Z x0 +h
dy = f (x, y)dx
y0 x0
Z x0 +h
y1 = y0 + f (x, y)dx (15)
x0

To evaluate the integral onR.H.S. we shall use simpson’s one third rule. We
divide the interval x0 , x0 + h in to two equal parts, each of width h2 and find
 dy 
the value of integrand f (x, y) dx at the point x0 , x0 h2 and x0 + h. Let us first
find the values of y these points. At x = x0 , y = y0 .
Let the tangent at A meet the verticals at M and N in Q and R respectively.
Now
dy 
f (x0 , y0 ) = = slope of tangent at A
dx A
= tan θ1 , where θ1 = ∠P AQ and AP ||x − axis

28
h
When x = x0 + 2

y = ym = M Q = M P + P Q
h
= y0 + AP tan θ1 = y0 + f (x0 , y0 )
2

Also
yR = N R = N S + SR
= y0 + AS tan θ1 = y0 + hf (x0 , y0 )

The value of y at x = x0 + h is given by the point T where the line through A


drawn with slop at (x0 + h, y0 ) meet N R.
dy 
= tan θ2 = f (x0 + h, yR ) = f (x0 + h, y0 + hf (x0 , y0 ))
dx T

y1 + N T = N S + ST
= y0 + AS tan θ2 = y0 + hf (x0 + h, y0 + hf (x0 , y0 ))

h
Thus the value of f (x, y) at x0 , x0 + 2 and x0 + h are respectively
f0 = f (x0 , y0 )
h h 
fm = f x0 + , y0 + f0
2 2
f1 = f (x0 + h, y0 + hfk )
where
fk = f (x0 + h, y0 + hf0 )
∴ From (15), we get
h
y1 = y0 + [f0 + 4fm + f1 ] by Simpson0 s one third rule
2
3
h
= y0 + [f0 + 4fm + f1 ]
6
The formula gives sufficiently accurate value of y1 = y(x0 + h).
Hence to solve (14) by Runge’s method compute,
f0 = f (x0 , y0 )
h h 
fm = f x0 + , y0 + f0
2 2
fk = f (x0 + h, y0 + hf0 )
f1 = f (x0 + h, y0 + hfk )

Is succession. Then y1 = y(x0 + h) = y0 + h6 (f0 + 4fm + hfk )


The repeated application of the formula gives the value of y at equi-spaced
points
Example. Using Runge’s method to find an approximate value of y when x =
0.8, gives that
dy √
= x + y, y(0.4) = 0.41
dx

29
Take h = 0.2

sol. Here f (x, y) = x + y,h = 0.2
We first compute y(0.6) and then y(0.4)
For y(0.6), we have x0 = 0.4, y0 = 0.41

√ √
f0 = f (x0 , y0 ) = f (0.4, 0.41) = o.4 + 0.41 = 0.81 = 0.9
h h 
fm = x0 + , y0 + f0
2 2 √

= f (0.4 + 0.1, 0.41 + 0.1 × 0.9) = f (0.5, 0.5) = 0.5 + 0.5 = 1 = 1
fk = f (x0 + h, y0 + hf0 )
= f (0.4 + 0.2, 0.41 + 0.2 ∗ 0.9) = f (0.6, 0.59)
√ √
= 0.6 + 0.59 = 1.19 = 1.0908
f1 = f (x0 + h, y0 + hfk )
= f (0.4 + 0.2, 0.41 + 0.2 × 1.0908) = f (0.6, 0.62816)
√ √
= 0.6 + 0.62816 = 1.22816 = 1.1082


h
y(x0 + h) = y0 + (f0 + 4fm + f1 )
6
0.2
y(0.6) = 0.4 + (0.9 + 4 × 1 + 1.1082) = 0.6102
6

For y(0.8),we have X0 = 0.6, y = 0.6102

f0 = f (x0 , y0 ) = f (0.6, 0.6102)


√ √
= 0.6 + 0.6102 = 1.2102 = 1.1000
h h 
fm = f x0 + , y0 f0
2 2
= f (0.6 + 0.1, 0.6102 + 0.1 × 1.1) = f (0.7, 0.7202)
√ √
= 0.7 + 0.7202 = 1.4202 = 1.1917
fk = f (x0 + h, y0 + hf0 )
= f (0.6 + 0.2, 0.6102 + 0.2 × 1.1) = f (0.8, 0.8302)
√ √
= 0.8 + 0.8302 = 1.6302 = 1.2767
f1 = f (x0 + h, y0 + hfk )
= f (0.6 + 0.2, 0.6102 + 0.2 × 1.2767) = f (0.8, 0.8655)
√ √
= 0.8 + 0.8655 = 1.6655 = 1.2767


h
y(x0 + h) = y0 + (f0 + 4fm + f1 )
6

0.2
y(0.8) = 0.6102 + (1.1 + 4 × 1.1917 + 1.2905) = 0.8487
0.6

PRACTICE QUESTION
1. Apply Runge’s method to find an approximate value of y when x = 0.2,
dy
given that dx = x + y and y = 1 when x = 0.

30
2. Use Runge’s method to solve numerically the differential equation y 0 =
x − y,y(1) = 0.4 for x = 1.6.
3. Apply Runge’s method to find an approximate value of y when x = 0.1
dy
given that dx = 3x + y 2 , y(0)=1

RUNGE-KUTTA METHODS

Runge-kutta methods are more accurate methods of great practical impor-


tance. They do not require the computation of higher order derivative as in
Taylor’s series method, rather they require evaluation of (x, y). They agree
with Taylor’s series upto the terms of hr , where r is different methods and is
known as the order of that Runge-kutta method.
Euler’s method, Modified Euler’s method and Runge’s method are the Runge-
kutta methods of first, second and third order respectively.
The fourth order Runge-kutta method is the most commonly used in practice
and is often referred to as Runge-kutta method only without any reference to
the order.
dy
To solve the differential equation dx = f (x, y),y(x0 ) = y0 .
Runge-kutta method, compute
k1 = hf (x0 , y0 )
1 1 
k2 = hf x0 + h, y0 + k1
2 2
1 1 
k3 = hf x0 + h, y0 k2
2 2
k4 = hf (x0 + h, y0 + k3 )
1
y1 = y(x0 + h) = y0 + (k1 + 2k2 + 2k3 + k4 )
6

Example. Use Runge-kutta method of find y when x = 1.2 in steps of given


dy
that dx = x2 + y 2 and y(1) = 1.5
Sol. Here f (x, y) = x2 + y 2 , h = 0.1
We first compute y(1.1) and then y(1.2)

For y(1.1), we have x0 = 1, y0 = 1.5

k1 = hf (x0 , y0 ) = 0.1f (1, 1.5) = 0.1[12 + (1.5)2 ] = 0.325


1 1 
k2 = hf x0 + h, y0 k1 = 0.1f (1 + 0.05, 1.5 + 0.1625)
2 2
= 0.1f (1.05, 1.6625) = 0.1 (1.05)2 + (1.6625)2 = 0.3866
 

1 1 
k3 = hf x0 + h, y0 + k2 = 0.1f (1.05, 1.5 + 0.1933)
2 2
= 0.1 (1.05)2 + (1.6933)2 = 0.3969
 

k4 = hf (x0 + h, y0 + k3 ) = 0.1f (1 + 0.1, 1.5 + 0.3969)


= 0.1 (1.1)2 + (1.8969)2 = 0.4808
 


1
y1 = y(x0 + h) = y0 + (k1 + k2 + k3 + k4 )
6

31
1
y(1.1) = 1.5 + (0.325 + 0.7732 + 0.7938 + 0.4808) = 1.8954
6

For y1.2), we have x1 = 1.1, y = 1.8954

k1 = hf (x1 , y1 ) = 0.1f (1.1, 1.8954) = 0.1 (1.1)2 + (1.8954)2 = 0.4802


 

1 1 
k2 = hf x1 + h, y1 + k1 = 0.1(1.1 + 0.05, 1.8954 + 0.2401)
2 2
= 0.1 (1.15)2 + (2.1355)2 = 0.5882
 

1 1 
k3 = hf x1 + h, y1 + k2 = 0.1f (1.15, 1.8954 + 0.2941)
2 2
= 0.1 (1.15)2 + (2.1895)2 = 0.6116
 

k4 = hf (x1 + h, y1 k3 ) = 0.1f (1.1 + 0.1, 1.8954 + 0.6116)


= 0.1 (1.2)2 + (2.5070)2 = 0.7725
 


1
y2 = y(x1 + h) = y1 + (k1 + 2k2 + 2k3 + k4 )
6

1
y(1.2) = 1.8954 + (0.4802 + 1.1764 + 1.2232 + 0.7725) = 2.5041
6

PRACTICE QUESTIONS

1. Apply Runge-kutta fourth order method to find an approximate value of


dy
y when x = 0.2 given that = x + y and y = 1 when x = 0
dx
2. Using Runge-kutta method of order four, compute y(0.2) in steps of 0.1,
dy
if = x + y 2 , given that y = 1 when x = 0
dx
dy y−x
3. Using Runge-kutta method,find y(0.2) for the equation = ,
dx y+x
y(0) = 1 take h = 0.2

MILNE’S PREDICTOR-CORRECTOR METHOD


As the name suggests, Predictor-Corrector method is the method in which we
first predict a value of yn+1 by using a certain formula and then correct the
value by using a more accurate formula. Thus an initially crude estimate is
refined.
Consider the differential equation
dy
= f (x, y), y(x0 ) = y0 (16)
dx
We first find the numerical value of
y0 = y(x0 )
y1 = y(x1 ) = y(x0 + h)
y2 = y(x2 ) = y(x0 + 2h)
y3 = y(x3 ) = y(x0 + 3h)

32
dy
and then from 16,we compute y10 = dx

x0 ,y0
= f (x0 , y0 )
y10 = f (x1 , y1 ),y20 = f (x2 , y2 ),y30 = f (x3 , y3 )
For equi-spaced arguments x0 ,x0 + h,x0 + 2h,......., by newton’s forward inter-
polation formula, we know that

r(r − 1) 2 r(r − 1)(r − 2) 3


u = u0 + r∆u0 + ∆ u0 + ∆ u0 + ..... (17)
2! 3!

Where r = x−xh ,i.e x = x0 + rh


0

Replacing u by y, we have
r(r − 1) 2 0 r(−1)(r − 2)
y 0 = y00 + r∆y00 + ∆ y0 + = ∆3 y00 + ....... (18)
2! 3!
Integrating 18 w.r.t.x over the interval 0 to x0 + 4h, we have
x0 +4h x0 +4h
r(r − 1) 2 0 r(r − 1)(r − 2) 3 0
Z Z
y 0 dx =
 0
y0 +r∆y00 + ∆ y0 + ∆ y0 +...]dx
x0 x0 2! 3!
(19)
 x=x0 +4h
Now L.H.S = y x=x0 = y4 − y0
In the R.H.S. since x = x0 + rh ∴ dx = hdr
When x = x0 + 4h, r = 4
∴ from 19,we
R 4have
y4 − y0 = h 0 y00 + r∆y00 + r(r−1) 2 0 r(r−1)(r−2) 3 0
 
2! ∆ y0 + 3! ∆ y0 + .... dr
Considering differences only upto the third order

Z 4 ZZ 44 Z 4
1 1
y4 = y0 + h y00 rdr + ∆2 y00
dr + ∆y00 (r2 − 1)dr + ∆3 y00 (r3 − 3r2 + 2r)dr
 
0 0 2 0 6 0
1 64 1
= y0 + h y0 × 4 + ∆y00 × 8 + ∆2 y00
 0
− 8 + ∆3 y00 (64 + 16)
 
2 3 6
20 8
= y0 + h 4y0 + 8(E − 1)y00 + ∆2 y00 + ∆3 y00
 0 
3 3
20 8
= y0 + h 4y0 + 8(E − 1)y00 + (E − 1)2 y00 + (E − 1)3 y00
 0 
3 3
Using the operator relation ∆ = E − 1

20 8
= y0 + h 4y00 + 8(E − 1)y00 + (E 2 − 2E + 1)y00 + (E 3 − 3E 3 + 3E − 1)y00
 
3 3
20 8
= y0 + h 4y0 + 8(y10 − y00 ) + (y20 − 2y10 + y00 ) + (y30 − 3y20 + 3y10 − y00 )
 
3 3
20 8  0 40 20 8 
+ 8 y10 + − 8 y20 + y30
  
= y0 + h 4 − 8 + − y0 + 8 −
3 3 3 3 3
8 0 4 0 8 0
= y0 + h y1 − y2 + y3
3 3 3

4h
(2y10 − y20 + 2y30 )
y4 + h = y0 + (20)
3
The formula is known as Milne’s predictor formula.
To get Milne’s corrector formula, we integrate (13) w.r.t.x over the interval x0
to x0 + 2h. Thus
x0 +2h x0 +2h
r(r − 1) 2 0 r(r − 1)(r − 2) 3 0
Z Z
y 0 dx =
 0
y0 +r∆y00 +

∆ y0 + ∆ y0 +..... dx
x0 x0 2! 3!
(21)

33
Now  x=x0 +2h
L.H.S = y x=x = y2 − y0
0

In the R.H.S. Since x = x0 + rh ∴ dx = hdr


When x = x0 , r = 0
When x = x0 + 2h, r = 2
∴ from (21), we have
R2
y2 − y0 = h 0 y00 + r∆y00 + r(r−1) 2 0 r(r−1)(r−2) 3 
2! ∆ y0 + 3! ∆ + .... dr
Considering differences only upto the third order

2 2
1 2 0 2 2 1 3 0 4 3
Z Z Z Z
y2 = y0 + h y00 ∆y00 (r − 3r2 + 2r)dr
 
dr + rdr + ∆ y0 (r − r)dr + ∆ y0
0 0 2 0 6 0
 0 0 1 2 0 8  1 3 0 
= y0 + h y0 ∗ 2 + ∆y0 ∗ 2 + ∆ y0 − 2 + ∆ y0 (4 − 8 + 4)
2 3 6
1 2 0 1
= y0 + h 2y0 + 2∆y0 + ∆ y0 = y0 + h 2y0 + 2(E − 1)y00 + (E − 1)2 y00
 0 0
 0 
3 3
 0 0 1 2 2 0

= y0 + h 2y0 + 2(E − 1)y0 + (E − 2E + 1) y0
2
1 0
= y0 + h 2y0 + 2(y1 − y0 ) + (y2 − 2y10 + y00 )
0
 0 0 0

3
1 0 2 1 
= y0 + h 2 − 2 + y0 + 2 − y10 + y20

3 3 3
1 0 4 0 1 0
= y0 + h y0 + y1 + y2
3 3 3
h
y2 = y0 + (y00 + 4y10 + y[0 2]) (22)
3
This formula is known as Milne’s corrector formula.
Expressing the results in general from and replacing y 0 by f (x, y), we have
yn+1 ,p = yn−3 + 4h3 (2fn−2 − fn−1 + 2f n) -Milne’s predictor formula
yn+1 ,c = yn−1 + h3 (fn−1 + 4fn + fn+1 ) -Milne’s corrector formula

Note. In Milne’s method to find y4 we require four prior values y0 , y1 , y2 , y3


of y. if in any question, these values are not given we determine then by using
Taylor series or Runge-kutta method.
dy
Example 1. Given dx = x2 (1 + y) and y(1) = 1, y(1.1) = 1.233, y(1.2) =
1.548, y(1.3) = 1.979, evaluate y(1.4) by Milne’s predictor-corrector method.
Sol.Here
y 0 = f (x, y) = x2 (1 + y)
x0 = 1, x1 = 1.1, x2 = 1.2, x3 = 1.3, x4 = 1.4
h = 0.1
y0 = 1, y1 = 1.233, y2 = 1.548, y3 = 1.979
∴ y10 = f (x1 , y1 ) = (1.1)2 (1 + 1.233) = 2.7019 = f1
y20 = f (x2 , y2 ) = (1.2)2 (1 + 1.548) = 3.6691 = f2
y30 = f (x3 , y3 ) = (1.3)2 (1 + 1.1979) = 5.0345 = f3
4h
Using Milne’s predictor formula, y4 , p = y0 + 3 (sf1 − f2 + 2f3 ) we have
4
y4 , p = 1 + × 0.1(5.4038 − 3.6691 + 10.0690) = 2.5738
3

Now x4 = 1.4, y4 = 2.5738

34

y40 = f (x4 , y4 ) = (1.4)2 (1 + 2.5738) = 7.0046 = f4

Using Milne’s corrector formula


h
y4,c = y2 + (f2 + 4f3 + f4 )
3

we have
0.1
y4,c = 1.548 + (3.6691 + 20.1380 + 7.0046) = 2.5750
3

Hence
y(1.4) = 2.5750

Example 2. Use Milne’s method to find y(.3) from y 0 = x2 + y 2 , y(0) = 1. Find


the initial values y(−1),y(.1) and y(.2) from the Taylor’s series method.
Sol. Given equation is y 0 = x2 + y 2
Differentiating repeatedly w.r.t.x, we get
y” = 2x + 2yy 0 and y”0 = 2 + 2(yy” + y 02 )
At x = 0,y = 1, we have

y 0 (0) = 1, y”(0) = 2 × 0 + 2 × 1 × 1 = 2
y”0 (0) = 2 + 2(1 × 2 + 12 ) = 8

The Taylor series for y(x) near x = 0 is given by

x2 x3 4x3
y(x) = y0 + xy 0 (0) y”(0) + y”0 (0) + ..... = 1 + x + x2 + ...
2! 3! 3


4(−.1)3
y(−.1) = 1 − .1 + (.1)2 + − .... = 0.9087
3
4(1)3
y(.1) = 1 + .1 + (.1)2 + − ..... = 1.1113
3
4(.2)3
y(.2) = 1 + .2 + (.2)2 + − .... = 1.2506
3

Now

x−1 = −.1, x0 = 0, x1 = .1, x2 = .2, x3 = .3, h = 0.1


y−1 = 0.9087, y0 = 1, y1 = 1.1113, y2 = 1.2506
∴ y00 = f (x0 , y0 ) = 02 + 12 = 1 = f0
y10 = f (x1 , y1 ) = (.1)2 + (1.1113)2 = 1.2449 = f1
y20 = f (x2 , y2 ) = (.2)2 + (1.2506)2 = 1.6040 = f2

Using Milne’s predictor formula

4h
y3,p = y−1 + (2f0 − f1 + 2f2 )
3
,

35
we have
4 ∗ 0.1
y3,p = 0.9087 + (2 − 1.2449 + 3.2080) = 1.4371
3
Since x3 = .3,y3 = 1.4371

∴ y3 = f (x3 , y3 ) = (.3)2 + (1.4371)2 = 2.1552 = f3


Using Milne’s corrector formula

h
y3,c = y1 + (f1 + 4f2 + f3 ),
3
we have

0.1
y3,c = 1.1113 + (1.2449 + 6.4160 + 2.1552) = 1.3485
3
Hence
y(0.3) = 1.4385

PRACTICE QUESTIONS
1. Using Milne’s predictor corrector method to obtain the solution of the
dy
equation = x − y 2 at x = 0.8, given that y(0) = 0.0000,y(0.2) =
dx
0.0200,y(0.4) = 0.0795,y(0.6) = 0.1762.
2. Using Milne’s method, obtain the solution of the equation
1
y0 = ,y(0) = 2 at x = 0.8,given that y(0.2) = 2.0933,(0.4) =
x+y
2.1755,(0.6) = 2.2493.
dy
3. Solve by Milne’s predictor-corrector method, the differential equation dx =
2
y − x with the following starting value:
y(0) = 1,y(.2) = 1.12186,y(.4) = 1.4682,y(.6) = 1.7379 and find the value
of y when x = .8

SOLUTION OF SYSTEMS OF LINEAR EQUATIONS

A system of m linear equation in n unknowns x1 , x2 ...., xn is a set of equa-


tions of the form

a11 x1 + a12 x2 + · · · + a1n xn = b1


a21 x1 + a22 x2 + · · · + a2n xn = b2
·································
am1 x1 + am2 x2 + · · · + amn xn = bm
where the coefficient ajk and the bj are given numbers. The system is said
to be homogeneous if all the bj are zero; otherwise it is said to be non-
homogeneous.
The system of linear equations is equivalent to the matrix equation (or the single
vector equation)
Ax = b

36
where the coefficient matrix A = [aij ] is then m ∗ n matrix and x and b
are the column matrices (vectors) given by:
 
a11 a12 · · · a1n
 a21 a22 · · · a2n 
A= .
 
. .. .. 
 . . ··· . 
am1 am2 · · · amn
,
 
x1
 x2 
x= . 
 
 .. 
xn
and  
b1
 b2 
b= . 
 
 .. 
bm
A solution of the system is a set of numbers x1 , x2 , ...., xn which satisfy all
the m equations, and a solution vector of (1)is a column matrix whose com-
ponents constitute a solution of system. The method of solving such a system
using methods like Cramer’s rule is impracticable for large system. Hence, we
use other methods like Gauss elimination.

Gauss Elimination Method


In the Gauss elimination method, the solution of the system of equations is ob-
tained in two stages. In the first stage, the given system of equations is reduced
to an equivalent upper triangular form using elementary transformation.In the
second stage, the upper triangular system is solved using back subtraction pro-
cedure by which we obtain the solution in the order xn , xn−1 , xn−2 , · · · , x2 , x1

Example. Solve the system

2x1 + x2 + 2x3 + x4 = 6 ...(1)


6x1 − 6x2 + 6x3 12x4 = 36 ...(2)
4x1 + 3x2 + 3x3 − 34 = −1 ...(3)
2x1 + 2x2 − x3 + x4 = 10 ...(4)

To eliminate x1 from equation (2), (3) and (4), we subtract suitable multiples of
equation (1) and we get the following system of equations:

(2) − 3.(1) → − 9x2 + 0x3 + 9x4 = 18 ...(5)


(3) − 2.(1) → x2 − x3 − 5x4 = −13 ...(6)
(4) − 1.(1) → x2 − 3x3 + 0x4 = 4 ...(7)

To eliminate x2 from equations (6) and (7), subtract suitable multiples of equa-
tion (5) and get the following system of equations:

 −1 
(6) − (5) → − x3 − 4x4 = −11 ...(8)
9
 −1 
(7) − (5) → − 3x3 + x4 = 6 ...(9)
9

37
To eliminate x2 from equation (9), subtract 3x(8) and get the following
equation:

13x4 = 39 ...(10)

From equation (10),x4 = 39/13 = 3; using this value of x4 ,(9) gives x3 = −1;
using these values of x4 and x3 ,(7) gives x2 = 1; using all these values (1) gives
x1 = 2. Hence the solution to the system is x1 =,x2 = 1,x3 = −1,4 = 3
Note: The above method can be simplified using the matrix notation. The given
system of equations can be written as

Ax = b

and the augmented matrix is


 
2 1 2 1 6
6
 −6 6 12 36 

4 3 3 −3 −1
2 2 −1 1 10
which on successive row transformations give
 
2 1 2 1 6
0 −9 0 9 18 
 
0 0 −1 −4 −11
0 0 0 13 39

Hence
    
2 1 2 1 x1 6
0
 −9 0 9 x2  =  18 
   
0 0 −1 −4 x3  −11
0 0 0 13 x4 39
Back substitution gives

x1 = 2, x2 = 1, x3 = −1, x4 = 3

In the example, we had a11 6= 0. Otherwise we would not have been able to
eliminate x1 by using the equations in the given order. Hence if a11 6= 0 in
the system of equations we ha to reorder the equation (and perhaps even the
unknowns in each equation) in a suitable fashion; similarly, in the further steps.
Such a situation can be seen in the following Example.
Example Using Gauss elimination solve

y + 3z = 9
2x + 2y − z = 8
−x + 5z = 8

Here the leading coefficient (i.e, coefficient of x) is 0. Hence to proceed further


we have to interchange row 1 and 2, so that

2x + 2y − z = 8 ...(1)
y + 3z = 9 ...(2)
−x + 5z = 8 ...(3)

38
Elimination of x from last two equations
2x + 2y − z = 8
y + 3z = 9
1 9
(3) + (1) → y + z = 12 ...(4)
2 2
Elimination of y from last equation
2x + 2y − z = 8
y + 3z = 9
3
(4) − (2) → z=3 ...(5)
2
Hence
z = 2, y = 9 − 6 = 3, x = 2
.
Hence    
x 2
y  = 3
z 2

Partial and Full Pivoting

In each step in the Gauss elimination method, the coefficient of the first
unknown in the first equation is called pivotal coefficient. By the above Ex-
ample, the Gauss elimination method fails if any one of the pivotal coefficient
becomes zero. In such a situation, we rewrite the equations in a different order
to avoid zero pivotal coefficient. Changing the order of equations is called piv-
oting

In partial pivoting, if the pivotal coefficient a11 happens to be zero or


near to zero, the ith column elements are searched for the numerically largest
element. Let the j th row (j > i) contains this element, then we interchange the
ith equation and proceed for elimination. This process is continued whenever
pivotal coefficients become zero during elimination.

In total pivoting, we look for an absolutely largest coefficient in the the


entire system and start the elimination with the corresponding variable, using
this coefficient as the pivotal coefficient (for this we have to interchange row
and column, if necessary); similarly in the further steps. Total pivoting, in fact,
is more complicated than the partial pivoting. Partial pivoting is preferred for
hand calculation.
Example. Solve the system
0.0004x1 + 1.402x2 = 1.406 ...(1)
0.4003x1 − 1.502x2 = 2.501 ...(2)
by Gauss elimination (a) without pivoting (b) with partial pivoting
(a) without pivoting (choosing the first equation as the pivotal equation)
0.0004x1 + 1.402x2 = 1.406 ...(1a)
0.40031
(2) − × (1a) → − 1405x2 = −1404 ...(2a)
0.0001
and so
1404
x1 = = 0.9993
0.0001

39
and hence from (1a)
1 0.005
x1 = (1.406 − 1.402 × 0.9993) = = 12.5
0.0004 0.0004

(b)(with partial pivoting)


Since |a11 | is small and is near to zero as compared with |a21 |, we accept a21 as
the pivotal coefficient (i.e. second equation becomes the pivotal equation). To
start with we rearrange the given system as follows:

0.4003x1 − 1.502x2 = 2.502 ...(3)


0.0004x1 + 1.402x2 = 1.406 ...(4)

Now by Gauss elimination the system becomes,

0.4003x1 − 1.502x2 = 2.502 ...(3a)


.0004
(4) − (3)1.404x2 = 1.404 ...(4a)
.4003
and so
1.404
x2 = =1
1.404

and from (3a)


1
x1 = (2.501 + 1.502 × 1) = 10
0.4003

Example Solve the following system (i) without pivoting (ii) with pivoting

0.0002x + 0.3003y = 0.1002 ...(1)


2.0000x + 3.0000y = 2.0000 ...(2)

(i) without pivoting


0.0002x + 0.3003y = 0.1002

2 0.3003 × 2  0.1002 × 2
(2) − (2) → 3.000 − y = 2.0000 −
.0002 0.0002 0.0002

i.e.,
1498.5y = 499
.
Now by back substitution, the solution of the system is given by y = 0.3330 and
x = 0.5005;

(ii) With pivoting


Since |a11 | is small and is near to zero as compared with |a21 |, we accept a21 as
the pivotal coefficient (i.e. second equation becomes the pivotal equation). To
start with we rearrange the given system as follows:

2.0000x + 3.0000y = 20000 ...(3)


0.0002x + 0.3003y = 0.1002 ...(4)
.0002 3.0000 × 0.0002  2 × 0.0002
(4) − (3) → 0.3003 − y = 0.1002 −
2 2 2

40
which simplifies to

0.3000y = 0.1000

Hence by bank substitution, the solution is


y = 13 and x = 12
Cholesky Method (Modification of the Gauss method)

Cholesky method , which is a modification of the Gauss method, is based


on the result that any positive definite square matrix A can be represented in
the form A = LU , where L and U are the unique lower and upper triangular
matrices. The method is illustrated through the following examples.
Example Using Cholesky’s method, solve the system:

x1 + 2x2 + 3x3 = 14
2x1 + 3x2 + 4x3 = 20
3x1 + 4x2 + x3 = 14

(LU decompositionof thecoef f icientmatrixA)


 
1 2 3
A = 2 3 4 
3 4 1

R2 → R3 + (−2)R1 m21 = −2
R3 → R3 + (−3)R1 m31 = −3
 
1 2 3
0 −1 −2 
0 −2 −8
 
1 2 3
0 −1 −2 
0 0 −4

R3 → R3 + (−2)R2 m32 = −3

We take  
1 2 3
U = 0 −1 −2 
0 0 −4
as the upper triangular matrix
Using the multiplier m21 = −2, m31 = −3, m32 = −2, we get the lower triangu-
lar matrix as follows:
   
1 0 0 1 0 0
L = −m21 1 0  = 2 1 0 
−m31 −m32 1 3 2 1

41
(solutionof thesystem)
The given system of equation can be written as
     
1 0 0 1 2 3 x1 14
2 1 0  0 −1 −2  x2  = 20  ...(1)
3 2 1 0 0 −4 x3 14
The above can be written as
    
1 0 0 y1 14
2 1 0  y2  = 20  ...(2)
3 2 1 y3 14
where
    
1 2 3 x1 y1
0 −1 −2  x2  = y2  ...(3)
0 0 −4 x3 y3
Solving the system in (2) by forward substitution, we get
   
y1 14
y2  =  −8 
y3 −12
With these values of y1 , y2 , y3 , Eq.(3) can now be solved by back substitution
and we obtain    
x1 1
x2  = 2 
x3 3
Example Solve the equations
2x + 3y + z = 9
x + 2y + 3z = 6
3x + y + 2z = 8
by LU decomposition.
(LU decomposition of the coefficient matrix A)
Proceeding as in the above example,
   
2 3 1 1 0 0
U = 0 21 52  and L =  21 1 0 
3
0 0 18 2 −7 1
(solutionof thesystem)
The given system of the equations can be written as
     
1 0 0 2 3 1 x 9
1/2 1 0  0 1/2 5/2  y  = 6  ...(iv)
3/2 −7 1 0 0 18 z 8
or,as
    
1 0 0 y1 9
1/2 1 0  y2  = 6  ...(v)
3/2 −7 1 y3 8

42
where
  
2 3 1 x  
0 1/2 5/2  y  = y1 y2 y3 ...(vi)
0 0 18 z

Solving the system in (v) by forward substitution, we get


3
y1 = 9, y2 = , y3 = 5
2

With these values of y1 , y2 , y3 , eq.(vi) can now be solved by the back substitution
process and we obtain
35 29 5
x= , y= , z=
18 18 18
. Gauss Jordan Method

The method is based on the idea of reducing the given system of equations
Ax = b,to diagonal system of equations Ix = d, where I is the identity ma-
trix, using elementary row operations. We know that the solutions of both the
systems are identical. This reduced system gives the solution vector x. This
reduction is equivalent to finding the solution as x = A−1 b

In this case, a system of 3 equation in 3 unknowns

a11 x1 + a12 x2 + a13 x3 = b1


a21 x2 + a22 x2 + a23 x3 = b2
a31 x2 + a32 x2 + a33 x3 = b3

is written as
    
a11 a12 a13 x1 b1
a21 a22 a23  x2  = b2  − − − −(∗ )
a31 a32 a33 x3 b3

After some linear transformations, we obtain the 3 × 3 system as


    
1 0 0 x1 d1
0 1 0  x2  = d2  − − − −(∗∗ )
0 0 1 x3 d3

To obtain the system as given in (∗∗ ), first we augment the matrices given is (∗ )
as,  
a11 a12 a13 b1
a21 a22 a23 b2 
a31 a32 a33 b3
and after some elementary operations, it is written as,
 
1 0 0 d1
0 1 0 d2  − − − (∗∗∗ ),
0 0 1 d3

this helps us to write the given system as given in (∗∗ ). Then it is easy to get
the solution of the system as x1 = d1 , x2 = d2 and x3 = d3 .

Eliminationprocedure: This first step is same as in Gauss elimination


method, which is, we make the elements below the first pivot in the augmented

43
matrix as zeros, using the elementary row transformations. From the second
step onwards, we make the elements below and above the pivots as zeros using
the elementary row transformations. Lastly, we divide each row by its pivot so
that the final matrix is of the form (∗∗∗ ). Partial pivoting can also be used in the
solution. We may also make the pivots as 1 before performing the elimination.

Problem: Solve the following system of equations

x1 + x2 + x3 = 1
4x1 + 3x2 − x2 = 6
3x1 + 5x2 + 3x3 = 4

using the Gauss-Jordan method without partial pivoting


solution
We have the matrix form as
    
1 1 1 x1 1
4 3 −1  x2  = 6
3 5 3 x3 4

(i) To do the eliminations follow the operations,


R2 = R2 − 4R1, and R3 = R3 − 3R1. This gives,
 
1 1 1 1
0 −1 −5 2 
0 2 0 1
T hen, R1 = R1 + R2 and R3 = R3 + 2R2 gives,
 
1 0 −4 3
0 −1 −5 2 
0 0 −10 5

R1 = R1 − (4/10)R3, R2 = R2 − (5/10)R3 gives,


 
1 0 0 1
0 −1 0 − 21 
0 0 −10 5

Now, making the pivots as 1, R2 = ((−R2) and R3 = (R3/(−10))), we get


 
1 0 0 1
0 1 0 1 
2
0 0 1 − 21

Hence,     
1 0 0 x1 1
0 1 0  x2  =  1 
2
0 0 1 x3 − 12
Therefore, the solution of the system is,
1 1
x1 = 1, x2 = , x3 = −
2 2
.
Note: The Gauss-Jordan method looks very elegant as the solution is obtained
directly. However, it is computationally more expensive than Gauss elimination.
For large n, the total number of divisions and multiplications for Gauss-Jordan
method is almost 1.5 times the total number of divisions and multiplications
required for Gauss elimination. Hence, we do not normally use this method for

44
the solution of the system of equations.

The most important application of this method is to find the inverse of a


non-singular matrix. To obtain inverse of a matrix, we start with the augmented
matrix of A with the identity matrix I of the same order.

We the Gauss-Jordan procedure is completed, we obtain, the matrix A aug-


mented with I, [A|I] in the form [I|A−1 ], since AA−1 = I.

Example Using Gauss Jordan method solve the system of equations:


x + 2y + z = 8 ...(1)
2x + 3y + 4z = 20 ...(2)
4x + 3y + 2z = 16 ...(3)
[Elimination of x f rom Eqs. (2) and (3) using(2a)]
x + 2y + z = 8 ...(1a)
−y + 2z = 4 ...(2a)
−5y − 2z = −16 ...(3a)
[Elimination of y f rom (1a) and (3a), using (2b)]
x + 5z = 16 ...(1b)
−y + 2z = 4 ...(2b)
−12z = −36 ...(3b)
[Elimination of z f rom (1b) and (2b), using (3b)]
x=1 ...(1c)
−y = −2 ...(2c)
−12z = −36 ...(3c)
Hence, x = 1, y = 2, z = 3

Assignment

1. Apply Gauss elimination method to solve the equations:


2x + 3y − z = 5
4x + 4y − 3z = 3
−2x + 3y − z = 1

2. Apply Gauss elimination method to solve the equations:


3x1 + 6x2 + x3 = 16
2x1 + 4x2 + 3x3 = 13
x1 + 3x2 + 2x3 = 9

3. Apply Gauss elimination method to solve the equations:


10x + 2y + z = 9
2x + 20y − 2z = −44
−2x + 3y + 10z = 22

4. Apply Gauss elimination method to solve the equation:


x + y + z = 10
2x + y + 2z = 17
3x + 2y + z = 17

45
5. Solve the system, using Gauss elimination method:

5x1 + x2 + x3 + x4 = 4
x1 + 7x2 + x3 + x4 = 12
x1 + x2 + 6x3 + x4 = −5
x1 + x2 + x3 + 4x4 = −6

6. Apply Gauss elimination method to solve the equation:

x + 4y − z = −5
x + y − 6z = −12
3x + y − z = 4

MATRIX INVERSION USING GAUSS ELIMINATION


We know that X will be the inverse of an n-square non-singular matrix A if

AX = I (23)

where I is the n × n identity matrix.

Every square non-singular matrix will have an inverse . Gauss elimination


and Gauss-Jordan methods are popular among many methods available for find-
ing the inverse of a non-singular matrix.
F or the third order matrices (1) may be written as
    
a11 a12 a13 x11 x12 x13 1 0 0
a21 a22 a23  x21 x22 x23  = 0 1 0 
a31 a32 a33 x31 x32 x33 0 0 1

Clearly the above equation is equivalent to the three equations


    
a11 a12 a13 x11 1
a21 a22 a23  x21  = 0
a31 a32 a33 x31 0
    
a11 a12 a13 x12 0
a21 a22 a23  x22  = 1
a31 a32 a33 x32 0
    
a11 a12 a13 x13 0
a21 a22 a23  x23  = 0
a31 a32 a33 x33 1
We can therefore solve each of these systems using Gaussian elimination method
and the result in each case will be the corresponding column of X = A−1 . We
solve all the three equations simultaneously as illustrated in the following ex-
amples

Example. Using Gaussian elimination, find the inverse of the matrix


 
2 1 1
A = 3 2 3 
1 4 9

46
In this method, we place an identity matrix, whose order is same as that of
A, adjacent to A which we call augmented matrix. Then the inverse of A is
computed in two stages. In the first stage, A is converted into an upper trian-
gular form, using Gaussian elimination method.

We write the augmented system first and then apply low transformations:
 
2 1 1 1 0 0
3 2 3 0 1 0  ...(1)

1 4 9 0 0 1

In order to increase the accuracy of the result, it is essential to employ partial


pivoting. We look for an absolutely largest coefficient in the f irst column and
we use this coefficient as the pivotal coefficient (for this we have to interchange
rows if necessary)

In first column of matrix (1), 4 is the largest element, and hence is the pivotal
element. In order to bring 4 in the first row we interchange the first and second
rows and obtain the augmented matrix in the form
 
4 3 −1 0 1 0
1 1 1 1 0 0  ...(2)

3 5 3 0 0 1

1 24 − 12 0 14 0
 
1 1 1 1 0 0  by R1 → 1 R1
4
3 5 3 0 0 1

1 42 − 41 0 1
 
4 0
0 1 5 1 −1 0 
4 4 4
11 15 0 −3 1
0 4 4 4

by R2 → R2 − R1
by R3 → R3 − 3R1

We now search for an absolutely largest coefficient in the second column


(and not in the first row) and we use this coefficient as the pivotal coefficient.
The pivot element is the max (1/4, 11/4) and is 11/4. Therefore, we interchange
second and third rows of the above.
1 43 − 41 0 1
 
4 0
0 11 15 1 − 3 1 
4 4 4
0 14 5
4
1 −1 0
4

Now, divide R2 by the pivot element a22 = 11/4, and obtain

1 34 − 41 1
 
0 0
4
0 1 15 0 − 3 4 
11 11 11
0 0 10 11
1 −1
4 0

In order to make the entries below 1 in the second column we perform R3 →


R3 − (1/4)R1 in the above matrix and obtain

1 34 − 14 0 1
 
4 0
0 1 15 0 − 3 4 
11 11 11
10 2 1
0 0 11 1 − 11 − 11

47
This is equivalent to the following three matrices

1 34 − 14 0 1 34 − 41 14 3
− 14
     
1 0
4 4
0 1 15 0  ; 0 1 15 − 3  ; 0 1 15 
11 10 11 11 111
0 0 10 11
1 0 0 10 11
− 2
11 0 0 10
11

11

Thus we have
  7 1
− 25
 
x11 x12 x13 5 5
A−1 = x21 x22 x23  = − 32 0 1 
2
11
x31 x32 x33 10 − 15 1
− 10

Matrix Inversion using Gauss-Jordan method


This method is similar to Gaussian elimination method for matrix inversion,
starting with the augmented matrix [AI] and reducing A to the identity matrix
using elementary row transformations. The method is illustrated in the following
example.
Example Find the inverse of the following matrix A by Gauss-Jordan method.
 
1 1 1
A = 4 3 −1
3 5 3

The augmented matrix is given by


 
1 1 1 1 0 0
4 3 −1 0 1 0 

3 5 3 0 0 1
 
1 1 1 1 0 0
0 −1 −5 −4 1 0 

0 2 0 −3 0 1

byR2 → R2 − 4R1
byR3 → R3 − 3R1
 
1 1 1 1 0 7
0 1 5 4 −1 0 
0 2 0 −3 0 1
byR2 → −R2
 
1 0 −4 −3 1 0
0 1 5 4 −1 0
0 0 −10 −11 2 1
by R1 → R1 − R2
by R3 → R3 − 2R2
 
1 0 −4 −3 1 0
0 1 5 4 −1 0 
0 0 1 11/10 −1/5 −1/10

1
byR3 → − R3
10
 
1 0 0 7/5 1/5 −2/5
0 1 0 −3/5 0 1/2 
0 0 1 11/10 −1/5 −1/10

byR1 → R1 + 4R3
byR2 → R2 − 5R1

48
Thus we have
7 1
− 25
 
5 5
− 3 0 1 
2 2
11
10 − 15 1
− 10

. Triangulation Method (LU Decomposition Method):

In linear algebra, LU decomposition (also called LU factorization)


factorizes a matrix as the product of a lower triangular matrix and an upper
triangular matrix

Let A be a non-singular square matrix. LU decomposition is a


decomposition of the form
A = LU
where L is a lower triangular matrix and U is an upper triangular matrix. This
means that L has only zeros above the diagonal and U has only zeros below the
diagonal. For example, for a 3 − by − 3 matrix A, its LU decomposition looks
like this:     
a11 a12 a13 1 0 0 u11 u12 u13
a21 a22 a23  = l21 1 0  0 u22 u23 
a31 a32 a33 l31 l32 1 0 0 u33
Consider a system of linear equations,
a11 x1 + a12 x2 + a13 x3 = b1
a21 x1 + a22 x2 + a23 x3 = b2
a31 x1 + a32 x2 + a33 x3 = b3
This can be written in the form,
Ax = b,
where    
  x1 b1
a11 a12 a13  x2 
 
 b2 
 
A = a21 a22  .  and
a23  , x =  
.
b= 
a31 a32 a33  .  .
xn bn
To solve the system of equations by LU decomposition, first we decompose A
as LU , where,
   
1 0 0 u11 u12 u13
l21 1 0 and U =  0 u22 u23 
l31 l32 1 0 0 u33
This gives,
LU x = b
Let U x = y. This implies, Ly = b.
This is,     
1 0 0 y1 b1
l21 1 0 y2  = b2 
l31 l32 1 y3 b3
Thus,
y1 = b1
l21 y1 + y2 = b2
l31 y1 + l32 y2 + y3 = b3

49
This gives the y values by forward substitution, which means, substitute the
value of y1 given by the first equation in the second and solve y2 , then use these
values of y1 and y2 in the third and solve y3 .
Then the system of equations
    
u11 u12 u13 x1 y1
U x = y; that is  0 u22 u23  x2  = y2 
0 0 u33 x3 y3

gives the required values of x1 , x2 and x3 as the solution of the original system
of linear equations by backward substitution.
 
a11 a12 a13
T o compose a matrix A = a21 a22 a23  , in the f orm
a31 a32 a33
    
a11 a12 a13 1 0 0 u11 u12 u13
a21 a22 a23  = l21 1 0  0 u22 u23  , we proceed as f ollows.
a31 a32 a33 l31 l32 1 0 0 u33
   
1 0 0 u11 u12 u13
On multiplying l21 1 0 and  0 u22 u23  , we get,
l31 l32 1 0 0 u33
 
u11 u12 u13
l21 u11 l21 u12 + u22 l21 u13 + u23 
l31 u11 l31 u12 + l32 u22 l31 u13 + l32 u23 + u33
Equating it with the corresponding terms of A, we get,

u11 = a11 ; U12 = a12 ; u13 = a13


a21 a31
l21 u11 = a21 ⇒ l21 = ; l31 u11 = a31 ⇒ l31 =
u11 u11
l21 u12 + uu22 = a22 ⇒ u22 = a22 − l21 u12 ;
l21 u13 + u23 = a23 ⇒ u23 = a23 − l21 u13 ;
simililarly,
l31 u12 + l32 u22 = a32 , l31 u13 + l32 u23 + u33 = a33 gives l32 and u33

Example: Solve the following system of equations by LU decomposition.

2x + 3y + z = 9
x + 2y + 3z = 6
3x + y + 2z = 8.

Solution :

The above system of equations is written as,


    
2 3 1 x 9
1 2 3 y  = 6
3 1 2 z 8

To compose the matrix  


2 3 1
1 2 3
3 1 2

50
in the form of LU , we equate the corresponding terms of A and LU as
already illustrated, and obtain

u11 = 2; u12 = 3 u13 = 1


a21 1 a31 3
l21 = = ; l31 = =
u11 2 u11 2
1 1
u22 = a22 − l21 u12 = 2 − × 3 = ;
2 2
1 5
u23 = a23 − l21 u13 = 3 − × 1 = ;
2 2
a32 − l31 u12
l32 = and
u22
3 5 3 35 
u32 = u33 = a33 − (l31 u13 + l32 u23 ) = 2 − × 1 + (−7) × =2− − = 18
2 2 2 2
Hence,     
2 3 1 1 0 0 2 3 1
1 2 3 =  21 1 0  0 1
2
5
2

1
3 1 2 2 −7 1 0 0 18
This implies,      
1 0 0 2 3 1 x 9
1 1 0 0 1 5  
y = 6
2 2 2
3
2 −7 1 0 0 18 z 8
Consider    
 x y
1    1

2 3
1 5 y = y2 ,
0 2 2 z y3
Then     
1 0 0 y1 9
1 1 0 y2  = 6 ,
2
3
2 −7 1 y3 8
Solving these, we get,    
y1 9
y2  =  3 
2
y3 5
That is,     
2 3 1 x 9
1 5  
0
2 2 y =  12 
0 0 18 z 5
Now, solving the above expression we obtain the values of x, y and z as a
solution of the given system of equations as,
   35 
x 18
y  =  29 
18
5
z 18

51
Assignment
1. Using Gauss-Jordan method, find the inverse of the following matrices:
   
1 1 3 1 1 2
(i) A =  1 3 −3 (ii) B = 1 2 4
−2 −4 −4 2 4 7

2. Using Gaussian elimination method, find the inverse of the following ma-
trices:    
0 1 2 2 0 1
(i) A = 1 2 3 (ii) B = 3 2 5
3 1 1 1 −1 0

52

You might also like