From: Wolfgang Bangerth Date: Fri, 6 Mar 1998 08:21:35 +0000 (+0000) Subject: Add determinant function. X-Git-Tag: v8.0.0~23227 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cbde930357e926429591b068ad8741d0c306003;p=dealii.git Add determinant function. git-svn-id: https://svn.dealii.org/trunk@24 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/dfmatrix.h b/deal.II/lac/include/lac/dfmatrix.h index 241d8f7a09..04943233d0 100644 --- a/deal.II/lac/include/lac/dfmatrix.h +++ b/deal.II/lac/include/lac/dfmatrix.h @@ -154,6 +154,15 @@ class dFMatrix * of computing time! */ bool operator == (const dFMatrix &) const; - + + /** + * Computes the determinant of a matrix. + * This is only implemented for one two and + * three dimensions, since for higher + * dimensions the numerical work explodes. + * Obviously, the matrix needs to be square + * for this function. + */ + double determinant () const; }; #endif diff --git a/deal.II/lac/source/dfmatrix.cc b/deal.II/lac/source/dfmatrix.cc index c7dd222200..9e8c807be7 100644 --- a/deal.II/lac/source/dfmatrix.cc +++ b/deal.II/lac/source/dfmatrix.cc @@ -860,3 +860,26 @@ dFMatrix::operator == (const dFMatrix &m) const if (el(i,j) != m.el(i,j)) return false; return true; }; + + +double dFMatrix::determinant () const { + THROW2 (dim_range != dim_image, ); + THROW2 ((dim_range<1) || (dim_range>3), IntError::Range(dim_range)); + + switch (dim_range) + { + case 1: + return el(0,0); + case 2: + return el(0,0)*el(1,1) - el(1,0)*el(0,1); + case 3: + return (el(0,0)*el(1,1)*el(2,2) + -el(0,0)*el(1,2)*el(2,1) + -el(1,0)*el(0,1)*el(2,2) + +el(1,0)*el(0,2)*el(2,1) + +el(2,0)*el(0,1)*el(1,2) + -el(2,0)*el(0,2)*el(1,1)); + default: + return 0; + }; +};