diff options
author | Alberto Ruiz <aruiz@um.es> | 2008-01-22 11:13:38 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2008-01-22 11:13:38 +0000 |
commit | e92696514c8861e7bed7abb434ca24527861c05c (patch) | |
tree | 9a01571a13d4b95f37da3229055d92afce93b6a5 /examples/tests.hs | |
parent | 1bdc3af98f098f45e97e9c1a3225c5dcb64e3119 (diff) |
improved relative error in the tests
Diffstat (limited to 'examples/tests.hs')
-rw-r--r-- | examples/tests.hs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/tests.hs b/examples/tests.hs index e20f871..6bc1922 100644 --- a/examples/tests.hs +++ b/examples/tests.hs | |||
@@ -21,14 +21,16 @@ type CM = Matrix (Complex Double) | |||
21 | 21 | ||
22 | -- relative error | 22 | -- relative error |
23 | dist :: (Normed t, Num t) => t -> t -> Double | 23 | dist :: (Normed t, Num t) => t -> t -> Double |
24 | dist a b = f nab na nb | 24 | dist a b = r |
25 | where norm = pnorm Infinity | 25 | where norm = pnorm Infinity |
26 | na = norm a | 26 | na = norm a |
27 | nb = norm b | 27 | nb = norm b |
28 | nab = norm (a-b) | 28 | nab = norm (a-b) |
29 | f _ a 0 = a | 29 | mx = max na nb |
30 | f _ 0 b = b | 30 | mn = min na nb |
31 | f d a b = d / max a b | 31 | r = if mn < eps |
32 | then mx | ||
33 | else nab/mx | ||
32 | 34 | ||
33 | infixl 4 |~| | 35 | infixl 4 |~| |
34 | a |~| b = a :~10~: b | 36 | a |~| b = a :~10~: b |