]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add determinant function.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 6 Mar 1998 08:21:35 +0000 (08:21 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 6 Mar 1998 08:21:35 +0000 (08:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@24 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/dfmatrix.h
deal.II/lac/source/dfmatrix.cc

index 241d8f7a094f26bb0b2f4ed6f0fd047fb48fb066..04943233d045522120d2a7725aacbd8c0bfb2676 100644 (file)
@@ -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
index c7dd222200bd275f493c1cb4db56b44d9a9f9b14..9e8c807be7030a7e055aa18e6214f9b60cc0b859 100644 (file)
@@ -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;
+    };
+};

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.