function [A,P,error]=mylu2(A,b)
N=length(A);
P=eye(N);
error=0;
for k=1:N-1
    if A(k,k)==0
        error=1;
        for i=k+1:N
            if A(i,k)~=0, 
               aux=A(i,:); A(i,:)=A(k,:); A(k,:)=aux; error=0;
               Paux=P(i,:); P(i,:)=P(k,:); P(k,:)=Paux; 
               break, 
            end
        end
        if error==1, return, end
    end
    i=[k+1:N];
    A(i,k)=A(i,k)/A(k,k);
    A(i,i)=A(i,i)-A(i,k)*A(k,i);
end 
