summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Algorithms.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-01-18 08:54:22 +0000
committerAlberto Ruiz <aruiz@um.es>2010-01-18 08:54:22 +0000
commit830164c7c34d874aa66754206be956f85456842f (patch)
tree8ddc23931a05b5d479187e3c61c2d84711f0be63 /lib/Numeric/LinearAlgebra/Algorithms.hs
parent3fb3a81e63540497a81b717c615f711ce031c76f (diff)
scalar moved to Linear and equal used for ==
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index de88dd9..51e0922 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -147,6 +147,14 @@ instance Field (Complex Double) where
147 147
148-------------------------------------------------------------- 148--------------------------------------------------------------
149 149
150square m = rows m == cols m
151
152vertical m = rows m >= cols m
153
154exactHermitian m = m `equal` ctrans m
155
156--------------------------------------------------------------
157
150-- | Full singular value decomposition. 158-- | Full singular value decomposition.
151svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) 159svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t)
152svd = svd' 160svd = svd'
@@ -179,7 +187,6 @@ compactSVD m = (u', subVector 0 d s, v') where
179 u' = takeColumns d u 187 u' = takeColumns d u
180 v' = takeColumns d v 188 v' = takeColumns d v
181 189
182vertical m = rows m >= cols m
183 190
184-- | Singular values and all right singular vectors. 191-- | Singular values and all right singular vectors.
185rightSV :: Field t => Matrix t -> (Vector Double, Matrix t) 192rightSV :: Field t => Matrix t -> (Vector Double, Matrix t)
@@ -255,12 +262,12 @@ eigenvaluesSH' = eigOnlySH
255-- 262--
256-- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@ 263-- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@
257eigSH :: Field t => Matrix t -> (Vector Double, Matrix t) 264eigSH :: Field t => Matrix t -> (Vector Double, Matrix t)
258eigSH m | m `equal` ctrans m = eigSH' m 265eigSH m | exactHermitian m = eigSH' m
259 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix" 266 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix"
260 267
261-- | Eigenvalues of a complex hermitian or real symmetric matrix. 268-- | Eigenvalues of a complex hermitian or real symmetric matrix.
262eigenvaluesSH :: Field t => Matrix t -> Vector Double 269eigenvaluesSH :: Field t => Matrix t -> Vector Double
263eigenvaluesSH m | m `equal` ctrans m = eigenvaluesSH' m 270eigenvaluesSH m | exactHermitian m = eigenvaluesSH' m
264 | otherwise = error "eigenvaluesSH requires complex hermitian or real symmetric matrix" 271 | otherwise = error "eigenvaluesSH requires complex hermitian or real symmetric matrix"
265 272
266-------------------------------------------------------------- 273--------------------------------------------------------------
@@ -317,14 +324,12 @@ cholSH = cholSH'
317-- 324--
318-- If @c = chol m@ then @m == ctrans c \<> c@. 325-- If @c = chol m@ then @m == ctrans c \<> c@.
319chol :: Field t => Matrix t -> Matrix t 326chol :: Field t => Matrix t -> Matrix t
320chol m | m `equal` ctrans m = cholSH m 327chol m | exactHermitian m = cholSH m
321 | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix" 328 | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix"
322 329
323 330
324 331
325 332
326square m = rows m == cols m
327
328-- | Determinant of a square matrix. 333-- | Determinant of a square matrix.
329det :: Field t => Matrix t -> t 334det :: Field t => Matrix t -> t
330det m | square m = s * (product $ toList $ takeDiag $ lup) 335det m | square m = s * (product $ toList $ takeDiag $ lup)
@@ -569,7 +574,7 @@ diagonalize m = if rank v == n
569 then Just (l,v) 574 then Just (l,v)
570 else Nothing 575 else Nothing
571 where n = rows m 576 where n = rows m
572 (l,v) = if m `equal` ctrans m 577 (l,v) = if exactHermitian m
573 then let (l',v') = eigSH m in (real l', v') 578 then let (l',v') = eigSH m in (real l', v')
574 else eig m 579 else eig m
575 580