X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flinal%2Fsquarematrix.h;h=0a97e61172b6489c58e91296421e946cfddfb9d8;hb=5797fe0a5296952cb8f8643fdc6cabddee19a554;hp=0af9a7454852cb5106382fcda2a4f1c5e2aaf824;hpb=adb812a194961d542dcb0abd61258cbc8723ecd9;p=libs%2Fmath.git diff --git a/source/linal/squarematrix.h b/source/linal/squarematrix.h index 0af9a74..0a97e61 100644 --- a/source/linal/squarematrix.h +++ b/source/linal/squarematrix.h @@ -1,19 +1,13 @@ #ifndef MSP_LINAL_SQUAREMATRIX_H_ #define MSP_LINAL_SQUAREMATRIX_H_ -#include +#include #include "matrix.h" +#include "matrixops.h" namespace Msp { namespace LinAl { -class not_invertible: public std::domain_error -{ -public: - not_invertible(): domain_error(std::string()) { } - virtual ~not_invertible() throw() { } -}; - /** A mathematical matrix with S rows and columns. Some operations are provided here that are only possible for square matrices. @@ -53,39 +47,7 @@ template SquareMatrix &SquareMatrix::invert() { SquareMatrix r = identity(); - for(unsigned i=0; ielement(i, i)==T(0)) - { - unsigned pivot = i; - for(unsigned j=i+1; jelement(j, i))>abs(this->element(pivot, i))) - pivot = j; - - if(pivot==i) - throw not_invertible(); - - this->exchange_rows(i, pivot); - r.exchange_rows(i, pivot); - } - - for(unsigned j=i+1; jelement(j, i)/this->element(i, i); - this->add_row(i, j, a); - r.add_row(i, j, a); - } - - T a = T(1)/this->element(i, i); - this->multiply_row(i, a); - r.multiply_row(i, a); - } - - for(unsigned i=S; i-->0; ) - for(unsigned j=i; j-->0; ) - r.add_row(i, j, -this->element(j, i)); - - return *this = r; + return invert_matrix(*this, r); } template