function [L,U] = LUDeco(A)


[m n] = size(A);

if(m~=n)
    
    error('Matrix most be square.');
    
else
    
    LTemp = eye(m);
    
    UTemp = zeros(m);
    
    for i=1:m
        
        for j=1:i
            
            sumTemp = 0;
            
            for k=1:i-1
                
                sumTemp = sumTemp + (LTemp(j,k) * UTemp(k,i));
            end
            
            UTemp(j,i) = A(j,i) - sumTemp;
            
        end
        
        for j=i+1:m
            
            sumTemp = 0;
            
            for k=1:i-1
                
                sumTemp = sumTemp + (LTemp(j,k) * UTemp(k,i));
                
            end
            
            LTemp(j,i) = (A(j,i) - sumTemp) / UTemp(i,i);
            
        end
        
    end
    L = LTemp;
    
    U = UTemp;
    
end

end

