diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-23 10:51:16 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-23 10:51:16 +0200 |
commit | 0a9ef8f5b0088c1ac25175bffca4ed95d9e109a5 (patch) | |
tree | 7bd461ebbf140804e470ae03bb3a2e29bdd935e2 /packages/base/src/Numeric/LinearAlgebra/Algorithms.hs | |
parent | 109fa7d25779e331356bbe310755c10eddfeb235 (diff) |
relativeError, cgSolve'
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Algorithms.hs | 21 |
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. |
722 | relativeError :: (Normed c t, Container c t) => c t -> c t -> Int | 722 | relativeError' :: (Normed c t, Container c t) => c t -> c t -> Int |
723 | relativeError x y = dig (norm (x `sub` y) / norm x) | 723 | relativeError' 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 | |||
728 | relativeError :: (Normed c t, Num (c t)) => NormType -> c t -> c t -> Double | ||
729 | relativeError 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, |