You are on page 1of 10

Because learning changes everything.

Part Three
Chapter 10
LU Factorization

PowerPoint slides prepared by


Steven C. Chapra, Tufts University
David E. Clough, University of Colorado

© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
Chapter Objectives
• Understanding that LU factorization involves decomposing
the coefficient matrix into two triangular matrices that can
then be used to efficiently evaluate different right-hand-side
vectors.
• Knowing how to express Gauss elimination as an LU
factorization.
• Given an LU factorization, knowing how to evaluate multiple
right-hand-side vectors.
• Recognizing that Cholesky’s method provides an efficient
way to decompose a symmetric matrix and that the resulting
triangular matrix and its transpose can be used to evaluate
right-hand-side vectors efficiently.
• Understanding in general terms what happens when the
linalg.solve function from Python’s NumPy module is
used to solve a set of linear algebraic equations.
© McGraw Hill LLC 2
LU Factorization - 1
Recall that the forward-elimination step of Gauss elimination
comprises the bulk of the computational effort.
LU factorization methods separate the time-consuming
elimination of the matrix A from the manipulations of the
right-hand-side b.
Once A has been factored (or decomposed), multiple right-
hand-side vectors can be evaluated in an efficient manner.

© McGraw Hill LLC 3


LU Factorization - 2
LU factorization involves two
steps:
• Factorization to decompose the
A matrix into a product of a
lower triangular matrix L and an
upper triangular matrix U.
L has 1 for each entry on the
diagonal.
• Substitution to solve for x.
Gauss elimination can be
implemented using LU
factorization

Access the text alternative for slide images.

© McGraw Hill LLC 4


Gauss Elimination as LU Factorization - 1
A·x = b can be rewritten as L·U·x = b using LU factorization.
The LU factorization algorithm requires the same total flops as
for Gauss elimination.
The main advantage is once A is decomposed, the same L
and U can be used for multiple b vectors.
The lu function from the Python SciPy linalg submodule
can be used to generate the L, U matrices and a permutation
matrix, P:
from scipy.linalg import lu
P,L,U = lu(A)

The permutation matrix is arranged in columns to show the


row swaps. This function uses partial pivoting to avoid
division by zero and the P matrix indicates the rows that were
swapped.
© McGraw Hill LLC 5
Gauss Elimination as LU Factorization - 2
To solve A·x = b , first decompose A to get L·U·x = b .
Set up and solve L·d = b , where d can be found using forward
substitution.
Set up and solve U·x = d , where x can be found using backward
substitution.
Python code:
import scipy as sc
P,L,U = sc.linalg.lu(A)
d = np.linalg.solve(L,b)
x = np.linalg.solve(U,d)

© McGraw Hill LLC 6


Gauss Elimination as LU Factorization - 3
Example  3 0.1 0.2   x1   7.85 
 0.1 7 0 .3    x    19.3
   2  
0.3 0.2 10   x3   71.4 

import scipy as sc
import numpy as np
A = np.matrix(' 3 -0.1 -0.2 ; 0.1 7 -0.3 ; 0.3 -0.2 10 ')
b = np.matrix(' 7.85 ; -19.3 ; 71.4 ‘)
P,L,U = sc.linalg.lu(A)
d = np.linalg.solve(L,b)
x = np.linalg.solve(U,d)
print(x)

[[ 3. ]
[-2.5]
[ 7. ]]

© McGraw Hill LLC 7


Cholesky Factorization - 1
Symmetric systems occur commonly in both mathematical
and engineering/science problem contexts, and there are
special solution techniques available for such systems.
The Cholesky factorization is one of the most popular of
these techniques, and is based on the fact that a symmetric
T
matrix can be decomposed as A = U ·U , where T stands for
transpose.
The rest of the process is similar to LU decomposition and
Gauss elimination, except only one matrix, U, needs to be
stored.

© McGraw Hill LLC 8


Cholesky Factorization - 2
Python’s SciPy’s linalg submodule has a Cholesky
function that performs the factorization:
from scipy.linalg import cholesky
U = sc.linalg.cholesky(A)

Example
import numpy as np
from scipy.linalg import cholesky

A = np.matrix(' 6 15 55 ; 15 55 225 ; 55 225 979')

U = cholesky(A)
print(U)

[[ 2.44948974 6.12372436 22.45365598]


[ 0. 4.18330013 20.91650066]
[ 0. 0. 6.11010093]]

© McGraw Hill LLC 9


End of Main Content

Because learning changes everything. ®

www.mheducation.com

© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.

You might also like