correct_det_by_minor_c

View page source

Correctness Test of det_by_minor Routine

Syntax

flag = correct_det_by_minor ()

flag

The return value has prototype

bool flag

It value is 1 if the test passes and 0 otherwise.

Source Code

bool correct_det_by_minor(void)
{  double a[9], det, check;
   double eps99 = 99.0 * DBL_EPSILON;

   random_seed(123);
   uniform_01(9, a);

   /* compute determinant using expansion by minors */
   det = det_by_minor(a, 3);

   /* use expansion by minors to hand code the determinant  */
   check = 0.;
   check += a[0] * ( a[4] * a[8] - a[5] * a[7] );
   check -= a[1] * ( a[3] * a[8] - a[5] * a[6] );
   check += a[2] * ( a[3] * a[7] - a[4] * a[6] );

   if( fabs(det / check - 1.0) < eps99 )
      return true;
   return false;
}