disp (' This is the code of LU method.Is writen by Ali Ashouri') disp (' ') disp (' ') disp (' ********Before enter anything read all of introduction that will write. read all of them*******') disp (' ') format long disp (' ') n=input(' enter (n) the number of array of matrix (n*n) :'); disp(' enter the data of matrix: from left to right then up to down '); A=cell(n,n); x=cell(n,1); y=cell(n,1); B=cell(n,1); L=cell(n,n); U=cell(n,n); for i=1:n x(i,1)={0}; y(i,1)={0}; end; disp(' The Matrix B is :') for i=1:n b=input('the number for B: '); B(i,1)={b}; end; disp(' ') disp(' The Matrix of B is : ') disp(B); for i=1:n for j=1:n b=input('the number A : '); A(i,j)={b}; end; end; tic W=A; disp(' ') disp(' The Matrix of A is : ') disp(A); for i=1:n-1 for j=i+1:n g=-cell2mat(W(j,i))./cell2mat(W(i,i)); if g==0 else for t=i:n W(j,t)={cell2mat(W(i,t))*g+cell2mat(W(j,t))}; end; end; end; end; for i=1:n for j=1:n if abs(cell2mat(W(i,j)))<0.000009 W(i,j)={0}; end; end; end; for i=1:n for j=1:n if abs(cell2mat(W(i,j)))<0.00009 W(i,j)={0}; end; end; end; disp(' ') disp(' The Matrix of U is : ') disp(cell2mat(W)) U=W; for i=1:n-1 for j=i+1:n L(i,j)={0}; end; end; for i=2:n j=i; L(i,j)={1}; end; j=1; for i=1:n L(i,j)={(cell2mat(A(i,j)))./(cell2mat(U(1,1)))}; end if n<3 else for i=3:n for j=2:i-1 a=0; for k=1:j-1 b=(cell2mat(L(i,k))).*(cell2mat(U(k,j)))+a; a=b; end; L(i,j)={(cell2mat(A(i,j))-a)./(cell2mat(U(j,j)))}; end; end; end; disp(' The Matrix of L is : ') disp(cell2mat(L)); for j=1:n g=cell2mat(L(j,j)); m=0; for t=1:j-1 m=m+cell2mat(L(j,t))*cell2mat(y(t,1)); end; if g==0 else y(j,1)={(cell2mat(B(j,1))-m)/g}; end; end; disp(' ') disp(' ') disp(' The values of y are : ') for i=1:+1:n; q=cell2mat(y(i,1)); disp([' ',num2str(q)]); end; for j=n:-1:1 g=cell2mat(U(j,j)); m=0; for t=j+1:+1:n m=m+cell2mat(U(j,t))*cell2mat(x(t,1)); end; if g==0 else x(j,1)={(cell2mat(y(j,1))-m)/g}; end; end; disp(' ') disp(' ') disp(' The values of x are : ') for i=1:+1:n; q=cell2mat(x(i,1)); disp([' ',num2str(q)]); end; disp(' ') disp(' ') toc