28.8 KB · commit a9602da
The solution of a linear system of equations can be accomplished by a numerical method which falls in one of two categories: direct or iterative
methods. Amongst the direct methods, we will describe the elimination method by Gauss as also its modification and the LU decomposition method. About the iterative types, we will describe only the Jacobi and Gauss–Seidel methods.
This is the elementary elimination method and it reduces the system of equations to an equivalent upper-triangular system, which can be solved by back substitution.
Let the system of n linear equations in n unknowns be given by
a11x1+a12x2+a13x3+⋯+a1nxna21x1+a22x2+a23x3+⋯+a2nxnan1x1+an2x2+an3x3+⋯+annxn=b1=b2⋮=bn⎭⎬⎫(7.27)There are two steps in the solution of the system given in Eq. (7.27), viz., the elimination of unknowns and back substitution.
Step 1: The unknowns are eliminated to obtain an upper-triangular system.
To eliminate x1 from the second equation, we multiply the first equation by (−a21/a11) and obtain −a21x1−a12a11a21x2−a13a11a21x3−⋯−a1na11a21xn=−b1a11a21.
Adding the above equation to the second equation of Eq. (7.27), we obtain (a22−a12a11a21)x2+(a23−a13a11a21)x3+⋯+(a2n−a1na11a21)xn=b2−b1a11a21,(7.28) which can be written as a22′x2+a23′x3+⋯+a2n′xn=b2′, where a22′=a22−a12(a21/a11), etc. Thus the primes indicate that the original element has changed its value. Similarly, we can multiply the first equation by −a31/a11 and add it to the third equation of the system (7.27). This eliminates the unknown x1 from the third equation of Eq. (7.27) and we obtain a32′x2+a33′x3+⋯+a3n′xn=b3′.(7.29)
In a similar fashion, we can eliminate x1 from the remaining equations and after eliminating x1 from the last equation of Eq. (7.27), we obtain the system
a11x1+a12x2+a13x3+⋯+a1nxna22′x2+a23′x3+⋯+a2n′xna32′x2+a33′x3+⋯+a3n′xnan2′x2+an3′x3+⋯+ann′xn=b1=b2′=b3′⋮=bn′⎭⎬⎫(7.30)We next eliminate x2 from the last (n−2) equations of Eq. (7.30). Before this, it is important to notice that in the process of obtaining the above system, we have multiplied the first row by (−a21/a11), i.e. we have divided it by a11 which is therefore assumed to be nonzero. For this reason, the first equation in the system (7.30) is called the pivot equation, and a11 is called the pivot or pivotal element. The method obviously fails if a11=0. We shall discuss this important point after completing the description of the elimination method. Now, to eliminate x2 from the third equation of Eq. (7.30), we multiply the second equation by (−a32′/a22′) and add it to the third equation. Repeating this process with the remaining equations, we obtain the system
a11x1+a12x2+a13x3+⋯+a1nxna22′x2+a23′x3+⋯+a2n′xna33′′x3+⋯+a3n′′xnan3′′x3+⋯+ann′′xn=b1=b2′=b3′′⋮=bn′′⎭⎬⎫(7.31)In Eq. (7.31), the 'double primes' indicate that the elements have changed twice. It is easily seen that this procedure can be continued to eliminate x3 from the fourth equation onwards, x4 from the fifth equation onwards, etc., till we finally obtain the upper-triangular form:
a11x1+a12x2+a13x3+⋯+a1nxna22′x2+a23′x3+⋯+a2n′xna33′′x3+⋯+a3n′′xnann(n−1)xn=b1=b2′=b3′′⋮=bn(n−1),⎭⎬⎫(7.32)where ann(n−1) indicates that the element ann has changed (n−1) times. We thus have completed the first step of elimination of unknowns and reduction to the upper-triangular form.
Step 2: We now have to obtain the required solution from the system (7.32). From the last equation of this system, we obtain xn=ann(n−1)bn(n−1).(7.33) This is then substituted in the (n−1)th equation to obtain xn−1 and the process is repeated to compute the other unknowns. We have therefore first computed xn, then xn−1,xn−2,…,x2,x1, in that order. Due to this reason, the process is called back substitution.
We now come to the important case of the pivot being zero or very close to zero. If the pivot is zero, the entire process fails and if it is close to zero, round-off errors may occur. These problems can be avoided by adopting a procedure called pivoting. If a11 is either zero or very small compared to the other coefficients of the equation, then we find the largest available coefficient in the columns below the pivot equation and then interchange the two rows. In this way, we obtain a new pivot equation with a nonzero pivot. Such a process is called partial pivoting, since in this case we search only the columns below for the largest element. If, on the other hand, we search both columns and rows for the largest element, the procedure is called complete pivoting. It is obvious that complete pivoting involves more complexity in computations since interchange of columns means change of 'order' of unknowns which invariably requires more programming effort. In comparison, partial pivoting, i.e. row interchanges, is easily adopted in programming. Due to this reason, complete pivoting is rarely used.
The upper-triangular form is therefore given by
2x+y+zy+3zz=10=6=5.It follows that the required solution is x=7, y=−9 and z=5. ◀
The next example demonstrates the necessity of pivoting in the elimination method.
This is a modification of the Gauss elimination method, the essential difference being that when an unknown is eliminated, it is eliminated from all equations. The method does not require back substitution to obtain the solution and is best illustrated by the following example.
We know that X will be the inverse of A if AX=I,(7.34) where I is the unit matrix of the same order as A. It is required to determine the elements of X such that Eq. (7.34) is satisfied. For example, for third-order matrices, Eq. (7.34) may be written as a11a21a31a12a22a32a13a23a33x11x21x31x12x22x32x13x23x33=100010001 The reader can easily see that this equation is equivalent to the three equations a11a21a31a12a22a32a13a23a33x11x21x31=100 a11a21a31a12a22a32a13a23a33x12x22x32=010 a11a21a31a12a22a32a13a23a33x13x23x33=001
We can therefore apply the Gaussian elimination method to each of these systems and the result in each case will be the corresponding column of A−1. Since the matrix of coefficients is the same in each case, we can solve all the three systems simultaneously. Starting with the 'augmented system' a11a21a31a12a22a32a13a23a33100010001 we obtain at the end of the first and second stage, respectively a1100a12a22′a32′a13a23′a33′1−a21/a11−a31/a11010001 and a1100a12a22′0a13a23′a33′′1α21α3101α32001, where α21=−a11a21,α31=a11a21a22′a32′−a11a31,α32=−a22′a32′.
The inverse can now be obtained easily, since the back-substitution process with each column of the matrix I will yield the corresponding column of A−1, where I is given by I=1α21α3101α32001.
Since the total execution time depends on the number of multiplications and divisions in Gaussian elimination, we give below a count of the total number of floating-point multiplications or divisions in this method.
For eliminating x1, i.e. in Eq. (7.28), the factor a21/a11 is computed once. There are (n−1) multiplications in the (n−1) terms on the left side and 1 multiplication on the right side. Hence the number of 'floating-point' multiplications/divisions required for eliminating x1 is 1+n−1+1=n+1. But x1 is eliminated from (n−1) equations. Therefore, the total number of multiplications/divisions required to eliminate x1 from (n−1) equations is (n−1)(n+1)=(n−1)(n+2−1). Similarly, the total number of multiplications/divisions required to eliminate x2 from (n−2) equations is (n−2)n=(n−2)(n+2−2). The total number of multiplications/divisions required to eliminate x3 from (n−3) equations is (n−3)(n−1)=(n−3)(n+2−3). Similarly, the total number of multiplications/divisions required to eliminate xp from (n−p) equations is (n−p)(n+2−p), and finally, xn−1 is eliminated in [n−(n−1)][n+2−(n−1)]=1⋅3.
Summing up all the above, we can write the total number of arithmetic operations (i.e. multiplications/divisions) as
p=1∑n−1(n−p)(n+2−p)=∑[(n−p)2+2(n−p)]=p=1∑n−1(n2+p2−2np+2n−2p)=n2(n−1)+6(n−1)(n)(2n−2+1)−2n2(n−1)n+2n(n−1)−22(n−1)n≈3n3,where we have used the formulae: 1+2+3+⋯+n=2n(n+1)and12+22+32+⋯+n2=6n(n+1)(2n+1).
It follows that the total number of 'floating-point' multiplications or divisions in Gaussian elimination is n3/3. In a similar way, it can be shown that the Gauss–Jordan method requires n3/2 arithmetic operations. Hence, Gauss elimination is preferred to Gauss–Jordan method while solving large systems of equations.
In Section 7.3, we described a scheme for computing the matrices L and U such that A=LU(7.35) where L is unit lower triangular and U an upper triangular matrix, and these are given in Eq. (7.2). Let the system of equations be given by
a11x1+a12x2+a13x3a21x1+a22x2+a23x3a31x1+a32x2+a33x3=b1=b2=b3⎭⎬⎫(7.36)which can be written in the matrix form AX=B(7.37) or LUX=B(7.38)
If we set UX=Y,(7.39) then Eq. (7.38) becomes LY=B(7.40) which is equivalent to the system
y1l21y1+y2l31y1+l32y2+y3=b1=b2=b3⎭⎬⎫(7.41)where (y1,y2,y3)T=Yand(b1,b2,b3)T=B.
The system (7.41) can be solved for y1,y2 and y3 by forward substitution. When Y is known, the system (7.39) becomes
u11x1+u12x2+u13x3u22x2+u23x3u33x3=y1=y2=y3⎭⎬⎫(7.42)which can be solved for x1,x2,x3 by backsubstitution process. As noted earlier, this method has the advantage of being applicable to solve systems with the same coefficient matrix but different right-hand side vectors.
Given any nonsingular square matrix A, the LU decomposition, where L is unit lower triangular and U an upper triangular matrix, can be achieved by the following computational steps:
Do i = 1(1)N - 1
Do j = i + 1(1)N
A(j, i) = A(j, i)/A(i, i)
Do M = i + 1(1) N
A(j, M) = A(j, M) - A(i, M) * A(j, i)
Next M
Next j
Next i
End
To save storage space, the elements of L and U are stored in the space occupied by A, the elements lii being omitted. Thus, after the factorization is effected, the layout of the store for a (4×4) matrix is given by u11l21l31l41u12u22l32l42u13u23u33l43u14u24u34u44
If the right-hand side vector is B=(b1,b2,b3), then the forward substitution can be accomplished by the statements:
Do j = 1(1)N - 1
Do i = j + 1(1) N
b(i) = b(i) - l(i, j) * b(j)
Next i
Next j
End.
Similarly, the backsubstitution can be effected by the steps:
Do j = N(-1)1
b(j) = b(j)/u(j, j)
Do i = 1(1) j - 1
b(i) = b(i) - u(i, j) * b(j)
Next i
Next j
End
We have seen that Gaussian elimination consists in reducing the coefficient matrix to an upper-triangular form. We show that the LU decomposition of the coefficient matrix can also be obtained from Gauss elimination. The upper-triangular form to which the coefficient matrix is reduced is actually the upper-triangular matrix U of the decomposition LU. Then, what is the lower-triangular matrix L? For this, we consider the system defined by AX=b,(7.43) where A=a11a21a31a12a22a32a13a23a33,X=x1x2x3,b=b1b2b3.
To eliminate x1 from the second equation, we multiply the first equation by a21/a11 and subtract it from the second equation. We then obtain (a22−a12a11a21)x2+(a23−a13a11a21)x3=(b2−b1a11a21) or a22′x2+a23′x3=b2′.(7.44)
The factor l21=a21/a11 is called the multiplier for eliminating x1 from the second equation. Similarly, the multiplier for eliminating x1 from the third equation is given by l31=a31/a11. After this elimination, the system is of the form
a11x1+a12x2+a13x3a22′x2+a23′x3a32′x2+a33′x3=b1=b2′=b3′.⎭⎬⎫(7.45)In the final step, we have to eliminate x2 from the third equation. For this we multiply the second equation by a32′/a22′ and subtract it from the third equation. We then obtain a33′′x3=b3′′,(7.46) where the double primes indicate that the concerned elements have changed their values twice. In this step, the multiplier is given by l32=a32′/a22′. The final form of the matrix of coefficients is the upper-triangular matrix given by U=a1100a12a22′0a13a23′a33′′.(7.47)
Equation (7.47) suggests that in any computer program, the places occupied by the zero elements may be used to store the values of the multipliers. Thus, after elimination, the matrix A may be written as a11l21l31a12a22′l32a13a23′a33′′,(7.48) which represents the storage of the LU decomposition of A with L=1l21l3101l32001andU=a1100a12a22′0a13a23′a33′′. It is easily verified that A=LU.
Consider the system of equations defined by
b1u1+c1u2a2u1+b2u2+c2u3a3u2+b3u3+c3u4anun−1+bnun=d1=d2=d3⋮=dn.⎭⎬⎫(7.49)The matrix of coefficients is A=b1a20⋯00c1b2a3⋯000c2b3⋯0000c3⋯⋯⋯⋯⋯⋯⋯00⋯⋯⋯⋯an−10⋯⋯⋯⋯bn−1an000⋯cn−1bn(7.50)
Matrices of the type, given in Eq. (7.50), called the tridiagonal matrices, occur frequently in the solution of ordinary and partial differential equations by finite difference methods. The method of factorization described earlier can be conveniently applied to solve the system (7.49). For example, for a (3×3) matrix we have b1a20c1b2a30c2b3=1l21001l32001b100c1u2200c2u33
This matrix equation gives
l21b1l32u22=a2,=a3,l21c1+u22l32c2+u33=b2,=b3}(7.51)From these four equations, we can compute l21, u22, l32 and u33 and these values are stored in the locations occupied by a2,b2,a3 and b3, respectively. These computations can be achieved by the following statements:
Do i = 2(1)N
a(i) = a(i)/b(i - 1)
b(i) = b(i) - a(i) c(i - 1)
Next i
When the decomposition is complete, forward and back substitutions give the required solution. This algorithm is due to Thomas and possesses all the advantages of the LU decomposition.
In practical applications, one usually encounters systems of equations in which small changes in the coefficients of the system produce large changes in the solution. Such systems are said to be ill-conditioned. On the other hand, if the corresponding changes in the solution are also small, then the system is well-conditioned.
Ill-conditioning can usually be expected when ∣A∣, in the system AX=b, is small. The quantity c(A) defined by c(A)=∥A∥∥A−1∥,(7.52) where ∥A∥ is any matrix norm, gives a measure of the condition of the matrix. It is, therefore, called the condition number of the matrix. Large condition numbers indicate that the matrix is ill-conditioned. Again, let A=[aij] and si=[ai12+ai22+⋯+ain2]1/2(7.53) If we define k=s1s2…sn∣A∣,(7.54) then the system is ill-conditioned if k is very small compared to unity. Otherwise, it is well-conditioned.
So, k=4.468×10−3 Hence the system is ill-conditioned. ◀
In general, the accuracy of an approximate solution can be improved upon by an iterative procedure. This is described below. Let the system be
a11x1+a12x2+a13x3a21x1+a22x2+a23x3a31x1+a32x2+a33x3=b1=b2=b3⎭⎬⎫(7.55)Let x1(1),x2(1) and x3(1) be an approximate solution. Substituting these values in the left side of Eq. (7.55), we get new values of b1,b2 and b3. Let these new values be b1(1),b2(1) and b3(1). The new system of equations is given by
a11x1(1)+a12x2(1)+a13x3(1)a21x1(1)+a22x2(1)+a23x3(1)a31x1(1)+a32x2(1)+a33x3(1)=b1(1)=b2(1)=b3(1)⎭⎬⎫(7.56)Subtracting each equation given in Eq. (7.56) from the corresponding equation given in Eq. (7.55), we obtain
a11e1+a12e2+a13e3a21e1+a22e2+a23e3a31e1+a32e2+a33e3=d1=d2=d3⎭⎬⎫(7.57)where ei=xi−xi(1) and di=bi−bi(1). We now solve the system (7.57) for e1,e2 and e3. Since ei=xi−xi(1), we obtain xi=xi(1)+ei,(7.58) which is a better approximation for xi. The procedure can be repeated to improve upon the accuracy.