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

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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