double DblMatrix::GetDeterminantNxN() { int w=GetWidth(); assert(w=GetHeight()); if(w==1) return (*this)[0][0]; if(w==2) return GetDeterminant2x2(); if(w==3) return GetDeterminant3x3(); double Det=0.0; // laplace's method (recursion) double s=1.0; if(w%2==1) s=-1.0; for(int i=0; i<w; i++) { DblMatrix SubDet; SubDet.assign(w-1, DblVector()); for(int j=1; j<w; j++) { for(int k=0; k<w; k++) { if(k==i) { continue; } else { SubDet[j-1].push_back((*this)[j][k]); } } } double v = (*this)[0][i]; double a = s * v * SubDet.GetDeterminantNxN(); //std::cout << "s " << s << std::endl; Det += a; s*=-1.0; } return Det; }