EXPT6
EXPT6
w=w+1;
F=B(m,1);
B(m,1)=B(q,1);
B(q,1)=F;
for y=1:n
H(q,y)=A(m,y);
A(m,y)=A(q,y);
A(q,y)=H(q,y);
end;
end;
end;
end;
if w==0
disp('Pivoting is not needed')
else
disp('Pivoting is done')
disp('After pivoting the matrices are--')
end;
A
B
%UPPER TRIANGULAR MATRIX
for i=1:n
B(i,1)=B(i,1)/A(i,i);
for j=n:-1:1
A(i,j)=A(i,j)/A(i,i);
end;
for k=i+1:n
B(k,1)=B(k,1)-B(i,1)*A(k,i);
for l=n:-1:1
A(k,l)=A(k,l)-A(i,l)*A(k,i);
end;
end;
end;
%BACK SUBSTITUION
x(n,1)=B(n,1)/A(n,n);
for i=n-1:-1:1
s=0;
for j=i+1:n
s=s+A(i,j)*x(j,1);
end;
x(i,1)=(B(i,1)-s)/A(i,i);
end;
%DISPLAYING ROOTS
disp('The roots are--')
x
f=input('Enter 0 to continue or 1 to exit');
end;