summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Algorithms.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-12-28 17:59:18 +0000
committerAlberto Ruiz <aruiz@um.es>2009-12-28 17:59:18 +0000
commit3d15dffe52629fd621ad548b671c3043caefb0d0 (patch)
tree63fed8084a74482b74199cc3ec91136aa110c79e /lib/Numeric/LinearAlgebra/Algorithms.hs
parentb2715e91d7aef5cee1b64b641b8f173167a7145a (diff)
additional eig functions
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 1544d7c..3d4a209 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -40,6 +40,7 @@ module Numeric.LinearAlgebra.Algorithms (
40 leftSV, rightSV, 40 leftSV, rightSV,
41-- ** Eigensystems 41-- ** Eigensystems
42 eig, eigSH, eigSH', 42 eig, eigSH, eigSH',
43 eigenvalues, eigenvaluesSH, eigenvaluesSH',
43-- ** QR 44-- ** QR
44 qr, 45 qr,
45-- ** Cholesky 46-- ** Cholesky
@@ -92,6 +93,8 @@ class (Normed (Matrix t), Linear Vector t, Linear Matrix t) => Field t where
92 linearSolveSVD' :: Matrix t -> Matrix t -> Matrix t 93 linearSolveSVD' :: Matrix t -> Matrix t -> Matrix t
93 eig' :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) 94 eig' :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double))
94 eigSH'' :: Matrix t -> (Vector Double, Matrix t) 95 eigSH'' :: Matrix t -> (Vector Double, Matrix t)
96 eigOnly :: Matrix t -> Vector (Complex Double)
97 eigOnlySH :: Matrix t -> Vector Double
95 cholSH' :: Matrix t -> Matrix t 98 cholSH' :: Matrix t -> Matrix t
96 qr' :: Matrix t -> (Matrix t, Matrix t) 99 qr' :: Matrix t -> (Matrix t, Matrix t)
97 hess' :: Matrix t -> (Matrix t, Matrix t) 100 hess' :: Matrix t -> (Matrix t, Matrix t)
@@ -129,16 +132,24 @@ linearSolve = linearSolve'
129linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t 132linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t
130linearSolveSVD = linearSolveSVD' 133linearSolveSVD = linearSolveSVD'
131 134
132-- | Eigenvalues and eigenvectors of a general square matrix using lapack's dgeev or zgeev. 135-- | Eigenvalues and eigenvectors of a general square matrix.
133-- 136--
134-- If @(s,v) = eig m@ then @m \<> v == v \<> diag s@ 137-- If @(s,v) = eig m@ then @m \<> v == v \<> diag s@
135eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) 138eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double))
136eig = eig' 139eig = eig'
137 140
141-- | Eigenvalues of a general square matrix.
142eigenvalues :: Field t => Matrix t -> Vector (Complex Double)
143eigenvalues = eigOnly
144
138-- | Similar to 'eigSH' without checking that the input matrix is hermitian or symmetric. 145-- | Similar to 'eigSH' without checking that the input matrix is hermitian or symmetric.
139eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t) 146eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t)
140eigSH' = eigSH'' 147eigSH' = eigSH''
141 148
149-- | Similar to 'eigenvaluesSH' without checking that the input matrix is hermitian or symmetric.
150eigenvaluesSH' :: Field t => Matrix t -> Vector Double
151eigenvaluesSH' = eigOnlySH
152
142-- | Similar to 'chol' without checking that the input matrix is hermitian or symmetric. 153-- | Similar to 'chol' without checking that the input matrix is hermitian or symmetric.
143cholSH :: Field t => Matrix t -> Matrix t 154cholSH :: Field t => Matrix t -> Matrix t
144cholSH = cholSH' 155cholSH = cholSH'
@@ -187,6 +198,8 @@ instance Field Double where
187 ctrans' = trans 198 ctrans' = trans
188 eig' = eigR 199 eig' = eigR
189 eigSH'' = eigS 200 eigSH'' = eigS
201 eigOnly = eigOnlyR
202 eigOnlySH = eigOnlyS
190 cholSH' = cholS 203 cholSH' = cholS
191 qr' = unpackQR . qrR 204 qr' = unpackQR . qrR
192 hess' = unpackHess hessR 205 hess' = unpackHess hessR
@@ -203,7 +216,9 @@ instance Field (Complex Double) where
203 linearSolveSVD' = linearSolveSVDC Nothing 216 linearSolveSVD' = linearSolveSVDC Nothing
204 ctrans' = conj . trans 217 ctrans' = conj . trans
205 eig' = eigC 218 eig' = eigC
219 eigOnly = eigOnlyC
206 eigSH'' = eigH 220 eigSH'' = eigH
221 eigOnlySH = eigOnlyH
207 cholSH' = cholH 222 cholSH' = cholH
208 qr' = unpackQR . qrC 223 qr' = unpackQR . qrC
209 hess' = unpackHess hessC 224 hess' = unpackHess hessC
@@ -211,13 +226,18 @@ instance Field (Complex Double) where
211 multiply' = multiplyC 226 multiply' = multiplyC
212 227
213 228
214-- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric matrix using lapack's dsyev or zheev. 229-- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric matrix.
215-- 230--
216-- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@ 231-- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@
217eigSH :: Field t => Matrix t -> (Vector Double, Matrix t) 232eigSH :: Field t => Matrix t -> (Vector Double, Matrix t)
218eigSH m | m `equal` ctrans m = eigSH' m 233eigSH m | m `equal` ctrans m = eigSH' m
219 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix" 234 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix"
220 235
236-- | Eigenvalues of a complex hermitian or real symmetric matrix.
237eigenvaluesSH :: Field t => Matrix t -> Vector Double
238eigenvaluesSH m | m `equal` ctrans m = eigenvaluesSH' m
239 | otherwise = error "eigenvaluesSH requires complex hermitian or real symmetric matrix"
240
221-- | Cholesky factorization of a positive definite hermitian or symmetric matrix using lapack's dpotrf or zportrf. 241-- | Cholesky factorization of a positive definite hermitian or symmetric matrix using lapack's dpotrf or zportrf.
222-- 242--
223-- If @c = chol m@ then @m == ctrans c \<> c@. 243-- If @c = chol m@ then @m == ctrans c \<> c@.