|
1 #ifndef RIVET_MATH_MATRIXN 2 #define RIVET_MATH_MATRIXN 4 #include "Rivet/Math/MathHeader.hh" 5 #include "Rivet/Math/MathUtils.hh" 6 #include "Rivet/Math/Vectors.hh" 8 #include "Rivet/Math/eigen/matrix.h" 50 for ( size_t i = 0; i < N; ++i) { 51 rtn.set(i, i, diag[i]); 58 for ( size_t i = 0; i < N; ++i) { 72 _matrix = other._matrix; 75 Matrix& set( const size_t i, const size_t j, const double value) { 77 _matrix(i, j) = value; 79 throw std::runtime_error( "Attempted set access outside matrix bounds."); 84 double get( const size_t i, const size_t j) const { 88 throw std::runtime_error( "Attempted get access outside matrix bounds."); 92 Vector<N> getRow( const size_t row) const { 94 for ( size_t i = 0; i < N; ++i) { 95 rtn. set(i, _matrix(row,i)); 101 for ( size_t i = 0; i < N; ++i) { 102 _matrix(row,i) = r.get(i); 107 Vector<N> getColumn( const size_t col) const { 109 for ( size_t i = 0; i < N; ++i) { 110 rtn. set(i, _matrix(i,col)); 116 for ( size_t i = 0; i < N; ++i) { 117 _matrix(i,col) = c.get(i); 124 tmp._matrix.replaceWithAdjoint(); 136 tmp._matrix = _matrix. inverse(); 142 return _matrix.determinant(); 148 for ( size_t i = 0; i < N; ++i) { 158 rtn._matrix = -_matrix; 168 bool isZero( double tolerance=1E-5) const { 169 for ( size_t i=0; i < N; ++i) { 170 for ( size_t j=0; j < N; ++j) { 179 for ( size_t i=0; i < N; ++i) { 180 for ( size_t j=i; j < N; ++j) { 181 if (! Rivet::isZero(_matrix(i,j) - other._matrix(i,j)) ) return false; 189 return isEqual(this->transpose()); 194 for ( size_t i=0; i < N; ++i) { 195 for ( size_t j=0; j < N; ++j) { 196 if (i == j) continue; 203 bool operator == ( const Matrix<N>& a) const { 204 return _matrix == a._matrix; 207 bool operator != ( const Matrix<N>& a) const { 208 return _matrix != a._matrix; 211 bool operator < (const Matrix<N>& a) const { 212 return _matrix < a._matrix; 215 bool operator <= (const Matrix<N>& a) const { 216 return _matrix <= a._matrix; 219 bool operator > ( const Matrix<N>& a) const { 220 return _matrix > a._matrix; 223 bool operator >= ( const Matrix<N>& a) const { 224 return _matrix >= a._matrix; 228 _matrix = _matrix * m._matrix; 232 Matrix<N>& operator *= ( const double a) { 237 Matrix<N>& operator /= ( const double a) { 243 _matrix += m._matrix; 248 _matrix -= m._matrix; 254 typedef Eigen::Matrix<double,N> EMatrix; 266 result._matrix = a._matrix + b._matrix; 282 return subtract(a, b); 288 rtn._matrix = a * m._matrix; 294 return multiply(a, m); 299 return multiply(1/a, m); 304 return multiply(a, m); 309 return multiply(a, m); 315 tmp._matrix = a._matrix * b._matrix; 321 return multiply(a, b); 328 tmp._vec = a._matrix * b._vec; 334 return multiply(a, b); 346 return m.transpose(); 356 return m.determinant(); 373 for ( size_t i = 0; i < m. size(); ++i) { 375 for ( size_t j = 0; j < m. size(); ++j) { 376 const double e = m.get(i, j); 388 inline ostream& operator << (std::ostream& out, const Matrix<N>& m) { 400 for ( size_t i = 0; i < N; ++i) { 401 for ( size_t j = 0; j < N; ++j) { 402 const double a = ma.get(i, j); 403 const double b = mb.get(i, j); 414 return m. isZero(tolerance); Definition: ALICE_2010_I880049.cc:13
Matrix< N > inverse() const Calculate inverse. Definition: MatrixN.hh:134
bool isSymm() const Check for symmetry under transposition. Definition: MatrixN.hh:188
double det() const Calculate determinant. Definition: MatrixN.hh:141
Vector< N > & set(const size_t index, const double value) Set indexed value. Definition: VectorN.hh:60
bool isZero(double tolerance=1E-5) const Index-wise check for nullness, allowing for numerical precision. Definition: MatrixN.hh:168
General -dimensional mathematical matrix object. Definition: MatrixN.hh:14
std::enable_if< std::is_arithmetic< N1 >::value &&std::is_arithmetic< N2 >::value &&(std::is_floating_point< N1 >::value||std::is_floating_point< N2 >::value), bool >::type fuzzyEquals(N1 a, N2 b, double tolerance=1e-5) Compare two numbers for equality with a degree of fuzziness. Definition: MathUtils.hh:45
A minimal base class for -dimensional vectors. Definition: VectorN.hh:13
double trace() const Calculate trace. Definition: MatrixN.hh:146
Matrix< N > operator-() const Negate. Definition: MatrixN.hh:156
std::enable_if< std::is_floating_point< NUM >::value, bool >::type isZero(NUM val, double tolerance=1e-8) Compare a number to zero. Definition: MathUtils.hh:21
bool isEqual(Matrix< N > other) const Check for index-wise equality, allowing for numerical precision. Definition: MatrixN.hh:178
std::string toString(const AnalysisInfo &ai) String representation. Definition: AnalysisInfo.cc:144
size_t size() const Get dimensionality. Definition: MatrixN.hh:163
bool isDiag() const Check that all off-diagonal elements are zero, allowing for numerical precision. Definition: MatrixN.hh:193
|