Introduction to Algorithms
Total Page:16
File Type:pdf, Size:1020Kb
9/8 –9/19/03; DisMth CPS196.2, Chapter 2; Matrix Algebra and Vector Spaces 1. Introduction In this time period, we will take another look at material you may have covered in your linear algebra course and in cps150. 2. Arrays and Matrices Arrays are collections of data that can be accessed by a multiple index set. These index sets could be quite general and abstract, but we will stick to matlab conventions where 1-dimensional arrays are indexed as in A(i) , 1i≤ ≤ n, and 2-dimensional arrays as in A(i,j), i as before, and 1j≤≤m. In matlab, for the n x m array A, A(i,j) is in the ith row and jth column; A(:,j) is the jth column and A(i,:) is the ith row. The entries in an array can be anything depending on the application; e.g., phone numbers, internet addresses, test scores. Microsoft Excel is a program that allows convenient operations on arrays, for example. When the array, A, contains numbers, by which we shall mean entries from a field,F , then A is usually called a matrix over the field F . Matrices have algebraic properties; you can add them, multiply them if their sizes are compatible, and sometimes find inverses and other useful manipulations. Matrix equations model lots of applications and matrix algebra is important and essential in modern technology. Consider the n x n matrix A = (aij) (this notation means A(i,j) = aij ) and column n-vectors x = [x1; x2; …; xn] and b = [b1; b2; …; bn]. The matrix equation (LS1) Ax = b , which asks for the solution x given b is probably the most important equation in applied mathematics. In the old days, this was tediously written as, n (LS2) ∑axij j =≤bi ,1 i≤n, i1= which is unnecessary and boring once you know matrix operations. We turn now to the solution of (LS1) by the algorithm known as Gaussian elimination, which is really matrix factorization. 3. Solving Linear Equations, Ax = b Suppose we write A as A =[a1, …, an]; then (LS1) an be written as 1 n (LS3) ∑ xaii= b, i1= and this is not so boring since it says we are trying to represent b by a linear combination of the columns of A (EXERCISE 1: why?) We will look further at such notions in the next section. Please review lower and upper triangular matrices, diagonal matrices, and permutation matrices, which have all entries 0 except for a single 1 in each row and column. If P is an n x n permutation matrix matrix, PA rearranges the rows of A while AP rearranges the columns (EXERCISE 2: why?). Note also that PPT = PTP is also a defining property. Recall that the matrix A has a left inverse if there is a C such that CA = I, the n x n identity matrix. Similarly A has a right inverse if there is a B such that AB = I. As we will see directly either inverse implies the other, and both equations imply B = C. We can then write the inverse as A-1 with A-1A = AA-1 = I so formally (LS1) has the solution (INV) xA= −1b. Of course, we still don’t know how to compute x. We know, from matlab, that matrices can often be conveniently in block (or partitioned) form. Suppose we write our matrix A as ar (BLK) A = , cB where a 1 x 1 (called a scalar), B (n-1) x (n-1), and r and c are row and column vectors of size n-1. If a≠ 0, we can begin to factor A as ar 1 0ar (GE1) AL== =0UB. cB c/aI0B1 where L0 is unit lower triangular (lower triangular with 1’s on the diagonal), UB is block upper triangular, r and B1= B – cr/a. Continuing recursively, suppose BL1= 1U1where, again L1 is unit lower triangular and U1 is upper triangular. Then ar 1 0ar A == cB c/aI0B1 10ar (GE2) = c/a 1 0L11U 10ar ==LU. c/a L110 U 2 We see that we have factored A as A = LU where L is unit lower triangular and U is upper triangular, assuming a≠ 0and that BL1= 1U1has such a factorization; we will have to clean up these assumptions later, since maybe a = 0 or is relative very small. But, if we can do such a factorization, solving Ax = b is easy. We just backsolve twice with the triangular factors; that is we solve (BKS1) Ly = b for y1,…,yn (since the lii =1) and (BKS2) Ux = y for xn,…,x1 (assuming the uii ≠ 0). Then L(Ux) = b = Ax which is what we want. −1 10 −1 Notice that L0 has an inverse, L0 = and LA0= U1. Exercise 3: You need −c/a I -1 to check that the effect of L0 on A is to add –ci/a x row 1 to row i of A; this zeros out the first column of A below the diagonal and gives U1. This is the first “elimination step” in Gaussian elimination. The recursion just continues the process on U1 (or B1) until we get U. Often explanations of this view of Gaussian elimination also do the row operations on b as one proceeds, but this is unnecessary. In fact, the view of LU factorization implied by (GE2) is clean and clear and it implies and obvious implementation using recursion (which might be inefficient) or a for loop. 01 But it is not always possible to factor A = LU; for example consider A = . 10 However the associated linear system does have the solution x1 = b2 and x2 = b2. The whole answer is given in the following theorem. Theorem LU. For any n x n matrix A, the following are equivalent. [LI] A has a left inverse. [CI] Ax = 0 implies x = 0. [FCT] PA = LU, where P is a permutation matrix, L is unit lower triangular, and U = (uij) is upper triangular with u0ii ≠ . [LSS] For any b, Ax = b has a solution. [RI] A has a right inverse. [RwI] ATx = 0 implies x = 0. We proceed the proof with some discussion. In view of (LS3), the column independence condition, [CI], says there is no linear combination of the columns of A that sums to the zero vector. This implies immediately that the x of the linear system solution in [LSS] is unique (Exercise 4: why?). Since AT appears in [RwI], this is the row independence condition. Notice that to fix up our intuitive discussion related to (GE2), we have to use 3 the row interchange permutation matrix, P, in the matrix factorization condition, [FCT], and that once we have this factorization, solving A x = b is just backsolving using PTb. If any of the conditions of Theorem LU hold, we say A is nonsingular. Often “nonsingular” is defined to be the condition (CI), and the existence of an inverse is called “invertibility.” Proof. We prove that each condition implies the one following with the last implying the first. [LI] implies [CI]. Suppose A has a left inverse C; the CA = I. Then if Ax = 0, we have C(Ax) = CAx = x = 0, and we are done. [CI] implies [FCT]. We use induction on n. [CT] implies that, if A is 1 x 1, A≠ 0; otherwise Ax = 0 for any x. No permutation matrix is necessary and A = 1 A. The induction hypothesis assumes the case n-1 from which we must prove case n. For n x n A, we first note that [CT] implies some entry in the first column, say a, has a≠ 0; otherwise, Ax = 0 for any x = [x1,0] and x1 ≠ 0. Hence, in analogy with (GE1), ar there is a P which interchanges rows and we write PA1 = ,a≠ 0, and B is n x n. cB As in (GE1), ar 1 0ar (GE3) PA1 ==x , B1= B – cr/a. cB c/aI0B1 We would like to use the induction hypothesis to assert that P2B1 = L1U1, but we need to verify that B1y = 0 implies y = 0. Suppose some y ≠ 0 exits with B1y = 0. Let x = [-ry/a, y]. Then ar 1 0ar−ry/a PA1 x== =0. cB c/aI0B1 y T But, then, P1 (P1Ax) = Ax = 0 for nonzero x which contradicts [CI]; hence no such y exists and we can assert P2B1 = L1U1 where P2, L1, and U1 are as in the statement of [FCT]. Combining this equation with (GE3), we see ar 1 0ar PA1 == T cB c/aI0P21LU1 (GE4) 10ar = T . c/a P21L 0 U1 4 We see we are almost done. However we have done row interchanges corresponding to 10 P2, and we must bring them “out”. To do this we take P= P1 and notice that the 0P2 first matrix is a permutation matrix and the product is also a permutation (Exercise 5: why?). Hence 10ar (GE5) PA ==LU, Pc21/a L 0 U1 and wee are done. [FCT] implies [LSS]. To solve Ax = b, we backsolve Ly = PTb and Ux = y. [LSS] implies [RI]. Solve Axi = ei, where ei = I(:,i) , and let X(:,I) = xi. The AX = I. [RI] implies [RwI]. Note ATx = 0 if and only if xTA = 0. If xTA = 0 and AX = I, then xTAX = xT = 0 iff x = 0. [RwI] implies [LI]. Since ATx = 0 implies x = 0 the chain of implications from [LI] to [RI] applies to AT. T T T T Hence A has a right inverse, say, B , such that A B = I. Thus BA = I (rules of transpose) and A has a left inverse.