1 Systems of Linear Equations Gauss-Jordan Elimination and LU Decomposition.

Slides:



Advertisements
Similar presentations
Algebraic, transcendental (i.e., involving trigonometric and exponential functions), ordinary differential equations, or partial differential equations...
Advertisements

MATH 685/ CSI 700/ OR 682 Lecture Notes
Scientific Computing Linear Systems – Gaussian Elimination.
Numerical Analysis – Linear Equations(I) Hanyang University Jong-Il Park.
Simultaneous Linear Equations
LU Factorization LU-factorization Matrix factorization Forward substitution Back substitution.
Systems of Linear Equations
SOLVING SYSTEMS OF LINEAR EQUATIONS. Overview A matrix consists of a rectangular array of elements represented by a single symbol (example: [A]). An individual.
Lecture 9: Introduction to Matrix Inversion Gaussian Elimination Sections 2.4, 2.5, 2.6 Sections 2.2.3, 2.3.
Numerical Algorithms Matrix multiplication
Chapter 9.1 = LU Decomposition MATH 264 Linear Algebra.
Part 3 Chapter 9 Gauss Elimination
Solution of linear system of equations
Chapter 9 Gauss Elimination The Islamic University of Gaza
Major: All Engineering Majors Author(s): Autar Kaw
Linear Algebraic Equations
1 Systems of Linear Equations Iterative Methods. 2 B. Iterative Methods 1.Jacobi method and Gauss Seidel 2.Relaxation method for iterative methods.
1 Systems of Linear Equations Iterative Methods. 2 B. Direct Methods 1.Jacobi method and Gauss Seidel 2.Relaxation method for iterative methods.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 17 Solution of Systems of Equations.
1 Systems of Linear Equations Error Analysis and System Condition.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 15 Solution of Systems of Equations.
ECIV 520 Structural Analysis II Review of Matrix Algebra.
Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1 for all eq.s k greater than j a) multiply eq. j by a kj /a jj b) subtract.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 10 LU Decomposition and Matrix.
Systems of Linear Equations
1 Systems of Linear Equations Error Analysis and System Condition.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Part 31 Chapter.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Linear Algebraic Equations ~ Gauss Elimination Chapter.
Major: All Engineering Majors Author(s): Autar Kaw
LU Decomposition 1. Introduction Another way of solving a system of equations is by using a factorization technique for matrices called LU decomposition.
Scientific Computing Linear Systems – LU Factorization.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Part 31 Linear.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Using LU Decomposition to Optimize the modconcen.m Routine Matt Tornowske April 1, 2002.
ΑΡΙΘΜΗΤΙΚΕΣ ΜΕΘΟΔΟΙ ΜΟΝΤΕΛΟΠΟΙΗΣΗΣ 4. Αριθμητική Επίλυση Συστημάτων Γραμμικών Εξισώσεων Gaussian elimination Gauss - Jordan 1.
Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.
Chemical Engineering Majors Author(s): Autar Kaw
EE616 Dr. Janusz Starzyk Computer Aided Analysis of Electronic Circuits Innovations in numerical techniques had profound import on CAD: –Sparse matrix.
Lecture 8 Matrix Inverse and LU Decomposition
Lecture 7 - Systems of Equations CVEN 302 June 17, 2002.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 9 Linear Systems of Equations: Gauss Elimination.
Gaussian Elimination Electrical Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for.
Chapter 9 Gauss Elimination The Islamic University of Gaza
Gaussian Elimination Industrial Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for.
Gaussian Elimination Mechanical Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for.
Linear Systems Dinesh A.
Part 3 Chapter 9 Gauss Elimination PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill Companies,
Gaussian Elimination Civil Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for STEM.
Unit #1 Linear Systems Fall Dr. Jehad Al Dallal.
Autar Kaw Benjamin Rigsby Transforming Numerical Methods Education for STEM Undergraduates.
Numerical Methods.  LU Decomposition is another method to solve a set of simultaneous linear equations  For most non-singular matrix [A] that one could.
Lecture 9 Numerical Analysis. Solution of Linear System of Equations Chapter 3.
Numerical Computation Lecture 6: Linear Systems – part II United International College.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 9.
Pitfalls of Gauss Elimination ● Division by zero (avoid by pivoting) ● Round-off errors – Important with >100 eqns – Substitute answer into original eqn.
LU Decomposition ● In Gauss elimination; Forward elimination Backward substitution Major computational effort Low computational effort can be used for.
Spring Dr. Jehad Al Dallal
Gaussian Elimination.
Gauss-Siedel Method.
Linear Equations.
Chapter 10: Solving Linear Systems of Equations
Metode Eliminasi Pertemuan – 4, 5, 6 Mata Kuliah : Analisis Numerik
Numerical Analysis Lecture14.
Numerical Computation and Optimization
Numerical Analysis Lecture10.
Lecture 8 Matrix Inverse and LU Decomposition
Linear Systems of Equations: solution and applications
The Gauss Jordan method
Ax = b Methods for Solution of the System of Equations (ReCap):
Presentation transcript:

