Using LU Decomposition to Optimize the modconcen.m Routine Matt Tornowske April 1, 2002.

Slides:



Advertisements
Similar presentations
LU Factorization.
Advertisements

Chapter 4 Systems of Linear Equations; Matrices
4.3 Matrix Approach to Solving Linear Systems 1 Linear systems were solved using substitution and elimination in the two previous section. This section.
Chapter 4 Systems of Linear Equations; Matrices
Linear Algebra Applications in Matlab ME 303. Special Characters and Matlab Functions.
MATH 685/ CSI 700/ OR 682 Lecture Notes
Scientific Computing Linear Systems – Gaussian Elimination.
Chapter 8 Numerical Technique 大葉大學 資訊工程系 黃鈴玲 Linear Algebra.
LU Factorization LU-factorization Matrix factorization Forward substitution Back substitution.
Grayson Ishihara Math 480 April 15,  What is Partial Pivoting?  What is the PA=LU Factorization?  What kinds of things can we use these tools.
Chapter 9.1 = LU Decomposition MATH 264 Linear Algebra.
Inverses of n x n Matrices. The Inverse Matrix If A is an n x n matrix, the inverse of A (call it A -1 ) is the matrix such that A * A -1 is equal to.
1.2 Row Reduction and Echelon Forms
Solution of linear system of equations
Chapter 9 Gauss Elimination The Islamic University of Gaza
Chapter 2 Section 1 Solving a System of Linear Equations (using Matrices)
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 17 Solution of Systems of Equations.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion.
Table of Contents Solving Systems of Linear Equations - Gaussian Elimination The method of solving a linear system of equations by Gaussian Elimination.
Matrices Write and Augmented Matrix of a system of Linear Equations Write the system from the augmented matrix Solve Systems of Linear Equations using.
1 1.1 © 2012 Pearson Education, Inc. Linear Equations in Linear Algebra SYSTEMS OF LINEAR EQUATIONS.
Scientific Computing Linear Systems – LU Factorization.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Sec 3.1 Introduction to Linear System Sec 3.2 Matrices and Gaussian Elemination The graph is a line in xy-plane The graph is a line in xyz-plane.
MA2213 Lecture 5 Linear Equations (Direct Solvers)
MATH 250 Linear Equations and Matrices
G AUSSIAN E LIMINATION Presented by: Max Le Max Le Justin Lavorgna Data Structures II: Algorithm Design & Analysis Algorithm Design & Analysis.
Numerical Computation Lecture 7: Finding Inverses: Gauss-Jordan United International College.
Sec 3.2 Matrices and Gaussian Elemination Coefficient Matrix 3 x 3 Coefficient Matrix 3 x 3 Augmented Coefficient Matrix 3 x 4 Augmented Coefficient Matrix.
Section 2.2 Echelon Forms Goal: Develop systematic methods for the method of elimination that uses matrices for the solution of linear systems. The methods.
MA/CS 375 Fall MA/CS 375 Fall 2003 Lecture 19.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 21.
Lecture 8 Matrix Inverse and LU Decomposition
Matrices and Systems of Equations
Hello Mr. Anderson… We’ve been waiting for you.. Hello Mr. Anderson… We’ve been waiting for you.
Matrices and Systems of Equations
Meeting 19 System of Linear Equations. Linear Equations A solution of a linear equation in n variables is a sequence of n real numbers s 1, s 2,..., s.
Chapter 9 Gauss Elimination The Islamic University of Gaza
1 Section 5.3 Linear Systems of Equations. 2 THREE EQUATIONS WITH THREE VARIABLES Consider the linear system of three equations below with three unknowns.
ECE 530 – Analysis Techniques for Large-Scale Electrical Systems Prof. Hao Zhu Dept. of Electrical and Computer Engineering University of Illinois at Urbana-Champaign.
7.3 & 7.4 – MATRICES AND SYSTEMS OF EQUATIONS. I N THIS SECTION, YOU WILL LEARN TO  Write a matrix and identify its order  Perform elementary row operations.
1 Chapter 7 Numerical Methods for the Solution of Systems of Equations.
Copyright ©2015 Pearson Education, Inc. All rights reserved.
Linear Systems Dinesh A.
2 2.5 © 2016 Pearson Education, Ltd. Matrix Algebra MATRIX FACTORIZATIONS.
Unit #1 Linear Systems Fall Dr. Jehad Al Dallal.
Numerical Methods.  LU Decomposition is another method to solve a set of simultaneous linear equations  For most non-singular matrix [A] that one could.
Numerical Computation Lecture 6: Linear Systems – part II United International College.
LU Decomposition ● In Gauss elimination; Forward elimination Backward substitution Major computational effort Low computational effort can be used for.
College Algebra Chapter 6 Matrices and Determinants and Applications
Multivariable Linear Systems and Row Operations
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Chapter: 3c System of Linear Equations
Systems of linear equations
Chapter 8 Numerical Technique
Spring Dr. Jehad Al Dallal
Linear Equations.
Chapter 8: Lesson 8.1 Matrices & Systems of Equations
Linear Algebra Lecture 15.
MA/CS 375 Spring 2002 Lecture 19 MA/CS 375 Fall 2002.
RECORD. RECORD Gaussian Elimination: derived system back-substitution.
Larger Systems of Linear Equations and Matrices
Lial/Hungerford/Holcomb/Mullins: Mathematics with Applications 11e Finite Mathematics with Applications 11e Copyright ©2015 Pearson Education, Inc. All.
Implementing our backward order final equation
Numerical Computation and Optimization
RECORD. RECORD COLLABORATE: Discuss: Is the statement below correct? Try a 2x2 example.
Numerical Analysis Lecture10.
Lecture 8 Matrix Inverse and LU Decomposition
Ax = b Methods for Solution of the System of Equations (ReCap):
Presentation transcript:

