LU Decomposition
INGE4035 Numerical Methods Applied to Engineering
- Dr. Marco A Arocha
October 2, 2014
LU Decomposition INGE4035 Numerical Methods Applied to Engineering - - PowerPoint PPT Presentation
LU Decomposition INGE4035 Numerical Methods Applied to Engineering Dr. Marco A Arocha October 2, 2014 Motivation The motivation for an LU decomposition is based on the observation that systems of equations involving triangular coefficient
INGE4035 Numerical Methods Applied to Engineering
October 2, 2014
that systems of equations involving triangular coefficient matrices are easier to deal with.
coefficient matrix with one that is triangular.
triangular systems.
A = LU
unique.
A = LU
an LU decomposition of A.
matrix and an upper triangular matrix that is equal to A. Off course the multiplication process follows the rules of linear algebra.
L = 1 π¦ 1 π¦ π¦ 1 π¦ π¦ π¦ 1 x= any number; oneβs in diagonal
U = 1 π¦ π¦ π¦ 1 π¦ π¦ 1 π¦ 1 x= any number; oneβs in diagonal
diagonal elements are equal
where π = π11 π21 π22 π31 π32 π33 π = 1 π12 π13 1 π23 1
Matrix multiplication is reviewed at the end of the presentation Multiplying out LU and setting the answer equal to A gives
π11 π11π12 π11π13 π21 π21π12 + π22 π21π13 + π22π23 π31 π31π12 + π32 π31π13 + π32π23 + π33 = 1 2 4 3 8 14 2 6 13
π11 π11π12 π11π13 π21 π21π12 + π22 π21π13 + π22π23 π31 π31π12 + π32 π31π13 + π32π23 + π33 = 1 2 4 3 8 14 2 6 13
We begin by running along the first column: π11 = 1; π21 = 3; π31 = 2 For the second column: π11π12 = 2, then π12 = 2 π21π12 + π22 = 8 then π22 = 2 π31π12 + π32 = 6 then π32 = 2 For the third column: π11π13 = 4, then π13 = 4 π21π13 + π22π23 = 14 then π23 = 1 π31π13 + π32π23 + π33 = 13 then π33 = 3
where π = 1 3 2 2 2 3 π = 1 2 4 1 1 1
Matrix multiplication is reviewed at the end of the presentation
Example (Doolittle)
% Crout LU Decomposition clc, clear A=[1,2,4; 3,8,14;2,6,13] [L, U] = CroutLU(A) function [L, U] = CroutLU(A) [R, C] = size(A); for i = 1:R L(i, 1) = A(i, 1); U(i, i) = 1; end for j = 2:R U(1, j) = A(1, j) / L(1, 1); end for i = 2:R
for j = 2:i L(i, j) = A(i, j) - L(i, 1:j - 1) * U(1:j - 1, j); end for j = i - 1:R U(i, j) = (A(i, j) - L(i, 1:i - 1) * U(1:i - 1, j)) / L(i, i); end
end end https://rosettacode.org/wiki/LU_decomposition#Creating_a_MATLAB_function
% LU Decomposition % lu is a library matlab function clc, clear A=[1,2,4; 3,8,14;2,6,13] [L,U]=lu(A) A = 1 2 4 3 8 14 2 6 13 L = 0.3333 -1.0000 1.0000 1.0000 0 0 0.6667 1.0000 0 U = 3.0000 8.0000 14.0000 0.6667 3.6667 0 0 3.0000
not a triangular matrix
parts it is possible to obtain the solution to AX = B in a direct way.
coefficient matrix: right-hand side vector:
Crout
The steps in finding the solution vector with LU Decomposition
Expressing each equation and solving for {D}, i.e., d1, d2 and d3: 1d1=15 2d1-2d2+0d3=22 3d1-5d2+3.5d3=39
1d1=15 2d1-2d2+0d3=22 3d1-5d2+3.5d3=39
which produces π1=15, π2=4, and π3=4 πΈ = π1 π2 π3 = 15 4 4
πΈ = π1 π2 π3 = 15 4 4
Third step: π π = πΈ 1 3 2 1 0.5 1 π¦1 π¦2 π¦3 = 15 4 4
π π = πΈ 1 3 2 1 0.5 1 π¦1 π¦2 π¦3 = 15 4 4
1π¦3 = 4 1π¦2 + 0.5π¦3 = 4 1π¦1 + 3π¦2 + 2π¦3 = 15 which produces π¦3 = 4, π¦2 = 2 , π¦1 = 1 π = π¦1 π¦2 π¦3 = 1 2 4
% Linear System Solution with LU % Decomposition with CroutLU function clc, clear A=[1,3,2; 2,4,3;3,4,7] B=[15;22;39] [L,U] = CroutLU(A) D = L\B X = U\D A = 1 3 2 2 4 3 3 4 7 B = 15 22 39 L = 1.0000 0 2.0000 -2.0000 0 3.0000 -5.0000 3.5000 U = 1.0000 3.0000 2.0000 1.0000 0.5000 0 0 1.0000 D = 15 4 4 X = 1 2 4
% Linear System Solution with LU % Decomposition with lu matlab % function
A=[1,3,2; 2,4,3;3,4,7] B=[15;22;39] [L,U] = lu(A) D = L\B X = U\D A = 1 3 2 2 4 3 3 4 7 B = 15 22 39 L = 0.3333 1.0000 0 0.6667 0.8000 1.0000 1.0000 0 U = 3.0000 4.0000 7.0000 1.6667 -0.3333 0 0
D = 39.0000 2.0000
X = 1.0000 2.0000 4.0000
products of each row in A with each column in B
becomes an element with row equal to A and column equal to B in the resulting matrix
ο½
ο½ ο½
m k kj ik ij
b a c AB
1
34
A B A*B
No commutative: ABβ BA
Math Syntax: AB MATLAB Syntax: A*B (NO DOT)
>> A=[1 3 5; 2 4 6] A = 1 3 5 2 4 6
35
Sample calculation: The dot product of row-1 of A and column-1 of B: (1*-2)+(3*3)+(5*12)=67
>> A*B ans = 67 18 80 28 >> B=[-2 4; 3 8; 12 -2] B =
3 8 12 -2
Math Syntax: AB MATLAB Syntax: A*B %(NO DOT)
>> A=[1 3 5; 2 4 6] A = 1 3 5 2 4 6
36
Sample calculation: The dot product of row-1 of A and column-1 of B: (1*-2)+(3*3)+(5*12)=67
>> matriX(A,B) ans = 67 18 80 28 >> B=[-2 4; 3 8; 12 -2] B =
3 8 12 -2