Lab 6 LU Decomposition
Lab 6 LU Decomposition
Lab No: 6
LU Decomposition Method
Section: A
Software:
MATLAB
Theory:
Basically, we do computations and visualization in MATLAB. In this lab, we did the
computations. We learn how to write the matrices in MATLAB and perform the arithmetic
operations on matrices. We learn how to find roots of system of linear of equations by using
the LU decomposition method in MATLAB. In LU decomposition method, the matrix is
transformed into lower and triangular matrix, there are two methods in LU decomposition
which are Croute’s method and Doolittle’s method. In lower triangular matrix we take diagonal
elements unity in Doolittle’s methods. In croute’s method we take diagonal elements of upper
matrix as unity. Three steps are necessary for LU decomposition. LU decomposition method
is used to solve the system of linear equations.
A = [L][U]
[L]Y=B
[U]X=Y
4x1-2x2+5x3=10
0x1-2x2+5x3=12
-5x1+10x2+15x3=-20
MATLAB Code:
A=[4 -2 5;0 -2 5;-5 10 15];
A=[4 -2 5;0 -2 5;-5 10 15];
[L,U] = lu(A)
y=[10;12;-20];
x1=inv(A)*y
x2=A\y
x3=U\(L\(P*y))
Results:
Croute’s Method:
MATLAB Code:
function[L U]=LU_crout(A)
m=length(A);
L=zeros(size(A));
U=zeros(size(A));
L(:,1)=A(:,1);
U(1,:)=A(1,:)/L(1,1);
U(1,1)=1;
for k=2:m
for j=2:m
for i=j:m
L(i,j)=A(i,j)-dot(L(i,1:j-1),U(1:j-1,j));
end
U(k,j)=(A(k,j)-dot(L(k,1:k-1),U(1:k-1,j)))/L(k,k);
end
end
Result:
Doolittle’s Method:
A=input('Enter the square matrix to be factorized ');
[m,n]=size(A);
if m~=n
disp('Matrix must be square')
beep
end
U=zeros(m);
L=zeros(m);
for j=1:m
L(j,j)=1;
end
for j=1:m
U(1,j)=A(1,j);
end
for i=2:m
for j=1:m
for k=1:i-1
s1=0;
if k==1
s1=0;
else
for p=1:k-1
s1=s1+L(i,p)*U(p,k);
end
end
L(i,k)=(A(i,k)-s1)/U(k,k);
end
for k=i:m
s2=0;
for p=1:i-1
s2=s2+L(i,p)*U(p,k);
end
U(i,k)=A(i,k)-s2;
end
end
end
disp('The matrix to be decomposed is')
A
disp('The Lower Triangular Matrix is')
L
disp('The Upper Triangular Matrix is')
U
Result:
Conclusion:
After performing this lab, we come to know about the computations in MATLAB and basic
operations that we did on matrices in MATLAB. We write the code for Gauss elimination
method to determine the roots of system of linear equations. We successfully determine the
roots of equations by transforming the matrix into reduce echelon form and then use the back
substitution.