function X = gauss0(A,B) 

printf('gauss0 sans pivot maximal avec calcul dans le cas de matrice singulière')

n=size(A,'c')
if ~ size(A,'r')==n  then printf('matrice non carree'), end

A(:,n+1) = B // ou A=[A,B]
print(6,A),

for k = 1 : n ,
    if A(k,k)==0 then 
        printf('pivot nul a l''etape %d',k),
        if k<n then i=k+1,
                    while(A(i,k)==0 & i<n ), i=i+1, 
                    end,
               else i=k,
        end,
        if A(i,k)==0 then printf('matrice singulière pas de pivot non nul à l''étape%d',k),  
                     else printf('on echange les lignes %d et %d',k,i),
                          A([k,i],:)=A([i,k],:),
                          print(6,A),
        end,
    end,
  
  if ~ A(k,k)==0,
    // si pas de pivot non nul on ne fait rien
    printf('pivot=%f',A(k,k)),
    A(k+1:n,k:n+1) = A(k+1:n,k:n+1) - A(k+1:n,k)*A(k,k:n+1)/A(k,k)
  end,
    printf('etape %d',k),
    print(6,A),
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),
    // pour traiter le cas indéterminé ou impossible
    num =A(i,n+1) - A(i,i+1:n)*X(i+1:n),
    if A(i,i)==0,
       if num==0, indet=1000, // ou 0 ou 1000 ou int(rand(10)*10),
                  printf('X(%d) est indéterminé (0/0), on choisit la valeur %d',i,indet),
                  X(i)=indet,
       else printf('le calcul de X(%d) est impossible (%d/0)',i,num),X='impossible',return,
       end,
    else    X(i) = num/A(i,i),
    end,
end,
printf('solution'),

// appel gauss0(A,B) ou X=gauss0(A,B)
// A=[2,1,-4;4,2,-7;2,1,-1], B=[8;15;9]        impossible
// A=[2,1,-4;4,2,-7;2,1,-1], B=[8;15;5]        indetermine

// A=[2 2 3 ; 1 1 3 ; 2 2 1], B1=[1;2;-1], B2=[1;2;2] 
 

