0% found this document useful (0 votes)
22 views3 pages

All All 'Enter Matrix (A) :' 'Math Error': Clear Close A Input Size (A, 1) 3 && Size (A, 2) 3 Disp

This document contains MATLAB code to decompose a matrix A into its lower triangular (L) and upper triangular (U) components using Gaussian elimination. It takes input matrices A and r, performs Gaussian elimination on A to obtain L and U, then solves the system of equations Ax=r to find the roots x.

Uploaded by

arine
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)
22 views3 pages

All All 'Enter Matrix (A) :' 'Math Error': Clear Close A Input Size (A, 1) 3 && Size (A, 2) 3 Disp

This document contains MATLAB code to decompose a matrix A into its lower triangular (L) and upper triangular (U) components using Gaussian elimination. It takes input matrices A and r, performs Gaussian elimination on A to obtain L and U, then solves the system of equations Ax=r to find the roots x.

Uploaded by

arine
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/ 3

Task:

clear all
close all
A = input ('enter matrix [A]:');
if size(A,1)~=3 && size(A,2)~=3
disp('math error');
return
end
x=A(2,1)/A(1,1);
A(2,:)=A(2,:)-x*A(1,:);
y=A(3,1)/A(1,1);
A(3,:)=A(3,:)-y*A(1,:);
z=A(3,2)/A(2,2);
L=[1 0 0;x 1 0;y z 1];
disp(L)
Report:

clear all
close all
A=input ('Enter [A]:');
r=input('Constant matrix [r]:');
[a,b]= size(A);
t=zeros(b);
S=0;
for j=1:b
for i= S+1:b-1
f= A(i+1,j)/A(j,j); A(i+1,:)= A(i+1,:)- f*A(j,:);
%new row
t(i+1,j)= f;
end
S=S+1;
end
U=A; %Upper triangular matrix
L=t; %Lower traingular matrix
for i=1:b
L(i,i)=1;
end
B(1)=r(1);
for i=2:b
S=0;
for j=1:i-1
S=S+L(i,j)*B(j);
end
B(i)=r(i)-S;
end
x(b)=B(b)/U(b,b);
for i= b-1: -1: 1
S=0;
for j=i+1:b
S=S+U(i,j)*x(j);
end
x(i)=(1/U(i,i))*(B(i)-S);
end
disp('L=');disp(L)
disp('U=');disp(U)
disp('Roots=');disp(x)

You might also like