linear systems ii
play

Linear Systems II CS3220 Summer 2008 Jonathan Kaldor Revisiting - PowerPoint PPT Presentation

Linear Systems II CS3220 Summer 2008 Jonathan Kaldor Revisiting the LU Factorization Goal: Solve Ax = b Represents n linear equations, with n unknowns Assume A is full rank (invertible, nonsingular) Idea: Simplify without


  1. Linear Systems II CS3220 Summer 2008 Jonathan Kaldor

  2. Revisiting the LU Factorization • Goal: Solve Ax = b • Represents n linear equations, with n unknowns • Assume A is full rank (invertible, nonsingular) • Idea: Simplify without changing the solution • What form is simpler to solve?

  3. Triangular Matrices

  4. Triangular Matrices • Upper Triangular Matrix a 11 a 12 .... a 1n x 1 b 1 0 a 22 .... a 2n x 2 b 2 . . . . . . = . . . . . . . . a n-1,n-1 a n-1,n x n-1 b n-1 0 0 .... a nn x n b n

  5. Triangular Matrices • Upper Triangular Matrix a 11 a 12 .... a 1n x 1 b 1 0 a 22 .... a 2n x 2 b 2 . . . . . . = . . . . . . . . a n-1,n-1 a n-1,n x n-1 b n-1 0 0 .... a nn x n b n Solve for x n

  6. Triangular Matrices • Upper Triangular Matrix a 11 a 12 .... a 1n x 1 b 1 0 a 22 .... a 2n x 2 b 2 Substitute x n , . . . . . . = solve for x n-1 . . . . . . . . a n-1,n-1 a n-1,n x n-1 b n-1 0 0 .... a nn x n b n Solve for x n

  7. Triangular Matrices • Upper Triangular Matrix Repeat for each variable a 11 a 12 .... a 1n x 1 b 1 0 a 22 .... a 2n x 2 b 2 Substitute x n , . . . . . . = solve for x n-1 . . . . . . . . a n-1,n-1 a n-1,n x n-1 b n-1 0 0 .... a nn x n b n Solve for x n

  8. Triangular Matrices • Upper Triangular Matrix Repeat for each variable a 11 a 12 .... a 1n x 1 b 1 0 a 22 .... a 2n x 2 b 2 Substitute x n , . . . . . . = solve for x n-1 . . . . . . . . a n-1,n-1 a n-1,n x n-1 b n-1 0 0 .... a nn x n b n Solve for x n • “Backward Substitution”

  9. LU Factorization • Convert Ax = b into MA x= Mb , where MA is upper triangular • M = M n-1 ... M 2 M 1 • M 1 - matrix that eliminates first variable from equations 2...n, M 2 is... • Property: If C and D are both upper (or both lower) triangular, CD is also upper (or lower) triangular (so M is lower tri)

  10. LU Factorization • So after n-1 steps, have: M n-1 ... M 2 M 1 Ax = M n-1 ... M 2 M 1 b • Define U = M n-1 ... M 2 M 1 A . • Upper triangular by construction • Multiply by L = M 1-1 M 2-1 ... M n-1-1 • Then LU = A

  11. Gaussian Elimination • What do the update matrices M i look like? 1 0 ... 0 0 ... 0 0 1 ... 0 0 ... 0 Ones along ⋮ ⋮ ⋱ ⋮ ⋮ ⋱ ⋮ the diagonal 0 0 ... 1 0 ... 0 0 0 ... -a i+1,i /a i,i 1 ... 0 ⋮ ⋮ ⋱ ⋮ ⋮ ⋱ ⋮ 0 0 ... -a n,i /a i,i 0 ... 1 Entries in the i-th column, below the diagonal, chosen to cancel i-th variable in equations i+1:n

  12. Gaussian Elimination • What do the inverse matrices M i-1 look like?

  13. Gaussian Elimination • What do the inverse matrices M i-1 look like? 1 0 ... 0 0 ... 0 0 1 ... 0 0 ... 0 ⋮ ⋮ ⋱ ⋮ ⋮ ⋱ ⋮ Note: entries below diagonal 0 0 ... 1 0 ... 0 have flipped signs 0 0 ... a i+1,i /a i,i 1 ... 0 ⋮ ⋮ ⋱ ⋮ ⋮ ⋱ ⋮ 0 0 ... a n,i /a i,i 0 ... 1

  14. The L in LU • So each M i-1 is lower triangular as well • In fact, unit lower triangular (ones on diagonal) • How about the product M 1-1 M 2-1 ... M n-1-1 ?

  15. Solving with LU factorization • Have LUx = b • Replace Ux with y • Solve Ly = b (forward substitution) • Then solve Ux = y (backward substitution)

  16. What does L look like?

  17. What does L look like? • We know: L is lower triangular, consists of product of M i-1 matrices

  18. What does L look like? • We know: L is lower triangular, consists of product of M i-1 matrices • Do we need to multiply M i-1 together to form L ?

  19. What does L look like? • We know: L is lower triangular, consists of product of M i-1 matrices • Do we need to multiply M i-1 together to form L ? • No!

  20. What does L look like? • We know: L is lower triangular, consists of product of M i-1 matrices • Do we need to multiply M i-1 together to form L ? • No! • Do we need to scale/update rows like U ?

  21. What does L look like? • We know: L is lower triangular, consists of product of M i-1 matrices • Do we need to multiply M i-1 together to form L ? • No! • Do we need to scale/update rows like U ? • No! (chalkboard)

  22. A Vectorized U update • How can we quickly apply M i to partially computed U matrix?

  23. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 -1 -2 0 0 1 -1

  24. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 1 2 1 -1 -2 0 0 0 1 0 1 -1 0 1 -1 Scale first equation by -(-1/1), add to second equation

  25. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 0 0 1 0 1 -1 Scale first equation by -(-1/1), add to second equation

  26. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 0 0 1 0 1 -1

  27. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 0 0 1 0 1 -1 Scale second equation by -(2/0), add to first equation

  28. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 ? 0 0 1 0 1 -1 Scale second equation by -(2/0), add to first equation

  29. Pivoting • Gaussian (and Gauss-Jordan) elimination both have failure cases • Consider the following matrix: 1 2 1 ? 0 0 1 Division by zero! 0 1 -1 Scale second equation by -(2/0), add to first equation

  30. Pivoting 1 2 1 0 0 1 0 1 -1

  31. Pivoting • Does that mean that the system is singular? 1 2 1 0 0 1 0 1 -1

  32. Pivoting • Does that mean that the system is singular? • Does the order we specify equations matter? 1 2 1 0 0 1 0 1 -1

  33. Pivoting • Observe: if we swap the second and third equations, Gaussian elimination works as expected 1 2 1 1 2 1 0 0 1 0 1 -1 0 1 -1 0 0 -1 • We can reorder equations as-needed in order to get “good” pivots (pivot: A jj )

  34. What makes a good pivot? • Again, back to our example. Suppose A(2,2) = 1e-15 • Instead of dividing by zero, dividing by a very small number • Almost as bad • Observation: Want to swap equations so that diagonal element is as large as possible in absolute value

  35. Partial Pivoting • At i-th step • Look at elements in i-th column below the diagonal , find largest in absolute value (say, j-th) • Swap i-th and j-th rows. Largest entry now in A(i,i) • Advantage: all multipliers in L ≤ 1 (recall, multipliers are A(j,i)/A(i,i) )

  36. Permutation Matrices • Want to represent these row swaps using matrix notation • Suppose we want to swap rows i and j in A • Take identity matrix • Swap rows i and j, call this matrix P • Then PA is the same as A with rows i and j interchanged

  37. Permutation Matrices • Note: P -1 = P T • PA : swaps rows • AP : swaps columns • Like M i matrices, never form them explicitly • Oftentimes, don’t even need to explicitly swap rows

  38. Pivoting in Matrix Formulation • Introduce P i matrices during computation M n-1 P n-1 ... M 2 P 2 M 1 P 1 Ax = M n-1 P n-1 ... M 2 P 2 M 1 P 1 b • Job of each P i : move row with largest element in i-th column to the i-th row

  39. Pivoting in Matrix Formulation • U = M n-1 P n-1 ... M 2 P 2 M 1 P 1 A • L is still formed from M i , but multipliers below diagonal get permutated • P = P n-1 ... P 2 P 1 • End up with LU = PA

  40. An Example 1 2 2 4 4 2 4 6 4

  41. LU with Partial Pivoting • Factor A into PA = LU • To solve Ax = b : • Note: A = P T LU • So we have P T LUx = b • Multiply by P to get LUx = Pb

  42. LU with Partial Pivoting • Now have LUx = Pb • Solve Ly = Pb for the vector y using forward substitution • Solve Ux = y for the vector x using backward substitution

  43. LU with Partial Pivoting • What happens if all the elements in a column below the diagonal are zero?

  44. Solving in MATLAB • MATLAB provides an operator to solve linear systems • A \ b solves equation Ax = b • Can also specify matrix B • Be careful: also / operator (solves AB -1 ) • Solves more than just n x n systems (more to come!)

  45. Solving in MATLAB • To compute LU factorization of matrix A , use function lu(A) • Syntax: [L, U] = lu(A) • L is not lower triangular... ‘psychologically lower triangular’ • Or: [L,U,P] = lu(A) • P: permutation matrix

  46. Wait! ‘Partial’ Pivoting?! • We reordered equations to get a good pivot element... could we also relabel our unknowns to get a better element? • Short answer: Yes • Longer answer: Yes, but typically partial pivoting is good enough

  47. LU Factorization: A Summary • Generalized solution method for n x n systems of linear equations in n unknowns • Requires pivoting in order to avoid certain failure cases

Recommend


More recommend