0% found this document useful (0 votes)
21 views15 pages

Lecture 7

This document discusses LU decomposition and matrix inversion, explaining that LU decomposition provides an efficient way to compute matrix inverses by separating the computationally intensive Gaussian elimination step from manipulating the right-hand side vector, and that it works by decomposing a matrix A into lower and upper triangular matrices L and U such that A = LU, which can then be used to solve systems of equations. The document also provides MATLAB code for Gaussian elimination.

Uploaded by

haqeemifarhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views15 pages

Lecture 7

This document discusses LU decomposition and matrix inversion, explaining that LU decomposition provides an efficient way to compute matrix inverses by separating the computationally intensive Gaussian elimination step from manipulating the right-hand side vector, and that it works by decomposing a matrix A into lower and upper triangular matrices L and U such that A = LU, which can then be used to solve systems of equations. The document also provides MATLAB code for Gaussian elimination.

Uploaded by

haqeemifarhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

KIL1005: NUMERICAL METHODS FOR ENGINEERING

SEMESTER 2, SESSION 2022/2023

LECTURE 7: LU DECOMPOSITION AND


MATRIX INVERSION

DR MAHAR DIANA HAMID


DEPARTMENT OF CHEMICAL ENGINEERING
LU DECOMPOSITION AND MATRIX INVERSION
• Provides an efficient way to compute matrix inverse by separating the time
consuming elimination of the Matrix [A] from manipulations of the right-
hand side {B}.
• Gauss elimination, in which the forward elimination comprises the bulk of
the computational effort, can be implemented as an LU decomposition.

2
If
L- lower triangular matrix
U- upper triangular matrix
Then,
[A]{X}={B} can be decomposed into two matrices [L] and [U] such that
[L][U]=[A]
[L][U]{X}={B}
Similar to first phase of Gauss elimination, consider
[U]{X}={D}
[L]{D}={B}
• [L]{D}={B} is used to generate an intermediate vector {D} by forward substitution
• Then, [U]{X}={D} is used to get {X} by back substitution.

3
4
5
Fig.10.1

6
LU decomposition
• requires the same total FLOPS (floating point operations per
second) as for Gauss elimination.
• Saves computing time by separating time-consuming elimination
step from the manipulations of the right hand side.
• Provides efficient means to compute the matrix inverse

• Note: In computing, floating point operations per


second(FLOPS, flops or flop/s) is a measure of computer
performance, useful in fields of scientific computations that
require floating-point calculations. For such cases it is a more
accurate measure than measuring instructions per second.

7
8
9
10
MATLAB CODE FOR GAUSS ELIMINATION
Initialization and input descriptions

clc

close all

disp('Gauss Elmination method to solve "n" equations for in the format of:
"[A][x]=[b]" ');

A=input ('Enter the coefficients in the equations in matrix form i.e. Input
[A] matrix: ');

b=input ('Enter the right hand side column vector [b]: ');

n=length(b);

tic;
Creating an Upper Triangular Matrix

for j=1:n-1

if A(j,j)==0 Pivoting Operation because we do not want zero denominator

m=j; Pivot the row

for m=m+1:n For the subsequent row of m+1

if A(m,j)==0

continue

end

break

end

B=A(j,:);

C=b(j);

A(j,:)= A(m,:);

b(j)=b(m);

A(m,:)= B;

b(m)=C;
Forward elimination

for i=1+ss:n-1

fac = A(i+1,j)/A(j,j);

A(i+1,:) = A(i+1,:) - fac*A(j,:);

b(i+1) = b(i+1) - fac*b(j);

end

ss=ss+1;

end
Backward substitution

x(n)=b(n)/A(n,n);

for i=n-1:-1:1 syntax for count down from n-1 until 1

coefsum=0;

for j=i+1:n

coefsum=coefsum+A(i,j)*x(j);

end

x(i)=(1/A(i,i))*(b(i)-coefsum);
Displaying the output

toc

disp('Upper Triangular Form of Matrix [A] =');

disp(A)

disp('Solution of the system of equations is :');

disp(x')

You might also like