0% found this document useful (0 votes)
31 views2 pages

%LU Decomposition: All All

This document shows the steps to perform LU decomposition on a matrix. It defines an example matrix a and vector z, then creates the L and U matrices by performing Gaussian elimination. It uses forward and backward substitution on the L and U matrices to solve for vectors y and b.

Uploaded by

Rakeshgangavati
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)
31 views2 pages

%LU Decomposition: All All

This document shows the steps to perform LU decomposition on a matrix. It defines an example matrix a and vector z, then creates the L and U matrices by performing Gaussian elimination. It uses forward and backward substitution on the L and U matrices to solve for vectors y and b.

Uploaded by

Rakeshgangavati
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/ 2

%LU Decomposition

clc
clear all
close all
a=[ 1,1,-1
2,3,-2
1,2,2];
z = [ 0;6; 10];
a(:,4)= z;

%Creating L matrix
l=eye(3);
for j=1:3
for r=j+1:3
l(r,j)=a(r,j)/a(j,j);
for c=j+1:4
a(r,c)=a(r,c)-l(r,j)*a(j,c);
end
end
end

%creating U Matrix
u=a(:,1:3);
for i=1:3
for j=1:i-1
u(i,j)=0;
end
end

z=a(:,4);

%Forward Substitution to find out y


for i=1:3
sum=0;
for k=1:i-1
sum = sum + l(i,k)*y(k);
end
y(i)= [z(i)- sum]/l(i,i);

end

%Backward Substitution to find out b


for i=3:-1:1
sum=0;
for k=i+1:3
sum = sum + u(i,k)*b(k);
end
b(i)= [y(i)- sum]/u(i,i);
end

1
b =

-4.6667 6.0000 1.3333

Published with MATLAB R2016a

You might also like