function [x,error]=mygauss(A,b)
N=length(A);
A=[A,b];
x=zeros(N,1);
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;
               break, 
            end
        end
        if error==1, return, end
    end
    i=[k+1:N];
    j=[k+1:N+1];
    A(i,k)=A(i,k)/A(k,k);
    A(i,j)=A(i,j)-A(i,k)*A(k,j);
end
% backward
if A(N,N)==0, error=1; return, end
x(N)=A(N,N+1)/A(N,N);
for i=N-1:-1:1
   x(i)=(A(i,N+1)-A(i,i+1:N)*x(i+1:N))/A(i,i);
end
