Ignore:
Timestamp:
Jan 10, 2010, 7:25:50 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
9cdbee
Parents:
7b991d
Message:

Added Determinant() function to class GSLMatrix.

  • new function GSLMatrix::Determinant() which calculates the determinant for square matrices by LU decomposition.

Signed-off-by: Frederik Heber <heber@tabletINS.(none)>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/gslmatrix.cpp

    r7b991d r9291f85  
    229229    return (gsl_linalg_cholesky_decomp (matrix) != GSL_EDOM);
    230230};
     231
     232
     233/** Calculates the determinant of the matrix.
     234 * if matrix is square, uses LU decomposition.
     235 */
     236double 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
Note: See TracChangeset for help on using the changeset viewer.