1 Systems of Linear Equations Gauss-Jordan Elimination and LU Decomposition

2 Direct Methods 1.Gauss Elimination a.Naïve Gauss Eliminiation b.Pivoting Strategies c.Scaling 2.Gauss-Jordan Elimination 3.LU Decomposition

3 Gauss-Jordan Elimination Similar to the Gauss elimination except 1.Elimination is applied to all equations (excluding the pivot equation) instead of just the subsequent equations. 2.All rows are normalized by dividing them by their pivot elements. 3.No back substitution is required.

4 Pitfalls and Improvements Pitfalls: Same as those found in the Gauss elimination. –Division-by-zero, round-off error, and ill- conditioned systems. Improvement strategies: Same as those used in the Gauss elimination –Use pivoting and scaling to avoid division-by- zero and to reduce round-off error.

5 Computing Cost Which of Gauss elimination and Gauss-Jordan elimination involves more FLOPS? Gauss EliminationGauss-Jordan Elimination Elimination Step Forward Elimination – only needs to eliminate the coefficients below the diagonal. Cost ~ 2n 3 /3 Needs to eliminate coefficients below and above the diagonal. Cost ~ 2 * (2n 3 /3) Substitution Step Back Substitution Cost ~ O(n 2 ) No substitution step Total 2n 3 /3 + O(n 2 )4n 3 /3 (More costly when n is big)

6 Question What is?

7 Computing Matrix Inverse Gauss-Jordan Gauss Elimination Solve Let

8 Summary Algorithms –Gauss elimination Forward elimination + back substitution –Gauss-Jordan elimination Calculate the computing cost of Gauss Elimination in terms of FLOPS To avoid division-by-zero, use pivoting (partial or complete). To reduce round-off error, use pivoting and scaling. If a system is ill-conditioned, then substituting solution back to the system to check if the solution is accurate is not reliable. –How to determine if a matrix is ill-conditioned?

9 Direct Methods 1.Gauss Elimination a.Naïve Gauss Eliminiation b.Pivoting Strategies c.Scaling 2.Gauss-Jordan Elimination 3.LU Decomposition

10 3x 1 + 2x 2 + x 3 = 6 2x 2 + 3x 3 = 7 2x 3 = 4 Step 1: Solve for x 3 2x 3 = 4 => x 3 = 4/2 = 2 Step 2: Solve for x 2 2x 2 + 3(2) = 7 =>x 2 = [7 – 3(2)] / 2 = 0.5 Step 3: Solve for x 1 3x 1 + 2(0.5) + (2) = 6 =>x 1 = [6 – 2(0.5) – 2] / 3 = 1 Use to solve the system Ux = b where U is an upper triangular matrix. Back Substitution Example:

