OTUnit 2
OTUnit 2
Computing -I
UNIT 3 SOLUTION OF LINEAR
ALGEBRAIC EQUATIONS
Structure Page Nos.
3.0 Introduction 40
3.1 Objectives 41
3.2 Gauss Elimination Method 41
3.3 Pitfalls of Gauss Elimination Method 45
3.4 Gauss Elimination Method with Partial Pivoting 46
3.5 LU Decomposition Method 46
3.6 Iterative Methods 49
3.7 Summary 55
3.8 Exercises 55
3.9 Solutions to Exercises 56
3.0 INTRODUCTION
Systems of linear equations arise in many areas of study, both directly in modelling
physical situations and indirectly in the numerical solution of other mathematical
models. Linear algebraic equations occur in the linear optimization theory, least
square fitting of data, numerical solution of ordinary and partial differential equations,
statistical interference etc. Therefore, finding the numerical solution of a system of
linear equations is an important area of study.
From study of algebra, you must be familiar with the following two common methods
of solving a system of linear equations :
When smaller number of equations are involved, Cramer’s rule appears to be better
than elimination method. However, Cramer’s rule is completely impractical when a
large number of equations are to be solved because here n+1 determinants are to be
computed for n unknowns.
Numerical methods for solving linear algebraic systems can be divided into two
methods, direct and iterative. Direct methods are those which, in the absense of
round-off or other errors, yield exact solution in a finite number of arithmetic
operations. Iterative methods, on the other hand, start with an initial guess and by
applying a suitable procedure, give successively better approximations.
In this unit, we shall discuss two direct methods, namely, Gauss elimination method
and LU decomposition method, and two iterative methods, viz.; Jacobi method,
Gauss – Seidel method and Successive over relaxation method.These methods are
frequently used to solve systems of linear equations.
40
Solution of
Linear Algebraic
3.1 OBJECTIVES Equations
• state the difference between direct and iterative methods for solving a system of
linear equations;
• learn how to solve a system of linear equations by Gauss elimination method;
• understand the effect of round off errors on the solution obtained by Gauss
elimination method;
• learn how to modify Gauss elimination method to Gaussian elimination with
partial pivoting to avoid pitfalls of the former method;
• learn LU decomposition method to solve a system of linear equations;
• learn how to find inverse of a square matrix numerically;
• learn how to obtain the solution of a sytem of linear equations by using an
iterative method, and
• state whether an iterative method will converge or not.
One of the most popular techniques for solving simultaneous linear equations is the
Gaussian elimination method. Karl Friedrich Gauss, a great 19th century
mathematician, suggested this elimination method as a part of his proof of a particular
theorem. Computational scientists use this “proof” as a direct computational method.
The approach is designed to solve a general set of n equations and n unknowns
1) Forward Elimination: In this step, the elementary row operations are applied on
the augmented matrix [A|b] to transform the coefficient matrix A into upper
triangular form.
2) Back Substitution: In this step, starting from the last equation, each of the
unknowns is found by back substitution.
a21 a a
a21x1 + a12 x2 + ... + 21 a1n xn = 21 b1
a11 a11 a11
a a a
a22 − 21 a12 x2 + ... + a2 n − 21 a1n xn = b2 − 21 b1
a11 a11 a11
'
or a 22 x 2 + ... + a 2' n x n = b2
' a 21
where a 22 = a 22 − a12 ,…,
a11
a 21 a
a 2' n = a 2 n − a1n , b2' = b2 − 21 b1 .
a11 a11
This procedure of eliminating x1 , is now repeated for the third equation to the
nth equation to reduce the set of equations as
This completes the first step of forward elimination. Now, for the second step of
forward elimination, we start with the second equation as the pivot equation and a ' 22
as the pivot element. So, to eliminate x2 in the third equation, one divides the second
a'
equation by a ' 22 (the pivot element) and then multiply it by 32 . That is, same as
a' / a'
multiplying the second equation by 32 22 and subtracting from the third equation.
This makes the coefficient of x2 zero in the third equation. The same procedure is
now repeated for the fourth equation till the nth equation to give
The next steps of forward elimination are done by using the third equation as a pivot
equation and so on. That is, there will be a total of (n–1) steps of forward elimination.
At the end of (n–1) steps of forward elimination, we get the set of equations
Back Substitution: Now, the equations are solved starting from the last equation as it
has only one unknown. We obtain
bn( n −1)
xn = ( n −1)
a nn
1
x n −1 = ( n − 2)
[b( n −2)
n −1 − a n( n−−1,2n) x n ]
a n −1, n − 2
since x n is determined.
bn( n −1)
xn = ( n −1)
a nn
n
bi(i −1) − ∑ aij(i −1) x j
j =i +1
xi =
and aii(i −1) , for i = n – 1, n – 2,…, 1 (5)
Subtracting 4 times the first row from the second row gives
1 1 1 3
0 − 1 0 − 4
9 3 4 7
Subtracting 9 times the first row from the third row, we get
1 1 1 3
0 − 1 0 − 4
0 − 6 − 5 − 20
43
Numerical
Computing -I Subtracting 6 times the second row from the third row gives
1 1 1 3
0 − 1 0 − 4
0 0 − 5 4
−4
Solving the last equation, we get x 3 = . Solving the second equation, we get
5
4 −1
x 2 = 4 and the first equation gives x1 = 3 – x 2 – x 3 = 3 – 4 + = .
5 5
10 − 7 0 x1 7
− 3 2.099 6 x = 3.901
2
5 − 1 5 x3 6
Multiply the first row by 3/10 and add to the second equation, we get
10 −7 0 x1 7
0 − 0.001 6 x = 6.001
2
5 −1 5 x3 6
Multiply the first row by 5/10 and subtract from the third equation, we get
10 −7 0 x1 7
0 − 0.001 6 x = 6.001
2
0 2.5 5 x3 2.5
Multiply the second equation by 2.5/(–0.005)= –2500 and subtract from the third
equation, we obtain
10 −7 0 x1 7
0 − 0.001 6 x = 6.001
2
0 0 15005 x3 15005
We can now solve the above equations by back substitution. From the third equation,
we get
44
Solution of
15005x3 = 15005 , or x 3 = 1. Linear Algebraic
Equations
10 x1 − 7 x 2 = 7 , or 10 x1 = 7 + 7 x 2 = 0 , or x1 = 0 .
Division by zero: It is possible that division by zero may occur during forward
elimination steps. For example, for the set of equations
10 x 2 − 7 x3 = 7
6 x1 + 2.099 x 2 − 3 x3 = 3.901
5 x1 − x 2 + 5 x3 = 6
during the first forward elimination step, the coefficient of x1 is zero and hence
normalisation would require division by zero.
Round-off error: Gauss elimination method is prone to round-off errors. This is true,
when there are large numbers of equations as errors propagate. Also, if there is
subtraction of almost equal numbers, it may create large errors. We illustrate through
the following examples.
x + 10 5 y = 10 5
( 1 − 10 5 ) y = 2.0 − 10 5.
Substituting in the first equation, we get x = 0.0, which is not the solution.
Such errors can also arise when we perform computations with less number of digits.
To avoid these computational disasters, we apply partial pivoting to gauss elimination.
45
Numerical
Computing -I
3.4 GAUSS ELIMINATION METHOD WITH
PARTIAL PIVOTING
That is, maximum in magnitude of this elements on or below the diagonal element.
a
Then, if the maximum of these values is pk in the pth row, k ≤ p ≤ n, then
interchange rows p and k.. The other steps of forward elimination are the same as in
Gauss elimination method. The back substitution steps remain exactly the same as in
Gauss elimination method.
Since, a11 < a 21, we interchange the first and second rows (equations).
x + y = 2.0
10 −5 x + y = 1.0
The Gauss elimination method has the disadvantage that the right-hand sides are
modified (repeatedly) during the steps of elimination). The LU decomposition method
has the property that the matrix modification (or decomposition) step can be
performed independent of the right hand side vector. This feature is quite useful in
practice. Therefore, the LU decomposition method is usually chosen for computations.
In this method, the coefficient matrix into a product of two matrices is written as
A=LU (7)
The rationale behind this approach is that the two systems given in (9) are both easy to
solve. Since, L is a lower triangular matrix, the equations, Ly = b , can be solved for
y using the forward substitution step. Since U is an upper triangular matrix, U x = y
can be solved for x using the back substitution algorithm.
46
Solution of
We define writing A as LU as the Decomposition Step. We discuss the following Linear Algebraic
three approaches of Decomposition using 4 × 4 matrices. Equations
Doolittle Decomposition
Because of the specific structure of the matrices, we can derive a systematic set of
formulae for the components of L and U .
Crout Decomposition:
Cholesky Factorization:
If A is a symmetric and positive definite matrix, then we can write the decomposition
as
l11 0 0 0
l l 0 0
L = 21 22 (12)
l31 l32 l33 0
l41 l42 l43 l44
We now describe the rationale behind the choice of lii = 1 in (10) or u ii = 1 in (11).
Consider the decomposition of a 3 × 3 matrix as follows.
Now , let us give the solution for the Doolittle and Crout decomposition.
Example 5: Given the following system of linear equations, determine the value of
each of the variables using the LU decomposition method.
6x1 – 2x2 = 14
9x1 – x2 + x3= 21
3x1 – 7x2 + 5x3= 9
48
Solution of
6 0 0 1 −1/ 3 0 Linear Algebraic
Hence, L = 9 2 0 , U = 0
1/ 2
Equations
1
3 8 +1 0 0 1
6 0 0 y 14 1
Solving Ly = b, 9 2 0 y = 21
2
3 8 1 y 9
3
14 7 1
We get, y1 = = ; 9 y1 + 2 y2 = 21, y2 = (21–21) = 0
6 3 2
3 y1 + 8 y2 + y3 = 9, y3 = 9 – 7 = 2.
1 −1/ 3 0 x 7 / 3 1
Solving Ux = y, 0 1 1/ 2 x = 0
2
0 0 1 x 2 3
1 1 7 7 1
We get, x3 = 2, x2 + x3 = 0, x2 = –1; x1 – x2 = , x1 = – = 2.
2 3 3 3 3
After decomposing A as A = LU, the next step is to computate the solution. We have,
LUX = b, set UX = y
Iterate means repeat. Hence, an iterative method repeats its process over and over,
each time using the current approximation to produce a better approximation for the
true solution, until the current approximation is sufficiently close to the true solution –
or until you realize that the sequence of approximations resulting from these iterations
is not converging to the true solution.
Given an initial guess or approximation x(0) for the true solution x, we use x(0) to find
a new approximation x(1), then we use x(1) to find the better approximation x(2), and so
on. We expect that x(k) → x as k → ∞ ; that is, our approximations should become
closer to the true solution as we take more iterations of this process.
Since, we do not actually have the true solution x, we cannot check to see how close
our current approximation x(k) is to x. One common way to check the closeness of x(k)
to x is instead by checking how close Ax(k) is to Ax, that is, how close Ax(k) is to b.
49
Numerical
Computing -I Another way to check the accuracy of our current approximation is by looking at the
magnitude of the difference in successive approximations, | x(k) − x(k-1) |. We expect
x(k) to be close to x if | x(k) − x(k-1) | is small .
This method is also called Gauss – Jacobi method. In Jacobi method, the first equation
is used to solve for x1, second equation is used to solve x2 etc. That is,
1
x1 = [b1 − (a12 x 2 + ...... + a1n xn)]
a11
1
x 2 = [b 2 − (a 21 x1 + a 23 x 3 + ...... + a 2 n xn )]
a 22
If in the ith equation
n
∑a
j =1
i, j x j =bi (15)
0 0 L 0
0 a 12 L a
1na 11 0
a 0 O 0 0 0 O a a
L= ,U = ,D =
21 2n 22
M O O M M O O M O
a n1 a L 0
n2
0 0 L 0 0 a
nn
Therefore, we have
(L + D + U) X = b, or DX = – (L + U) x + b
= MJ x(k) + C (19)
The matrix MJ is called the iteration matrix. Covergence of the method depends on the
properties of the matrix MJ.
50
Solution of
Diagonally dominant: A matrix A is said to be diagonally dominant if Linear Algebraic
n Equations
| aii |≥ ∑
j =1,i ≠ j
| aij | (20)
Convergence: (i) The Jacobi method converges when the matrix A is diagonally
dominant. However, this is a sufficient condition and necessary condition.
(ii) The Jacobi method converges if Spectral radius (MJ) < 1. Where Spectiral radius
of a matrix = max =| λ | and xi are eigenralues of MJ.This is a necessary and sufficient
i
i
2 −5.81 34 124 34 56
A = 45 43 1
and B = 23 53 5
123 16 1 96 34 129
Solution: In A, all the three rows violate the condition (20). Hence, A is not
diagonally dominant.
In B, in the row | –129 | = 129 < 96 + 34 = 130. Therefore, B is also not diagonally
dominant.
51
Numerical
Computing -I Let us represent the matrix A in the form
0 0 0 1 0 0 0 1 1
A = L + D + U = −1 0 0 + 0 3 0 + 0 0 0
1 0 0 0 0 −2 0 0 0
We have,
1 0 0 0 1 −1 0 −1 1
−1
Mj = − D ( L + U ) = − 0 1/ 3 0 −1 0 0 = 1/ 3 0 0
0 0 −1/ 2 1 0 0 1/ 2 0 0
1 0 0 0
−1
c = D b = 0 1/ 3 0 2 / 3
0 0 −1/ 2 3 / 2
0 −1 1 0
X ( k +1)
= 1/ 3 0 0 X + 2 / 3
(k )
1/ 2 0 0 3 / 2
Then, we have
0 −1 1 0.8 0 1.3
X (1)
= 1/ 3 0 0 0.8 + 2 / 3 = 0.9333
1/ 2 0 0 2.1 3 / 2 1.9
Since, the two procedures (direct and in matrix form) are identical, we get the same
approximations x(2), ….. x(9). The exact solution is x = [1 1 2]T.
Note that the coefficient matrix A is not diagonal dominant. But, we have obtained the
solution correct to two decimal places in 9 interactions. This shows that the
requirement of A being diagonal dominant is a sufficient condition.
2x1 – x2 + x3 = –1
x1 + 2x2 – x3 = 6
x1 – x2 + 2x3 = –3.
( k +1) (k )
x 2
= −0.5 0.0 0.5 x + 3.0 2
Since, no intial approximation is given, we start with x(0) = (0, 0, 0)T. We get the
following approximations.
We observe from Examples 2 and 3 that even for a 3 x 3 system, the number of
iterations taken by the Jacobi method (to achieve 2 or 3 decimal accuracy) is large.
For large systems, the number of iterations required may run into thousands. Hence,
the Jacobi method is slow. We also observe that when the variable xi is being iterated
in say the k-th iteration, the variables, x1, …. xi-1 have already been updated in the k-th
iteration. However, these values are not being used to compute xi(k). This is the
disadvantage of the Jacobi method. If we use all the current available values, we call it
the Gauss-Seidel method.
Two important facts about the Gauss-Seidel method should be noted. First, the
computations in (21) are serial. Since, each component of the new iterate depends
upon all previously computed components, the updates cannot be done simultaneously
as in the Jacobi method. Second, the new iterate depends upon the order in which the
equations are being used. The Gauss-Seidel method is sometimes called the method of
successive displacements to indicate the dependence of the iterates on the ordering. If
this ordering is changed, the components of the new iterate (and not just their order)
will also change.
53
Numerical
Computing -I To derive the matrix formulation, we write,
AX = (L + D + U) X = b or (L + D) X = – UX + b.
The Gauss-Seidel method can be expressed as
X(k+1) = – (L + D) –1 U X(k) + (L + D)–1b
= MG X (k) + C (22)
where MG = – (L + D) –1 U is in iteration matrix and C = (L + D) –1 b.
Again, convergence depends on the properties of MG if Spectral radius(MG) < 1, the
iteraction converges always for any intial solution vector. Further, it is known that
Gauss-Seidel method converges atleast two times faster than for Jacobi method.
Example 4: Solve the system in Example 2, by the Gauss-Seidel method. Write its
matrix form.
In 5 iteractions, we have for two place accuracy, while 9 iteractions we required in the
Jacobi method.
Starting with X(0) = [ 0.8 0.8 2.1]T, we get the same iterated values as above.
3.7 SUMMARY
In this unit, we have discussed direct and interative methods for solving a system of
linear equations. Under these categories of methods, used to solve a system of linear
equations, we have discussed Gauss elimination method and LU decomposition
method. We have also discussed the method of finding inverse of a square matrix.
Further, under the category of iterative methods for root determination we have
discussed Jacobi and Gauss Scidel method.
3.8 EXERCISES
E1. Solve the following systems using the Gauss elimination method.
55
Numerical
Computing -I E3. For problems in 1(a), (b); 2(a), (b), (c), (d), obtain the solution to 3 decimals
using the Jacobi and Gauss Seidel methods. Write the matrix formulations
also. Assume the initial solution vectors respectively as
(i) [0.8, 0.6, 0.5]T,
(ii) [0.3, 0.3, 0.6]T,
(iii) [0.9, −0.6, 0.6]T,
(iv) [1.9, 0.2, 0.9]T,
(v) [0.2, 0.5, 1.1]T,
(vi) [−1.1, 0.9, 2.1]T.
56