Write a computer program to give the factorization PA LU fo
Solution
clc
 clear all
 A=input(\'enter Adata\ \');
[m n]=size(A);
if (m == n )
 L=eye(m,m);
 U=A;
 count1=0;
 count2=0;
 k=1;
 x=1;
 for i=1:m
 if U(i,i)~=0
 E=eye(m,m);
 for j=i+1:m
 multi=U(j,i)/U(i,i);
 E(j,i)=E(j,i)-multi;
 U(j,:)= U(j,:)-multi* U(i,:);
 end
 count1=count1+1;
 ele(:,:,count1)=E;
 elepos(k)=i;
 k=k+1;
 else
 P=eye(m,m);
 for y=i:m
 if U(y,i)~=0
 break
 end
 end
 U([i,y],:)=U([y,i],:);
 P([i,y],:)=P([y,i],:);
 count2=count2+1;
 per(:,:,count2)=P;
 E=eye(m,m);
 for j=i+1:m
 multi=U(j,i)/U(i,i);
 E(j,i)=E(j,i)-multi;
 U(j,:)= U(j,:)-multi* U(i,:);
 end
 count1=count1+1;
 ele(:,:,count1)=E;
 perpos(x)=i;
 x=x+1;
 end
 end
 else
 disp ( \'Dimension error: Matrix must be square\' );
 end
 P=eye(m,m);
 if count2>0
 for i=length(perpos):-1:1
 P=P*per(:,:,i);
 end
 if perpos(1)>1 || count2>1
 for i=1:length(elepos)
 temp=eye(m,m);
 for j=length(perpos):-1:i
 temp=temp*per(:,:,j);
 end
 ele(:,:,i)=temp*ele(:,:,i)*temp\';
 end
 end
 end
 for i=1:m
 for j=1:m
 for k=1:m
 if j>k
 ele(j,k,i)=-ele(j,k,i);
 end
 end
 end
 end
 for i=1:m
 L=L*ele(:,:,i);
 end
 P
 L
 U
RESULT:
enter Adata
 [0 1 0;-8 8 1;2 -2 0];
P =
0 1 0
 1 0 0
 0 0 1
 L =
1.0000 0 0
 0 1.0000 0
 -0.2500 0 1.0000
 U =
-8.0000 8.0000 1.0000
 0 1.0000 0
 0 0 0.2500


