examples/cadna/hilbert_determinant.cpp
/*
 * determinant of Hilbert's matrix
 *
 * The gradual loss of accuracy is pointed out by CADNA.
 * One can see that the value of the determinant is significant even if it is very "small".
 * This shows how difficult it is to judge the numerical quality of a computed result by its magnitude.
 *
 * http://www-pequan.lip6.fr/cadna/Examples_Dir/ex3.php
 */
determinant of Hilbert's matrix
The gradual loss of accuracy is pointed out by CADNA.
One can see that the value of the determinant is significant even if it is very "small".
This shows how difficult it is to judge the numerical quality of a computed result by its magnitude.


determinant of Hilbert ' s matrix The gradual loss of accuracy is pointed out by CADNA . One can see that the value of the determinant is significant even if it is very " small " . This shows how difficult it is to judge the numerical quality of a computed result by its magnitude .
void hilbert()
{
  std::cout << "The determinant of Hilbert's matrix" << '\n'
            << "The gradual loss of accuracy is pointed out." << '\n'
            << "One can see that the value of the determinant is significant even if it is very \"small\"." << std::endl;
  std::array<std::array<Sdouble, 11>, 11> amat;
  for (int i = 1; i <= 11; i++)
  {
    for (int j = 1; j <= 11; j++)
    {
      amat[i-1][j-1] = 1.0 / (i+j-1);
    }
  }
  Sdouble det = 1.0;
  int i;
  for (i = 1; i <= 10; i++)
  {
    Sdouble pivot = amat[i-1][i-1];
    std::cout << "Pivot Sdouble " << i << " = " << pivot << std::endl;
    det = det * pivot;
    Sdouble aux = 1.0 / pivot;
    for (int j = i+1; j <= 11; j++)
    {
      amat[i-1][j-1] = amat[i-1][j-1] * aux;
    }
    for (int j = i+1; j <= 11; j++)
    {
      aux = amat[j-1][i-1];
      for (int k = i+1; k<= 11; k++)
      {
        amat[j-1][k-1] = amat[j-1][k-1] - aux*amat[i-1][k-1];
      }
    }
  }
  Sdouble pivot = amat[i-1][i-1];
  det = det * pivot;
  std::cout << "Pivot Sdouble " << i << " = " << pivot << std::endl;
  std::cout << "Determinant = " << det << std::endl;
  std::cout << std::endl;
}
void hilbert ( ) { std :: cout << " " << ' \n ' << " " << ' \n ' << " \" \" " << std :: endl ; std :: array < std :: array < Sdouble , 11 > , 11 > amat ; for ( int i = 1 ; i <= 11 ; i ++ ) { for ( int j = 1 ; j <= 11 ; j ++ ) { amat [ i - 1 ] [ j - 1 ] = 1.0 / ( i + j - 1 ) ; } } Sdouble det = 1.0 ; int i ; for ( i = 1 ; i <= 10 ; i ++ ) { Sdouble pivot = amat [ i - 1 ] [ i - 1 ] ; std :: cout << " " << i << " " << pivot << std :: endl ; det = det * pivot ; Sdouble aux = 1.0 / pivot ; for ( int j = i + 1 ; j <= 11 ; j ++ ) { amat [ i - 1 ] [ j - 1 ] = amat [ i - 1 ] [ j - 1 ] * aux ; } for ( int j = i + 1 ; j <= 11 ; j ++ ) { aux = amat [ j - 1 ] [ i - 1 ] ; for ( int k = i + 1 ; k <= 11 ; k ++ ) { amat [ j - 1 ] [ k - 1 ] = amat [ j - 1 ] [ k - 1 ] - aux * amat [ i - 1 ] [ k - 1 ] ; } } } Sdouble pivot = amat [ i - 1 ] [ i - 1 ] ; det = det * pivot ; std :: cout << " " << i << " " << pivot << std :: endl ; std :: cout << " " << det << std :: endl ; std :: cout << std :: endl ; }
determinant of Hilbert's matrix
 The gradual loss of accuracy is pointed out by CADNA.
determinant of Hilbert ' s matrix The gradual loss of accuracy is pointed out by CADNA .