Using LU Decomposition to Optimize the modconcen.m Routine Matt Tornowske April 1, 2002

Review of Gaussian Elimination Find the augmented matrix of the system of linear equations. Find an echelon form of the augmented matrix using elementary row operations. Find the system of equations corresponding to the echelon form. Use back substitution to arrive at the solution.

Example using Gaussian Elimination Solve the following system of linear equations using the method of Gaussian Elimination: Starting with the augmented matrix create zeros below the pivot in the first column:

Gaussian Elimination : Echelon Form At this stage we create a zero only below the pivot: The corresponding system of equations is:

Gaussian Elimination : Back Substitution We now solve the system using back substitution. Since we have x 4 = 2 we substitute this into the row above: Substituting x 4 = 2 and x 3 = -5 into the first equation: And we’re left with:

Computational Cost of Gaussian Elimination for an n x n Matrix For multiplication: For addition: Total operations: For 1532 x 1532 matrix:

Method of LU Decomposition Find the LU decomposition of the matrix Solve LY=B using forward substitution Solve UX=Y by back substitution Hopefully, we save computational time

Finding the LU Factors The LU Factorization is done by finding the Upper and Lower triangle matrices of an original matrix. The upper matrix, U, is the reduced echelon form of the original matrix, A. The lower matrix, L, is the inverse of the elementary matrices obtained from the operations to obtain U.

LU decomposition: Getting U Solve the following system of equations using LU decomposition: First reduce the associated matrix into upper triangular form:

LU Decomposition: Elementary Matrices The elementary matrices that correspond to these row operations are: The inverses of these matrices are:

LU Decomposition: Getting L Thus,

LU Decomposition: Solving LUX = B We now solve the given system LUX = B by solving the two subsystems LY = B and UX = Y: This lower triangular system has solution y 1 = -1, y 2 = 7, y 3 = 2. The solution to the upper triangular system is x 1 = 5, x 2 = -8, x 3 = -1, which happens to be the solution to A.

Computational Cost of LU Decomposition for an n x n Matrix Total number of arithmetic operations to solve a system of equations using LU decomposition is exactly the same as Gaussian Elimination. The method is the most efficient method available for solving many systems all having the same matrix of coefficients, when the right hand sides are not all available in advance. Since the factorization only has to be done once, it uses (4n 3 – 3n 2 – n)/6 operations. The solutions of the two triangular systems can be carried out in 2n 2 – n operations compared to (4n 3 + 9n 2 – 7n)/6 operations for full Gaussian elimination each time. Ideally, for 1528 x 1528 matrix, this is a savings of nearly 99.8% per system!

Permutation Matrix Our LU decomposition won’t work properly if there are any pivots needed We can use the lu() function in Matlab to create a permutation matrix P to keep track of these pivots We’ll simply change the algorithm slightly to solve LY=PB instead of LY=B

Implementation in Matlab We use the Matlab lu() function to give us our L, U, and P matrices We will adjust the code in Jennifer’s modified concentration routine to use LU factorization.

Modified Concentration Routine with LU Implemented % do the LU factorization here. [L,U,P]=lu(w); clear w; for m=1:ntimes m rhs = zeros(1528,1); for k = 1:1528 N = nb(k,find((nbor(k,:) == 1))); W = nb(k,find((nbor(k,:) == 3))); S = nb(k,find((nbor(k,:) == 5))); E = nb(k,find((nbor(k,:) == 7))); if(~isempty(N) & ~isempty(W) & ~isempty(S) & ~isempty(E)) In the last outer for block (modifications in red):

Modified Routine, continued ux = scaledvelocity(k,1); uy = scaledvelocity(k,2); rhs(k,1) = -concentration(k,m)/deltat; else rhs(k,1) = 0; end %xjen=w\rhs; replace this line with %backward/forward substitution rhs=P*rhs; xjen2=L\rhs; xjen2=U\xjen2;

Modified Routine, continued concentration(:,m+1)=xjen2; end Note: We use the left matrix divide instead of inverse operation. While some improvement can Be gained by performing some inversions outside of the for loop, the increase in speed can be far offset in the larger memory requirements.

Performance Gains on Pentium Mhz with 384 MB of RAM With deltat=0.5, old routine took 73 seconds while the new routine took 11 seconds Adjusting deltat for 0.25, old = 145 seconds, new = 17 seconds Deltat for.1, old = 350 seconds, new = 38 seconds

Conclusions Depending on the timestep, we’ve created a speedup of 7-9 times the original routine Use LU decomposition, all the cool people do!