/************************************************************************ NxN Matrix class Copyright (C) 1998 Michael Garland. See "COPYING.txt" for details. $Id: MxMatrix.cxx,v 1.4 1998/10/26 21:09:09 garland Exp $ ************************************************************************/ #include "stdmix.h" #include "MxMatrix.h" // Originally from Paul's matrix library. // // Returns determinant of a, and b=a inverse. // If matrix is singular, returns 0 and leaves trash in b. // // Uses Gaussian elimination with partial pivoting. #define SWAP(a, b, t) {t = a; a = b; b = t;} static double internal_invert(MxMatrix& A, MxMatrix& B) { uint N = A.dim(); uint i, j, k; double max, t, det, pivot; /*---------- forward elimination ----------*/ for (i=0; i max) { max = fabs(A(k, i)); j = k; } if (max<=0.) return 0.; /* if no nonzero pivot, PUNT */ if (j!=i) { /* swap rows i and j */ for (k=i; k0; i--) { /* eliminate in column i, above diag */ for (j=0; j