function [x,R]=Gauss1(A,b)
  n=size(A,"r");
 
// Transformation de la matrice    
for(k=1:1:n-1)
for (i=k+1:1:n)
    b(i)=b(i)-(A(i,k)/A(k,k))*b(k)     
    A(i,:)=A(i,:)-(A(i,k)/A(k,k))*A(k,:)
  
  end 
  end
//Remontee
R=A;
x(n)=b(n)/A(n,n);
for i=n-1:-1:1
  S=0;
  for j=n:-1:i+1
    S=S+A(i,j)*x(j);
    end  
x(i)=(b(i)-S)/A(i,i);
end
endfunction

function [x,R]=Gauss2(A,b)
  n=size(A,"r"); 
// Transformation de la matrice    
for(k=1:1:n-1)
  p=A(k,k);
  i=k;
    while ((p==0)&(i<n)) do
      i=i+1;
      p=A(i,k);     
    end
    c=A(k,:);
      A(k,:)=A(i,:);
      A(i,:)=c; 
      c=b(k);
      b(k)=b(i);
      b(i)=c;   
    for (i=k+1:1:n)
       b(i)=b(i)-(A(i,k)/A(k,k))*b(k)     
       A(i,:)=A(i,:)-(A(i,k)/A(k,k))*A(k,:)
    end 
end



//Remontee
x(n)=b(n)/A(n,n);
for i=n-1:-1:1
  S=0;
  for j=n:-1:i+1
    S=S+A(i,j)*x(j);
    end  
x(i)=(b(i)-S)/A(i,i);
end
endfunction
       

function [x]=Gauss3(A,b)
  n=size(A,"r"); 
// Transformation de la matrice    
   test=1;
for(k=1:1:n)

p=A(k,k);
   
  i=k;
    while ((p==0)&(i<n)) do
      i=i+1;
      p=A(i,k); 
     // mprintf('La matrice n est pas inversible  %i',p);    
    end
    if (p==0)
     // mprintf('La matrice n est pas inversible  %i',i);
      test=0;
    else
      c=A(k,:);
      A(k,:)=A(i,:);
      A(i,:)=c; 
        c=b(k);
      b(k)=b(i);
      b(i)=c;
      end    
    if (test==1)
      for (i=k+1:1:n)
          b(i)=b(i)-(A(i,k)/A(k,k))*b(k)     
          A(i,:)=A(i,:)-(A(i,k)/A(k,k))*A(k,:)
  
       end 
     end
end
//if (A(n,n)==0) then
//  mprintf('La matrice n est pas inversible  %i',i); 
//elseif (test==1) then
//Remontee
if (test==1)
x(n)=b(n)/A(n,n);
for i=n-1:-1:1
  S=0;
  for j=n:-1:i+1
    S=S+A(i,j)*x(j);
    end  
x(i)=(b(i)-S)/A(i,i);
end
else 
   x=0
   mprintf('La matrice n est pas inversible %d\n',i);
end    
    
endfunction
       



   