11 2x 1 = 4 3x 1 + 2x 2 = 7 x 1 + 2x 2 + 3x 3 = 6 Step 1: Solve for x 1 2x 1 = 4 => x 1 = 4/2 = 2 Step 2: Solve for x 2 3(2) + 2x 2 = 7 =>x 2 = [7 – 3(2)] / 2 = 0.5 Step 3: Solve for x 3 (2) + 2(0.5) + 3x 3 = 6  x 3 = [6 – 2 – 2(0.5)] / 3 = 1 Use to solve the system Lx = b where L is a lower triangular matrix. Forward Substitution Example:

12 LU Decomposition Idea: To solve Ax = b Step 1: Decompose A into L and U such that A = LU where We will discuss later how to compute L and U when given A. For now, let's assume we can! Step 2: Solve LUx = b using forward and back substitution.

13 Solving LUx = b

14 Decomposing A using Gauss Elimination U is formed by applying the forward elimination of Gauss Elimination (without including the right hand side vector) L is formed by the factors used to eliminate each elements during the forward elimination process as

15 Decomposing A into L and U -- Example 1 st iteration (1 st column), eliminating a 21 1 st iteration (1 st column), eliminating a 22

16 Decomposing A into L and U -- Example 2 st iteration (2 st column), eliminating a 32 Thus we can express A as LU where Due to round-off error

17 LU Decomposition In LU decomposition, the l and u values are obtained from Note: These are just mathematical expressions representing the steps involved in Gauss Elimination.

18 Compact Representation For U, the lower part are all 0's. For L, the diagonal elements are all 1's and the upper part are all 0's. When implementing the algorithm, we can store both U and L back into A.

19 Forward and Back Substitution To solve Ly = b, we use forward substitution To solve Ux = y, we use back substitution Note: Here the a ij represents the coefficients of the resulting matrix A produced by the LU Decomposition algorithm.

20 Effect of Pivoting If we directly apply Gauss elimination algorithm (with pivoting), we will need to swap row 3 with row 1 and eventually yield L and U as Let Pivot row in 1 st iteration

21 Effect of Pivoting If we are given a vector b, can we solve Ax = b as LUx = b ? No! We can't because we have swapped the rows during the elimination step. In implementing the LU decomposition, we have to remember how the rows were swapped so that we can reorder the elements in x and b accordingly.

22 Addressing the issue of row swapping in implementation i o[i] To remember how the rows were swapped, we can introduce an array, o[], to store the indexes to the rows. Initially, o[i] = i for i = 1, 2, …, N. Whenever we need to swap rows, we only swap the indexes stored in o[]. For example, after swapping row 1 with row 3 i o[i]

23 Addressing the issue of row swapping in implementation If rows were swapped, A ≠A'. However, o[i] tells us that row i in A corresponds row o[i] in A'. To solve Ax = b, we can first reorder the elements in x and b to produce x' and b' as x' i = x o[ i ] and b' i = b o[ i ] and then solve A'x' = b' as L'U'x' = b'. Note: In actual implementation, we do not need to explicitly create x' and b'. We can refer to their elements directly as x o[ i ] and b o[ i ]. A L' U' A' LU Decomposition with pivoting =

24 Illustration: Using o[] i o[i] Array A i o[i] Array A After swapping row 3 with row 1 Initial states. Pick row 3 as pivot row i o[i] Array A f 31 is calculated as A[o[3],1] / A[o[1],1] and the result is stored back to A[o[3],1]. After the 1 st iteration. Implementation

25 Pseudocode for LU Decomposition // Assume arrays start with index 1 instead of 0. // a: Coef. of matrix A; 2-D array. Upon successful // completion, it contains the coefficients of // both L and U. // b: Coef. of vector b; 1-D array // n: Dimension of the system of equations // x: Coef. of vector x (to store the solution) // tol: Tolerance; smallest possible scaled // pivot allowed. // er: Pass back -1 if matrix is singular. // (Reference var.) LUDecomp(a, b, n, x, tol, er) { Declare s[n] // A n n-element array for storing scaling factors Declare o[n] // Use as indexes to pivot rows. // o i or o(i) stores row number of the i th pivot row. er = 0 Decompose(a, n, tol, o, s, er) if (er != -1) Substitute(a, o, n, b, x) }

