public class sysLin{
private matrice A;
private vecteur b;	

//constructeurs
sysLin(double[][] AA, double[] bb)
{A=new matrice(AA);
b= new vecteur(bb);
}



//Resolution par la methode de Gauss
public vecteur Gauss1()
{// copies locales
matrice lA= new matrice(A);
lA.afficher();
vecteur lb= new vecteur(b);
double c=0.0;
int n=A.nbColonnes();
// Transformation de la matrice
for(int k=0;k<n;k++)
{
for (int i=k+1;i<n;i++)
{  c=lb.elt(i)-(lA.coef(i,k)/lA.coef(k,k))*lb.elt(k);   
    lb.toElt(i,c);
    for (int j=k+1;j<n;j++)
    {
    c=lA.coef(i,j)-(lA.coef(i,k)/lA.coef(k,k))*lA.coef(k,j);
    lA.toCoef(i,j,c);
  }
  }}
  lA.afficher();
vecteur x=new vecteur(n);  
//Remontee

x.toElt(n-1,lb.elt(n-1)/lA.coef(n-1,n-1));
for (int i=n-2;i>-1;i--)
{ 
  double s=0;
  for (int j=i+1;j<n;j++)
    s+=lA.coef(i,j)*x.elt(j);
    x.toElt(i,(lb.elt(i)-s)/lA.coef(i,i));
}
x.afficher();
return x;

}


//Resolution par la methode de Gauss deuxieme version
public vecteur Gauss2()
{// copies locales
matrice lA= new matrice(A);
lA.afficher();
vecteur lb= new vecteur(b);
double c=0.0, ch=0.0;
double p=0.0;
int n=A.nbColonnes();
// Transformation de la matrice
for(int k=0;k<n;k++)
{
	
  p=lA.coef(k,k);
  int i=k;
    while ((p==0)&&(i<n-1)) {
      i++;
      p=lA.coef(i,k);}     
    for (int j=k;j<n;j++){ 
    ch=lA.coef(k,j);
      lA.toCoef(k,j,lA.coef(i,j));
      lA.toCoef(i,j,ch); 
   }
      ch=b.elt(k);
      b.toElt(k,b.elt(i));
      b.toElt(i,ch);   

for ( i=k+1;i<n;i++)
{  c=lb.elt(i)-(lA.coef(i,k)/lA.coef(k,k))*lb.elt(k);   
    lb.toElt(i,c);
    for (int j=k+1;j<n;j++)
    {
    c=lA.coef(i,j)-(lA.coef(i,k)/lA.coef(k,k))*lA.coef(k,j);
    lA.toCoef(i,j,c);
  }
  }}
  lA.afficher();
vecteur x=new vecteur(n);  
//Remontee

x.toElt(n-1,lb.elt(n-1)/lA.coef(n-1,n-1));
for (int i=n-2;i>-1;i--)
{ 
  double s=0;
  for (int j=i+1;j<n;j++)
    s+=lA.coef(i,j)*x.elt(j);
    x.toElt(i,(lb.elt(i)-s)/lA.coef(i,i));
}
x.afficher();
return x;

}


//Resolution par la methode de Gauss v3
public vecteur Gauss3() throws MatriceNonInvException
{// copies locales
matrice lA= new matrice(A);
lA.afficher();
vecteur lb= new vecteur(b);
double c=0.0, ch=0.0;
double p=0.0;
int n=A.nbColonnes();
vecteur x=new vecteur(n);
	
// Transformation de la matrice
for(int k=0;k<n;k++)
{
	
  p=lA.coef(k,k);
  int i=k;
    while ((p==0)&&(i<n-1)) {
      i++;
      p=lA.coef(i,k);
      }
  System.out.println(p);
  if (p==0) throw new MatriceNonInvException();
  else {      
    for (int j=k;j<n;j++){ 
    ch=lA.coef(k,j);
      lA.toCoef(k,j,lA.coef(i,j));
      lA.toCoef(i,j,ch); 
   }
      ch=b.elt(k);
      b.toElt(k,b.elt(i));
      b.toElt(i,ch);   

for ( i=k+1;i<n;i++)
{  c=lb.elt(i)-(lA.coef(i,k)/lA.coef(k,k))*lb.elt(k);   
    lb.toElt(i,c);
    for (int j=k+1;j<n;j++)
    {
    c=lA.coef(i,j)-(lA.coef(i,k)/lA.coef(k,k))*lA.coef(k,j);
    lA.toCoef(i,j,c);
  }
  }}}
  lA.afficher();
  
//Remontee

x.toElt(n-1,lb.elt(n-1)/lA.coef(n-1,n-1));
for (int i=n-2;i>-1;i--)
{ 
  double s=0;
  for (int j=i+1;j<n;j++)
    s+=lA.coef(i,j)*x.elt(j);
    x.toElt(i,(lb.elt(i)-s)/lA.coef(i,i));
}
x.afficher();


return x;
}
}