Lecture 7
Lecture 7
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
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(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);
end
ss=ss+1;
end
Backward substitution
x(n)=b(n)/A(n,n);
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(A)
disp(x')