diff options
Diffstat (limited to 'lib/LinearAlgebra/Algorithms.hs')
-rw-r--r-- | lib/LinearAlgebra/Algorithms.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/LinearAlgebra/Algorithms.hs b/lib/LinearAlgebra/Algorithms.hs index 126549a..4ac6dde 100644 --- a/lib/LinearAlgebra/Algorithms.hs +++ b/lib/LinearAlgebra/Algorithms.hs | |||
@@ -19,6 +19,8 @@ module LinearAlgebra.Algorithms ( | |||
19 | pinv, | 19 | pinv, |
20 | pinvTol, | 20 | pinvTol, |
21 | pinvTolg, | 21 | pinvTolg, |
22 | nullspacePrec, | ||
23 | nullVector, | ||
22 | Normed(..), NormType(..), | 24 | Normed(..), NormType(..), |
23 | det, | 25 | det, |
24 | eps, i | 26 | eps, i |
@@ -240,3 +242,20 @@ instance Normed (Matrix Double) where | |||
240 | 242 | ||
241 | instance Normed (Matrix (Complex Double)) where | 243 | instance Normed (Matrix (Complex Double)) where |
242 | pnorm = pnormCM | 244 | pnorm = pnormCM |
245 | |||
246 | ----------------------------------------------------------------------- | ||
247 | |||
248 | -- | The nullspace of a real matrix from its SVD decomposition. | ||
249 | nullspacePrec :: Double -- ^ relative tolerance in 'eps' units | ||
250 | -> Matrix Double -- ^ input matrix | ||
251 | -> [Vector Double] -- ^ list of unitary vectors spanning the nullspace | ||
252 | nullspacePrec t m = ns where | ||
253 | (_,s,v) = svdR' m | ||
254 | sl@(g:_) = toList s | ||
255 | tol = (fromIntegral (max (rows m) (cols m)) * g * t * eps) | ||
256 | rank = length (filter (> g*tol) sl) | ||
257 | ns = drop rank (toColumns v) | ||
258 | |||
259 | -- | The nullspace of a real matrix, assumed to be one-dimensional, with default tolerance (shortcut for @last . nullspacePrec 1@). | ||
260 | nullVector :: Matrix Double -> Vector Double | ||
261 | nullVector = last . nullspacePrec 1 | ||