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

Lu Factorization Matlab Code:: If Else For

This MATLAB code demonstrates LU factorization using Doolittle and Crout's methods. It takes a 6x6 matrix A and factors it into lower and upper triangular matrices (L and U) using both methods. For Doolittle, L has ones along the diagonal and U is the upper triangular portion of A. For Crout's method, L is the lower triangular portion of A and U has ones along the diagonal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

Lu Factorization Matlab Code:: If Else For

This MATLAB code demonstrates LU factorization using Doolittle and Crout's methods. It takes a 6x6 matrix A and factors it into lower and upper triangular matrices (L and U) using both methods. For Doolittle, L has ones along the diagonal and U is the upper triangular portion of A. For Crout's method, L is the lower triangular portion of A and U has ones along the diagonal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

LU FACTORIZATION

MATLAB Code:
clc;clear all;
A=[ 1 2 3 4 0 1; 0 1 3 2 1 4;
1 2 -1 -2 4 7;7 1 3 8 1 5;
-1 -8 3 2 1 0;1 1 2 2 3 1];
[n,m]=size(A);
if (n~=m)
disp('A should be a square matrix.');
else
for i=1:n-1
A(i+1:n,i)=A(i+1:n,i)/A(i,i);
A(i+1:n,i+1:n)=A(i+1:n,i+1:n)-A(i+1:n,i)*A(i,i+1:n);
end
%%%% DOOLITTLE METHOD %%%%
L_doo=eye(n,n)+tril(A,-1);
U_doo=triu(A);
A,L_doo,U_doo,
%%%% CROUTS METHOD %%%%
L_cr=tril(A);
U_cr=eye(n,n)+triu(A,1);
L_cr,U_cr,
end

OUTPUT:
A=
1.0000 2.0000 3.0000 4.0000

0 1.0000

0 1.0000 3.0000 2.0000 1.0000 4.0000


1.0000

0 -4.0000 -6.0000 4.0000 6.0000

7.0000 -13.0000 -5.2500 -25.5000 35.0000 81.5000


-1.0000 -6.0000 -6.0000 0.7059 6.2941 3.4706
1.0000 -1.0000 -0.5000 0.1176 0.2991 -3.6262
L_doo =
1.0000

0 1.0000

1.0000

0 1.0000

7.0000 -13.0000 -5.2500 1.0000

-1.0000 -6.0000 -6.0000 0.7059 1.0000

0
0

1.0000 -1.0000 -0.5000 0.1176 0.2991 1.0000

U_doo =
1.0000 2.0000 3.0000 4.0000

0 1.0000

0 1.0000 3.0000 2.0000 1.0000 4.0000


0

0 -4.0000 -6.0000 4.0000 6.0000

0 -25.5000 35.0000 81.5000

0 6.2941 3.4706

0 -3.6262

L_cr =
1.0000

0 1.0000

1.0000

0 -4.0000

7.0000 -13.0000 -5.2500 -25.5000

-1.0000 -6.0000 -6.0000 0.7059 6.2941

0
0

1.0000 -1.0000 -0.5000 0.1176 0.2991 -3.6262


U_cr =
1.0000 2.0000 3.0000 4.0000

0 1.0000

0 1.0000 3.0000 2.0000 1.0000 4.0000


0

0 1.0000 -6.0000 4.0000 6.0000

0 1.0000 35.0000 81.5000

0 1.0000 3.4706

0 1.0000

You might also like