Changeset 9291f85
- Timestamp:
- Jan 10, 2010, 7:25:50 PM (16 years ago)
- Children:
- 9cdbee
- Parents:
- 7b991d
- Location:
- molecuilder/src
- Files:
-
- 2 edited
-
gslmatrix.cpp (modified) (1 diff)
-
unittests/gslmatrixsymmetricunittest.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/gslmatrix.cpp
r7b991d r9291f85 229 229 return (gsl_linalg_cholesky_decomp (matrix) != GSL_EDOM); 230 230 }; 231 232 233 /** Calculates the determinant of the matrix. 234 * if matrix is square, uses LU decomposition. 235 */ 236 double GSLMatrix::Determinant() 237 { 238 int signum = 0; 239 assert (rows == columns && "Determinant can only be calculated for square matrices."); 240 gsl_permutation *p = gsl_permutation_alloc(rows); 241 gsl_linalg_LU_decomp(matrix, p, &signum); 242 gsl_permutation_free(p); 243 return gsl_linalg_LU_det(matrix, signum); 244 }; 245 -
molecuilder/src/unittests/gslmatrixsymmetricunittest.cpp
r7b991d r9291f85 247 247 m->SetFromDoubleArray(array); 248 248 CPPUNIT_ASSERT_EQUAL( true, m->IsPositiveDefinite() ); 249 250 //determinant 251 m->SetIdentity(); 252 CPPUNIT_ASSERT_EQUAL( 1., m->Determinant() ); 253 254 m->SetZero(); 255 CPPUNIT_ASSERT_EQUAL( 0., m->Determinant() ); 256 257 m->Set( 0, 0, 1.); 258 m->Set( 1, 1, 1.); 259 m->Set( 2, 1, 1.); 260 CPPUNIT_ASSERT_EQUAL( 0., m->Determinant() ); 261 262 double array2[] = { 2., 0., 1., 263 -3., 1., 1., 264 1., 5.5, 1. }; 265 m->SetFromDoubleArray(array2); 266 CPPUNIT_ASSERT_EQUAL( -26.5, m->Determinant() ); 249 267 }; 250 268
Note:
See TracChangeset
for help on using the changeset viewer.
