summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Algorithms.hs21
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
index 063bfc9..c7e7043 100644
--- a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
@@ -66,7 +66,7 @@ module Numeric.LinearAlgebra.Algorithms (
66 orth, 66 orth,
67-- * Norms 67-- * Norms
68 Normed(..), NormType(..), 68 Normed(..), NormType(..),
69 relativeError, 69 relativeError', relativeError,
70-- * Misc 70-- * Misc
71 eps, peps, i, 71 eps, peps, i,
72-- * Util 72-- * Util
@@ -719,11 +719,26 @@ instance Normed Matrix (Complex Float) where
719 pnorm Frobenius = pnorm PNorm2 . flatten 719 pnorm Frobenius = pnorm PNorm2 . flatten
720 720
721-- | Approximate number of common digits in the maximum element. 721-- | Approximate number of common digits in the maximum element.
722relativeError :: (Normed c t, Container c t) => c t -> c t -> Int 722relativeError' :: (Normed c t, Container c t) => c t -> c t -> Int
723relativeError x y = dig (norm (x `sub` y) / norm x) 723relativeError' x y = dig (norm (x `sub` y) / norm x)
724 where norm = pnorm Infinity 724 where norm = pnorm Infinity
725 dig r = round $ -logBase 10 (realToFrac r :: Double) 725 dig r = round $ -logBase 10 (realToFrac r :: Double)
726 726
727
728relativeError :: (Normed c t, Num (c t)) => NormType -> c t -> c t -> Double
729relativeError t a b = realToFrac r
730 where
731 norm = pnorm t
732 na = norm a
733 nb = norm b
734 nab = norm (a-b)
735 mx = max na nb
736 mn = min na nb
737 r = if mn < peps
738 then mx
739 else nab/mx
740
741
727---------------------------------------------------------------------- 742----------------------------------------------------------------------
728 743
729-- | Generalized symmetric positive definite eigensystem Av = lBv, 744-- | Generalized symmetric positive definite eigensystem Av = lBv,