20 Haziran 2011 Pazartesi

LU Decomposition

ONE SQUARE MATRIX = TWO TRIANGULAR MATRIX

A=LU

The factors are L and U triangular matrices. U is the upper triangular matrix with the pivots on diagonal. Eliminitaion takes A to U, reversing this step back U to A takes, L. L is lower triangular matrix and has all 1's its diagonal. Let's factorize a random matrix without row exchanges;

>>A=round(10*rand(n,n)) % creates n by n matrix (n=arbitrary)

%%%%%%%%%%%%%%%%%%%%
% Author: Mustafa DENIZ                    %
% Contact: mustafdeniz@itu.edu.tr        %
%%%%%%%%%%%%%%%%%%%%%

[n,n]=size(A);
tolerance=1.e-8;

for k = 1:n
   if abs(A(k, k)) < tolerance
   end
   L(k, k) = 1;
   for i = k+1:n
     L(i,k) = A(i, k) / A(k, k); %Multipliers for column k are put into L
     for j = k+1:n %Elimination beyond row k and column k.
       A(i, j) = A(i, j) - L(i, k)*A(k, j);
     end
   end
 for j = k:n
  U(k, j) = A(k, j);
 end
end


Matlab has a command also for LU factorization;

>> [U,L]=lu(A)

References:

Strang. G., 2009. Introduction to Linear Algebra, Fourth Edition, Wellesley Cambridge Press.

William H.P. et al, 2007. Numerical Recipes 3rd Edition: The Art of Scientific Computing, Cambridge University Press.

Hiç yorum yok:

Yorum Gönder