26 Pseudocode for decomposing A into L and U Decompose(a, n, tol, o, s, er) { for i = 1 to n { // Find scaling factors o[i] = i s[i] = abs(a[i,1]) for j = 2 to n if (abs(a[i,j]) > s[i]) s[i] = abs(a[i,j]) } for k = 1 to n-1 { Pivot(a, o, s, n, k) // Locate the k th pivot row // Check for singular or near-singular cases if (abs(a[o[k],k]) / s[o[k]]) < tol) { er = -1 return } // Continue next page

27 for i = k+1 to n { factor = a[o[i],k] / a[o[k],k] // Instead of storing the factors // in another matrix (2D array) L, // We reuse the space in A to store // the coefficients of L. a[o[i],k] = factor // Eliminate the coefficients at column j // in the subsequent rows for j = k+1 to n a[o[i],j] = a[o[i],j] – factor * a[o[k],j] } } // end of "for k" loop from previous page // Check for singular or near-singular cases if (abs(a[o[n],n]) / s[o[n]]) < tol) er = -1 }

28 Psuedocode for finding the pivot row Pivot(a, o, s, n, k) { // Find the largest scaled coefficient in column k p = k // p is the index to the pivot row big = abs(a[o[k],k]) / s[o[k]]) for i = k+1 to n { dummy = abs(a[o[i],k] / s[o(i)]) if (dummy > big) { big = dummy p = i } // Swap row k with the pivot row by swapping the // indexes. The actual rows remain unchanged dummy = o[p] o[p] = o[k] o[k] = dummy }

29 Psuedocode for solving LUx = b Substitute(a, o, n, b, x) { Declare y[n] y[o[1]] = b[o[1]] for i = 2 to n { sum = b[o[i]] for j = 1 to i-1 sum = sum – a[o[i],j] * b[o[j]] y[o[i]] = sum } x[n] = y[o[n]] / a[o[n],n] for i = n-1 downto 1 { sum = 0 for j = i+1 to n sum = sum + a[o[i],j] * x[j] x[i] = (y[o[i]] – sum) / a[o[i],i] } Forward substitution Back substitution

30 About the LU Decomposition Pseudocode If the LU decomposition algorithm is to be used to solve Ax = b for various b 's, then both array " a " and array " o " have to be saved. Subroutine substitute() can be applied repeatedly for various b 's. In subroutine substitute(), we can also reuse the space in " b " to store the elements of " y " instead of declaring the new array " y ".

31 Question What is the cost to decompose A into L and U ?

32 LU Decomposition vs. Gauss Elimination To solve Ax = b i, i = 1, 2, 3, …, K LU Decomposition Compute L and U once – O(n 3 ) Forward and back substitution – O(n 2 ) Total cost = O(n 3 ) + K * O(n 2 ) Gauss Elimination Total cost: K * O(n 3 )

33 Computing Matrix Inverse Solve Let First, decompose A into L and U, then

34 Pseudocode for finding matrix inverse using LU Decomposition // a: Given matrix A; 2-D array. // ai: Stores the coefficients of A -1 // n: Dimension of A // tol: Smallest possible scaled pivot allowed. // er: Pass back -1 if matrix is singular. LU_MatrixInverse(a, ai, n, tol, er) { Declare s[n], o[n], b[n], x[n] Decompose(a, n, tol, o, s, er) if (er != -1) { for i = 1 to n { for j = 1 to n // Construct the unit vector b[j] = 0 b[i] = 1 Substitute(a, o, n, b, x) for j = 1 to n ai[j,i] = x[j] }

35 Two types of LU decomposition Doolittle Decomposition or factorization Crout Decomposition

36 Crout Decomposition

37 Summary LU Decomposition Algorithm LU Decomposition vs. Gauss Elimination –Similarity –Advantages (Disadvantages?) –Computing Cost