Advertisement
Diamyx

LUfp

Apr 9th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.55 KB | None | 0 0
  1. function [L,U] = LUfp(A)
  2.     if det(A)==0
  3.         error('Matricea A nu este inversabila')
  4.     else
  5.         if size(A)~=size(A')
  6.             error('Matricea A nu este patratica')
  7.         end
  8.         n=size(A,1);
  9.         L=eye(n);
  10.         U=zeros(n);
  11.         S=zeros(n);
  12.         for i=1:n
  13.             S(i,i)=A(i,i);
  14.         end
  15.         for i=n:-1:2
  16.             U(n-i+1,n-i+1)=S(i,i);
  17.             L((n-i+2):end,n-i+1)=S(2:end,i)/S(i,i);
  18.             S=L((n-i+2):end,n-i+1)*U(n-i+1,(n-i+2):end)+A((n-i+1):end,(n-i+1):end);
  19.         end
  20.     end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement