1 / 49

6. LU Factorization

6. LU Factorization. 2005010211 Kim Hong Soo 2003010478 Kim Jin Soo 2003010481 Choi Jang Won. Contents. LU Factorization from Gaussian Elimination LU Factorization of Tridiagonal Matrices LU Factorization with Pivoting Direct LU Factorization Application of LU Factorization

nickolas
Download Presentation

6. LU Factorization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6. LU Factorization 2005010211 Kim Hong Soo 2003010478 Kim Jin Soo 2003010481 Choi Jang Won 분산시스템 연구실

  2. Contents • LU Factorization from Gaussian Elimination • LU Factorization of Tridiagonal Matrices • LU Factorization with Pivoting • Direct LU Factorization • Application of LU Factorization • Matlab’s Method 분산시스템 연구실

  3. Example. Circuit Analysis Application • Solve by LU Factorization of coefficient matrix Flow around the left loop - + - = 20 ( i i ) 10 ( i i ) 0 1 2 1 3 Flow around upper loop + - + - = 25 i 10 ( i i ) 20 ( i i ) 0 2 2 3 2 1 Flow around lower loop + - + - = 30 i 10 ( i i ) 10 ( i i ) 200 3 3 2 3 1 분산시스템 연구실

  4. 6.1 LU Factorization from Gaussian Elimination 분산시스템 연구실

  5. LU Factorization from Gaussian Elimination- Example 6.1 • Example 6.1 Three-By-Three System , , Step 1: , , Step 2: , , Multiply L by U, and Verify the result: . LU = = = A 분산시스템 연구실

  6. LU Factorization from Gaussian Elimination- Example 6.2 • Example 6.2 Four-By-Four System Step 1: Row 1 is unchanged, and rows 2-4 are modified to give 분산시스템 연구실

  7. LU Factorization from Gaussian Elimination- Example 6.2 Example 6.2 Four-By-Four System Step 2: Row 1 and 2 are unchanged, row 3 and 4 are transformed, yielding Step 3: The fourth row is modified to complete the forward elimination stage: 분산시스템 연구실

  8. LU Factorization from Gaussian Elimination- Example 6.2 Example 6.2 Four-By-Four System Multiply L by U to verify the result: . = L . U = A 분산시스템 연구실

  9. LU Factorization from Gaussian Elimination- MATLAB Function for LU Factorization 6.1.1 MATLAB Function for LU Factorization Using Gaussian Elimination function [L, U] = LU_Factor(A) % LU factorization of matrix A % using Gaussian elimination without pivoting % Input : A  n-by-n matrix % Output L ( lower triangular ) and % U (upper triangular ) [n, m] = size(A); L = eye(n); % initialize matrices U = A; for j = 1 : n for I = j + 1 : n L( i , j ) = U( i, j ) / U( j, j ); U( i , : ) = U( i, j ) / L( j, j ) * U( j, : ); end end % display L and U L U % verify results B = L * U A 분산시스템 연구실

  10. LU Factorization from Gaussian Elimination- MATLAB Function for LU Factorization >> LU_factor(A); L = 1.0000 0 0 0 0.2500 1.0000 0 0 0 0 1.0000 0 0 0 0 1.0000 L = 1.0000 0 0 0 0.2500 1.0000 0 0 0.5000 0 1.0000 0 0 0 0 1.0000 L = 1.0000 0 0 0 0.2500 1.0000 0 0 0.5000 0 1.0000 0 0.7500 0 0 1.0000 L = 1.0000 0 0 0 0.2500 1.0000 0 0 0.5000 0.7500 1.0000 0 0.7500 0 0 1.0000 L = 1.0000 0 0 0 0.2500 1.0000 0 0 0.5000 0.7500 1.0000 0 0.7500 0.5000 0 1.0000 L = 1.0000 0 0 0 0.2500 1.0000 0 0 0.5000 0.7500 1.0000 0 0.7500 0.5000 0.2500 1.0000 L = 1.0000 0 0 0 0.2500 1.0000 0 0 0.5000 0.7500 1.0000 0 0.7500 0.5000 0.2500 1.0000 U = 4 12 8 4 0 4 16 8 0 0 4 12 0 0 0 4 B = 4 12 8 4 1 7 18 9 2 9 20 20 3 11 15 14 A = 4 12 8 4 1 7 18 9 2 9 20 20 3 11 15 14 분산시스템 연구실

  11. LU Factorization from Gaussian Elimination- Example 6.3 • Example 6.3 LU Factorization for Circuit Analysis Example Step 1: The matrices after the first stage of Gaussian elimination are , Step 2: The matrices after the second stage of Gaussian elimination are , 분산시스템 연구실

  12. LU Factorization from Gaussian Elimination - Discussion • 6.1.2 Discussion . = Here, d12 = ca11+a21, d22=ca12+a22, and d32 = ca13+a32. We write this as CA = D We also need the inverse of the matrix C . , = or C-1 . C = I . 분산시스템 연구실

  13. LU Factorization from Gaussian Elimination - Discussion . = M1-1 . M1 = I . . = M2-1 . M2 = I . . = M1-1 . M2-1 = I . 분산시스템 연구실

  14. 6.2 LU Factorization of Tridiagonal Matrix 분산시스템 연구실

  15. LU Factorization of Tridiagonal Matrix • LU Factorization of a tridiagonal matrix T • less computation • less computer memory • 6.2.1 Matlab function for LU Factorization of • a Tridiagonal Matrix 분산시스템 연구실

  16. LU Factorization of Tridiagonal Matrix function [dd, bb] = LU_tridiag(a, d, b) % LU factorization of a tridiagonal matrix T % Input % a vector of elements above main diagonal, a(n) = 0 % d diagonal of matrix T % b vector of elements below main diagonal, b(1) = 0 % The factorization of T consists of % Lower bidiagonal matrix, % 1’s on main diagonal; lower diagonal is bb % Upper bidiagonal matrix, % main diagonal is dd; upper diagonal is a N = length(d) bb(1) = 0; dd(1) = d(1); for i = 2 : n bb(i) = b(i) / dd(i-1); dd(i) = d(i) – bb(i) * a(i-1); end 분산시스템 연구실

  17. LU Factorization of Tridiagonal MatrixExample 6.4 • Example 6.4 LU Factorization of Tridigonal System four-by-four tridigonal matrix Consider again the four-by-four tridigonal matrix from Example 3.7, , , , 분산시스템 연구실

  18. LU Factorization of Tridiagonal MatrixExample 6.4 • For i = 2, dd1 = d1 = 2, a1 = -1 • bb2 = b2/dd1 = -1/2 • dd2 = d2 – bb2a1 = 2-(-1/2)(-1) = 3/2 • For i = 3, a2 = -1 • bb3 = b3/dd2 = -1/(3/2) = -2/3 • dd3 = d3 - bb3a2 = 2-(-2/3)(-1) = 4/3 분산시스템 연구실

  19. LU Factorization of Tridiagonal MatrixExample 6.4 • For i = 4, a3 = -1 • bb4 = b4/dd2 = -1/(4/3) = -3/4 • dd4 = d4 - bb4a3 = 2-(-3/4)(-1) = 5/4 분산시스템 연구실

  20. 6.3 LU Factorization with pivoting 분산시스템 연구실

  21. 6.3.1 Why pivoting? 분산시스템 연구실

  22. 6.3.2 Theory for pivoting 1/2 • 한 쪽에 A행렬, 다른 한쪽에 I행렬을 놓는다. (A: LU 분해 할 NxN행렬, I: NxN 단위행렬) • A행렬을 가우스 소거법을 이용해 상삼각 행렬로 변환하면서 A행렬에 가하는 행렬 연산을 기록한다. (Nx: 소거, Px: 교환) 분산시스템 연구실

  23. 6.3.2 Theory for pivoting 2/2 • Nx 행렬을 좌측으로 빼면서 N’x로 변환한다. • 좌측 N’x들의 역행렬을 I행렬에 곱한다. 분산시스템 연구실

  24. 6.3.3 pivoting example 1/2 분산시스템 연구실

  25. 6.3.3 pivoting example 2/2 분산시스템 연구실

  26. 6.3.4 pivoting procedure 분산시스템 연구실

  27. 6.3.5 pivoting code Function [L, U, P] = LU_pivot(A) [n, n1] = size(A); L=eye(n); P=eye(n); U=A; For j = 1:n [pivot m] = max(abs(U(j:n, j))); m = m+j-1; if m ~= j % interchange rows m and j in U % interchange rows m and j in P if j >= 2 % interchange rows m and j in columns 1:j-1 of L end end for i = j+1:n L(i, j) = U(i, j) / U(j, j); U(i, :) = U(i, :) – L(i, j)*U(j, :); end end 분산시스템 연구실

  28. 6.4 Direct LU Factorization 분산시스템 연구실

  29. 6.4.1 Theory for Direct LU factorization 분산시스템 연구실

  30. 6.4.2 Type of Direct LU factorization • 조건의 수= N^2 변수의 수= N(N+1)/2 + N(N+1)/2 = N^2+N • Doolittle 방식 L의 대각 원소가 1 • Crout 방식 U의 대각 원소가 1 • Cholesky 방식 L과 U의 같은 위치 대각 원소끼리 같음 분산시스템 연구실

  31. 6.4.3 Doolittle example 분산시스템 연구실

  32. 6.4.4 Doolittle code Function [L, U] = Doolittle(A) [n, m] = size(A); U = zeros(n, m); L = eye(n); for k = 1:n U(k, k) = A(k, k) – L(k, 1:k-1)*U(1:k-1, k); for j = k+1:n U(k, j) = A(k, j) – L(k, 1:k-1)*U(1:k-1, j); L(j,k)= (A(j,k)– L(j, 1:k-1)*U(1:k-1, k))/U(k,k); end end 분산시스템 연구실

  33. 6.4.5 Cholesky example 분산시스템 연구실

  34. 6.4.6 Cholesky code Function [L, U] = Cholesky(A) % A is assumed to be symmetric. % L is computed, and U = L’ [n, m] = size(A); L = zeros(n, n); for k = 1:n L(k, k) = sqrt( A(k,k) – L(k, 1:k-1)*L(k, 1:k-1)’ ); for i = k+1:n L(i, k) = (A(i,k) – L(i, 1:k-1)*L(k, 1:k-1)’)/L(k, k); end end 분산시스템 연구실

  35. 6.5 Applications of LU Factorization 분산시스템 연구실

  36. Contents • 6.5 Applications of LU Factorization • Linear Equations • Tridiagonal System • Determinant of a Matrix • Inverse of a Matrix • 6.6 MATLAB’s Methods • lu, chol, det, inv 분산시스템 연구실

  37. 6.5.1 Solving Systems of Linear Equations • Ax = b → LUx = b → Ly = b • A = LU, Ux = y • Solve the system Ly = b for y • Forward substitution • y1 → y2 → …… yn • Solve the system Ux = y for x • Backward substitution • xn → xn-1 → …… x1 • If pivoting has been used • Ax=b → PAx=Pb, where PA=LU, Pb=c 분산시스템 연구실

  38. Ex 6.8 Solving Electrical Circuit for Several Voltages 분산시스템 연구실

  39. Ex 6.8 Solving Electrical Circuit for Several Voltages 분산시스템 연구실

  40. MATLAB Function to Solve the Linear System LUx=b function x = LU_Solve(L, U, b) % Function to solve the equation L U x = b % L --> Lower triangular matrix (with 1's on diagonal) % U --> Upper triangular matrix % b --> Right-hand side vector [n m] = size(L); z = zeros(n,1); x = zeros(n,1); % Solve L z = b using forward substitution z(1) = b(1); for i = 2:n z(i) = b(i) - L(i, 1:i-1) * z(1:i-1); end % Solve U x = z using back substitution x(n) = z(n) / U(n, n); for i = n-1 : -1 : 1 x(i) = (z(i) - U(i,i+1:n) * x(i+1:n)) / U(i, i); end 분산시스템 연구실

  41. 6.5.2 Solving a Tridiagonal System Ex 6.9 분산시스템 연구실

  42. MATLAB Function for Solving a Tridiagonal System function x = LU_tridiag_solve(a, d, b, r) % Function to solve the eqquation A x = r % LU factorization of A is expressed as % Lower bidiagonal matrix: % diagonal is 1s, lower diagonal is b; b(1) = 0. % Upper bidiagonal matrix: diagonal is d, upper diagonal is a % Right-hand-side vector is r % Solve L z = r using forward substitution n = length(d); z(1) = r(1); for i = 2:n z(i) = r(i) - b(i) * z(i-1); end % Solve U x = z using back substitution x(n) = z(n) / d(n); for i = n-1 : -1 : 1 x(i) = (z(i) - a(i) * x(i+1)) / d(i); end 분산시스템 연구실

  43. 6.5.3 Determinant of a Matrix Ex 6.10 분산시스템 연구실

  44. 6.5.4 Inverse of a Matrix • The inverse of an n-by-n matrix AAxi=ei(i=1, … ,n) • ei=[0 0 … 1 … 0 0]’, where the 1 appears in the ith position • X whose columns are the solution vectorsx1, … , xn is A-1 분산시스템 연구실

  45. Ex 6.11 Finding a Matrix Inverse Using LU Factorization 분산시스템 연구실

  46. Ex 6.11 Finding a Matrix Inverse Using LU Factorization 분산시스템 연구실

  47. MATLAB Function function x = LU_Solve_Gen(L, U, B) % Function to solve the equation L U x = B % L --> Lower triangular matrix (1's on diagonal) % U --> Upper triangular matrix % B --> Right-hand-side matrix [n n2] = size(L); [m1 m] = size(B); % Solve L z = B using forward substitution for j = 1:m z(1, j) = b(1, j); for i = 2 : n z(i,j) = B(i,j) - L(i, 1:i-1) * z(1:i-1, j); end end % Solve U x = z using back substitution for j = 1:m x(n, j) = z(n, j) / U(n, n); for i = n-1 : -1 : 1 x(i,j) = (z(i,j)-U(i,i+1:n)*x(i+1:n,j)) / U(i,i); end end 분산시스템 연구실

  48. 6.6 MATLAB’s Method 분산시스템 연구실

  49. 6.6 MATLAB’s Method • 4 built-in functions • LU decomposition of a square matrix A • [L, U] = lu(A), [L, U, P] = lu(A) • Cholesky factorization • chol • Determinant of a matrix • det • Inverse of a matrix • inv 분산시스템 연구실

More Related