Direct Methodsmethods Forfor Solvingsolving Linearlinear Systemssystems (3H.)(3H.)
Total Page:16
File Type:pdf, Size:1020Kb
NumericalNumerical MethodsMethods RafaRafałł ZdunekZdunek DirectDirect methodsmethods forfor solvingsolving linearlinear systemssystems (3h.)(3h.) ((GaussianGaussian eliminationelimination andand matrixmatrix decompositionsdecompositions)) Introduction • Solutions to linear systems • Gaussian elimination, • LU factorization, • Gauss-Jordan elimination, • Pivoting Bibliography [1] A. Bjorck, Numerical Methods for Least Squares Problems, SIAM, Philadelphia, 1996, [2] G. Golub, C. F. Van Loan, Matrix Computations, The John Hopkins University Press, (Third Edition), 1996, [3] J. Stoer R. Bulirsch, Introduction to Numerical Analysis (Second Edition), Springer-Verlag, 1993, [4] C. D. Meyer, Matrix Analysis and Applied Linear Algebra, SIAM, 2000, [5] Ch. Zarowski, An Introduction to Numerical Analysis for Electrical and Computer Engineers, Wiley, 2004, [6] G. Strang, Linear Algebra and Its Applications, Harcourt Brace & Company International Edition, 1998, Applications There are two basic classes of methods for solving a system of linear equations: direct and iterative methods. Direct methods theoretically give an exact solution in a (predictable) finite number of steps. Unfortunately, this does not have to be true in computational approach due to rounding errors: an error made in one step spreads in all following steps. Classical direct methods usually involve a variety of matrix factorization techniques such as the LU, LDU, LUP, Cholesky, QR, EVD, SVD, and GSVD. Direct methods are computationally efficient only for a specific class of problems where the system matrix is sparse and reveals some patterns, e.g. it is a banded matrix. Otherwise, iterative methods are usually more efficient. Solutions to linear systems m: ixrtro ma fingollow fd in thexses een beprations cqua era linem ofste syA Ax= b (1) , MN× M where =A [aij ] ∈ ℑ is a coefficient mtarix, =b []bi ∈ ℑ is a dat vector, and a N MN×( 1+ ) =x []x j ∈ ℑt ed. Ltestima e solution to be isB a=[] A = b ℑ mentauged be the eethr of one nyain veha beytions maqua era linem ofste syhe. T1)m (steixtr syma to the s: ya wpossible A stem has no solution, if The syrankAB()< rank )(. B unilstqeue solutem has a siion, ngThe sy if rankAB()=rank )( = . N C solutions, ifny malyinites infm haste syheTrankAB()=rank )( < . N Solutions to linear systems If the case B takes place, the system (1) can be basically solved with direct or iterative methods. When we have the case A (which often occurs in practice), only an approximate solution to (1) can be estimated, usually by formulating a least squares problem. The case C occurs for rank-deficient problems or under-determined problems. Gaussian elimination (example) ⎧ 21xxx123++=,(E1) ⎪ ⎨62xxx123+ +=− 1, (E2) ⎪−22xxx++= 7, (E ) (Pivot) ⎩ 123 3 ⎧ 21xxx123++=,⎧ 21xxx123++=,⎧ 21xxx123++=, ⎪ ⎪ ⎪ ⎨62xxx123+ +=− 1,⎨024,xx12− −=− x 3 (E2 -3E1 ) ⎨024,xx12− −=− x 3 ⎪ ⎪ ⎪ ⎩−+22xxx123 += 7,⎩−22xxx123++= 7, ⎩032xx12+ += x 3 8, (E3 -E1 ) Gaussian elimination (example) ⎧ 21xxx123++=,⎧ 21xxx123++=, ⎪ ⎪ ⎨024,xx12− −=− x 3 ⎨ 024,xx12− −=− x 3 ⎪032xx+ += x 8, ⎪004xxx+ −=− 4, ⎩ 12 3 ⎩ 123 (E3 -3E2 ) (Pivot) (Triangularization) Back-substitution: x3 =1, xx23= 42−=−⋅= 4212, 11 xxx= ()11−− =() −−=−211, 12322 Gaussian elimination (example) Augmented matrix: [Ab| ] Let ⎧ 21xxx123++=, ⎪ ⎨62xxx123+ +=− 1, ⎪ ⎩−22xxx123++= 7, ⎡⎤⎡⎤⎡⎤2111 2111 2111 ⎢⎥⎢⎥⎢⎥ []Ab|= ⎢⎥⎢⎥⎢⎥ 6211−→ 012 −− −→ 4 012 −− − 4 RR21−+33RR32 RR+ ⎣⎦⎣⎦⎣⎦⎢⎥⎢⎥⎢⎥−−−221 731 0 3 2 8 0 0 4 4 Gaussian elimination (example) Recursive technique: Step 1: k =1, AA(1) = , bb(1) = , Ax(1)= b (1) , (1) (1) (1) (1) (1) ⎡aaa b⎤ (R1 ) ⎢ 11 12 13 1 ⎥ ⎡⎤(1) (1) (1) (1) (1) (1) (R (1)) ⎣⎦Ab| = ⎢aaa21 22 23 b 2 ⎥ 2 (1) (1) (1) (1) ⎢aaa b⎥ (R (1)) ⎣ 31 32 33 3 ⎦ 3 ⎛⎞a(1) (1) (1) (1) (1) (2) (1) 21 (1) ⎡aaa b⎤ RR22←−⎜⎟ R 1, 11 12 13 1 a(1) (2) (2) ⎢ (2) (2) (2) ⎥ ⎝⎠11 ⎡⎤Ab|0= ⎢ aa22 23 b 2 ⎥ ⎣⎦ ⎛⎞a(1) ⎢ 0 aa(2) (2) b (2) ⎥ RR(2)←− (1) 31 R(1), ⎣ 32 33 3 ⎦ 33⎜⎟(1) 1 ⎝⎠a11 Gaussian elimination (example) k = 2, Step 2: ⎡aaa(1) (1) (1) b (1) ⎤ ⎢ 11 12 13 1 ⎥ ⎡⎤Ab(2)|0 (2) = aa(2) (2) b (2) ⎛⎞(2) ⎣⎦⎢ 22 23 2 ⎥ (3) (2) a32 (2) RR33←−⎜⎟ R 2, ⎢ 00ab(3) (3) ⎥ a(2) ⎣ 33 3 ⎦ ⎝⎠22 In general: ⎛⎞aa()kk () aa(1)kk+ ←− () ik kj ij ij ⎜⎟()k ⎝⎠akk (2) (1) Determinant: det(AA) =± det ( ) Computational cost Gaussian elimination (example) ⎧ xx23−=3, ⎪ ⎨ −+24xxx123 −= 1, ⎪ ⎩−254xx123+−=− x 2, Augmented matrix: ⎡ 01−− 1 3⎤⎡2411− ⎤ ⎢ ⎥⎢ ⎥ []Ab|2411=−⎢ −⎥⎢ → 0113− ⎥ Interchange RR12 and ⎣⎢−25−− 4 2⎦⎣⎥⎢−25 −− 4 2 ⎦⎥ ⎡⎤⎡⎤−−24 1 1 −− 24 1 1 ⎢⎥⎢⎥ →−→−⎢⎥⎢⎥01 13 01 1 3 RR31−− RR 32 ⎣⎦⎣⎦⎢⎥⎢⎥01−− 3 3 00−− 2 6 Gauss-Jordan elimination The difference between the Gaussian and Gauss-Jordan elimination: 1. At each step, the pivot element is forced to be 1, 2. At each step, all terms above the pivot as well as all terms below the pivot are eliminated. Solution Gauss-Jordan elimination (example) ⎧ 226xxx123++= 4, ⎡ 226 4⎤⎡ 1132⎤ ⎪ ⎢ ⎥⎢ ⎥ ⎨ 276,xx12++ x 3 = []Ab| =→217 6 217 6 ⎢ ⎥⎢ R /2 ⎥ ⎪−−267xxx − =− 1, 1 ⎩ 123 ⎣⎢−267−− − 1⎦⎣⎥⎢ −−− 267 − 1⎦⎥ ⎡⎤⎡⎤⎡⎤11 3 2 11 3 2 104 4 ⎢⎥⎢⎥⎢⎥ →−⎢⎥⎢⎥⎢⎥0112 → 0112 −−→ 0112 −− RR21−−2R2 RR12 − RR++2 RR4 31⎣⎦⎣⎦⎣⎦⎢⎥⎢⎥⎢⎥0413− −−−−− 041332 0055 ⎡⎤⎡⎤10 4 4 100 0 ⎡ 0 ⎤ ⎢⎥⎢⎥ ⎢ ⎥ →−−→−⎢⎥⎢⎥01 1 2 010 1 Solution: x = −1, −−RR31/5 4R3 ⎢ ⎥ ⎢⎥⎢⎥00 1 1 RR23+ 001 1 ⎣⎦⎣⎦ ⎣⎢ 1 ⎦⎥ Computational cost Partial Pivoting Strategy: Maximize the magnitude of the pivot at each step only by using row interchanges. Partial Pivoting (example) ⎧−10−4 xx+= 1, ⎨ 12 ⎩ xx12+=2, If real numbers are rounded to 3 floating digits, without partial pivoting, we have: ⎡−−10−−44 111⎤⎡ 10 1 ⎤ Ab| =→ []⎢ ⎥⎢4 4 4 ⎥ ⎣ 1121⎦⎣ RR21+10 010 0 ⎦ Round-off: 454454 float(1+= 10) float ( .10001 ×= 10) 10 , float(2+= 10) float ( .10002 ×= 10) 10 , Back-substitution gives: ⎡0⎤ x = ⎢ ⎥ , ⎣1⎦ Partial Pivoting (example) ⎧−10−4 xx+= 1, ⎨ 12 ⎩ xx12+=2, If real numbers are rounded to 3 floating digits, with partial pivoting, we have: ⎡⎤⎡⎤⎡⎤−10−4 1 1112112 []Ab| =→ → ⎢⎥⎢⎥⎢⎥ −4 −4 ⎣⎦⎣⎦⎣⎦1121011011− RR21+10 Round-off: −41 −41 float(1+ 10) =×= float ( .10001 10) 1, float (1+× 2 10) =float ( .10002 × 10) = 1, Back-substitution gives: ⎡1⎤ x = ⎢ ⎥ , ⎣1⎦ Ill-conditioned systems Ax= b Condition number: κ AAA=⋅−1 () 2 2 A system of linear equations is said to be ill-conditioned when some small perturbation in the system can produce relatively large changes in the exact solution. Otherwise, the system is said to be well-conditioned. Row Echelon Form mn× Let A ∈ℑ , A - j-th column of A A - i-th row of A ( )* j ( )i* Row Echelon Form: 1. If (A)i* consists entirely of zeros, then all rows below (A)i* are also entirely zero rows; 2. If the first non-zero entry in (A)i* lies in the j-th position, then all entries below the i-th position in columns (A)*1, (A)*2, ..., (A)*j are zero. Rank Suppose A ∈ m ℑ × n is reduced by row operations to the Row Echelon Form (REF). The rank of A is defined to be the number: rank(A) = number of pivots, = number of non-zero rows in REF, = number of basic columns in A, where the basic columns of A are these columns that contain pivots. Reduced Row Echelon Form Reduced Row Echelon Form (RREF): 1. REF is in row echelon form, 2. The first non-zero entry in each row (i.e. each pivot) is one, 3. All entries above each pivot are zeros. RREF (example) ⎡12231⎤ ⎡12231⎤⎡ 12231 ⎤ ⎢ ⎥ ⎢ ⎥⎢ ⎥ 24462 ⎢24462⎥⎢ 00000 ⎥ A = ⎢ ⎥ RREF =→ ⎢36696⎥ ⎢36696⎥⎢ 00003 ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ 12453 00222 ⎣12453⎦ ⎣ ⎦⎣ ⎦ ⎡12231⎤⎡ 1201−− 1⎤⎡ 1201 1⎤⎡ 12010 ⎤ ⎢00111⎥⎢ 0011 1⎥⎢ 0011 1⎥⎢ 00110 ⎥ →→⎢ ⎥⎢ ⎥⎢ →⎥⎢ → ⎥ ⎢00003⎥⎢ 0000 3⎥⎢ 0000 1⎥⎢ 00001 ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥ ⎣00000⎦⎣ 0000 0⎦⎣ 0000 0⎦⎣ 00000 ⎦ We have rank (A) = 3, Basic columns: {AAA*1,, *3 *5} Matrix Inversion If A is nonsingular: Gauss− Jordan −1 [AI||] ⎯⎯⎯⎯⎯→ ⎡⎤⎣⎦IA , Matrix Inversion (example) ⎡111⎤ ⎢ ⎥ A = ⎢122⎥ ⎣⎢123⎦⎥ ⎡111 100⎤⎡ 111 1 00⎤⎡ 100 2− 10⎤ ⎢ ⎥⎢ ⎥⎢ ⎥ []AI| =→−⎢122 010⎥⎢ 011 110⎥⎢→− 011 1 1 0⎥ ⎣⎢123 001⎦⎣⎥⎢ 012−− 101⎦⎣⎥⎢ 001 0 11⎦⎥ ⎡⎤100 2− 1 0 210− ⎢⎥⎡ ⎤ →−−010 1 2 1 −1 ⎢ ⎥ ⎢⎥A = ⎢−−12 1⎥ ⎢⎥001 0− 1 1 ⎣⎦⎣⎢ 011− ⎦⎥ Matrix Factorizations A matrix factorization (or decomposition) decomposes a matrix A into a product of other objects (or factors)FF 1,,K k : AFFF= 1 2L k , where the number of factor matrices k depends on the factorization. Most often, k = 2 or k = 3. There are many different matrix decompositions; each one finds use among a particular class of problems. The most known matrix decompositions or factorizations include: LU, LDU, LUP, Block LU, Cholesky, QR, EVD, SVD, GSVD, Jordan, Jordan-Chevalley, Schur, QZ, Takagi, Polar, Rank factorization, and several forms of NMF. Gaussian elimination algorithm Sweep over the columns Multipliers for the k-th column; They form a lower triangular matrix. (LU factorization) LU factorization aa a a ⎡⎤11 12 L 1(nn− 1) 1 ⎡⎤10LL 00 ⎡uu11 12 u1(nn− 1) u 1 ⎤ ⎢⎥⎢⎥⎢ ⎥ aaaa l1 00 u u u ⎢⎥21 22 LL2(nn− 1) 2 ⎢⎥21 ⎢ 0 22 L 2(nn− 1) 2 ⎥ ⎢⎥aa⎢⎥⎢ ⎥ aa31 32 LL3(nn− 1) 3 =⋅ll31 33 00 00L u3(nn− 1) u 3 ⎢⎥⎢⎥⎢ ⎥ ⎢⎥MMO MM ⎢⎥MMOMM ⎢ MMO MM⎥ ⎢⎥aa a a ⎢⎥ll l 1 ⎢ ⎥ ⎣⎦nn12L nnnn (1)− ⎣⎦nn12L nn (1)− ⎣ 00L 0 unn ⎦ A∈ℜnxn L∈ℜnxn U∈ℜnxn nn Determinant: det()ALU== det () det () 1⋅=∏uuii∏ ii ii==11 LU factorization For each k, we have ⎡10 0⎤ ⎢0 ⎥ ⎢ OO ⎥ ()k ()k a L = ⎢ OO1,⎥ where l = ik , ⎢ ⎥ ik a()k ⎢ 00−l(1)kk+ O ⎥ kk ⎢ ⎥ ⎣00L −lnk 1⎦ (1)kk+ () ()nn (−− 1) (2)(1) 1 Recursive technique: ALA= , ⇒ UA== LK LLALA =, −1 ()kk () Since (LL) =− , we have −−−−1111 (nnn−− 1) (2) (1) (1) (2) ( 1) (1) (2) (− 1) ()LLLLLKKK==( ) ( ) ( L) (− LL)(−) (− L) Finally ALU= LDU factorization ⎡1 uuu12 L 1(nn− 1) 1 ⎤ ALDU= % ⎢ ⎥ 01L uu2(nn− 1) 2 ⎧ 1 ⎫ ⎢ ⎥ where D = diag , and DU% = U, ⎢ uu⎥ ⎨ ()k ⎬ U% = 00L 3(nn− 1) 3 ⎩⎭akk ⎢ ⎥ ⎢MMO MM ⎥ ⎢ ⎥ T 00 01 If A is symmetric, ALDL= ⎣ L ⎦ n −1 Determinant: ()k det()ALDU== det () det () det ()% ∏()dkk i=1 Crout’s algorithm Set ukk =1 for all k For k = 1,…,n For i = k, k+1, …, n k−1 laik=− ik∑ lu ip pk p=1 For j = k +1,…, n 1 ⎛⎞k −1 ualukj=−⎜⎟ kj∑ kp pj lkk ⎝⎠p=1 LUP factorization If a zero pivot occurs, the basic LU factorization cannot be used.