1 #ifndef MSP_LINAL_SQUAREMATRIX_H_
2 #define MSP_LINAL_SQUAREMATRIX_H_
12 A mathematical matrix with S rows and columns. Some operations are provided
13 here that are only possible for square matrices.
15 template<typename T, unsigned S>
16 class SquareMatrix: public Matrix<T, S, S>
20 SquareMatrix(const T *d): Matrix<T, S, S>(d) { }
22 SquareMatrix(const Matrix<U, S, S> &m): Matrix<T, S, S>(m) { }
24 static SquareMatrix identity();
26 SquareMatrix &operator*=(const SquareMatrix &);
27 using Matrix<T, S, S>::operator*=;
29 SquareMatrix &invert();
32 template<typename T, unsigned S>
33 inline SquareMatrix<T, S> SquareMatrix<T, S>::identity()
36 for(unsigned i=0; i<S; ++i)
41 template<typename T, unsigned S>
42 SquareMatrix<T, S> &SquareMatrix<T, S>::operator*=(const SquareMatrix<T, S> &m)
44 return *this = *this*m;
47 template<typename T, unsigned S>
48 SquareMatrix<T, S> &SquareMatrix<T, S>::invert()
50 SquareMatrix<T, S> r = identity();
51 gauss_jordan(*this, r);
55 template<typename T, unsigned S>
56 inline SquareMatrix<T, S> invert(const SquareMatrix<T, S> &m)
58 SquareMatrix<T, S> temp = m;
59 SquareMatrix<T, S> r = SquareMatrix<T, S>::identity();
60 return gauss_jordan(temp, r);