From 28229a385d660108f9cc87e307512a07d6356b98 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 14 Oct 2012 14:05:59 -0400 Subject: [PATCH] Change the type signature of fixed_point to work on Vectors. --- src/Roots/Simple.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Roots/Simple.hs b/src/Roots/Simple.hs index 79750e8..5aed7a1 100644 --- a/src/Roots/Simple.hs +++ b/src/Roots/Simple.hs @@ -11,6 +11,8 @@ where import Data.List (find) +import Vector + import qualified Roots.Fast as F -- | Does the (continuous) function @f@ have a root on the interval @@ -128,8 +130,8 @@ newtons_method :: (Fractional a, Ord a) -> a -- ^ The tolerance epsilon -> a -- ^ Initial guess, x-naught -> Maybe a -newtons_method f f' epsilon x0 - = find (\x -> abs (f x) < epsilon) x_n +newtons_method f f' epsilon x0 = + find (\x -> abs (f x) < epsilon) x_n where x_n = newton_iterations f f' x0 @@ -225,9 +227,9 @@ fixed_point_iterations f x0 = -- f(f(x0)),... such that the magnitude of the difference between it -- and the next element is less than epsilon. -- -fixed_point :: (Num a, Ord a) +fixed_point :: (Num a, Vector a, RealFrac b) => (a -> a) -- ^ The function @f@ to iterate. - -> a -- ^ The tolerance, @epsilon@. + -> b -- ^ The tolerance, @epsilon@. -> a -- ^ The initial value @x0@. -> a -- ^ The fixed point. fixed_point f epsilon x0 = @@ -236,8 +238,7 @@ fixed_point f epsilon x0 = xn = fixed_point_iterations f x0 xn_plus_one = tail $ fixed_point_iterations f x0 - abs_diff v w = - abs (v - w) + abs_diff v w = norm (v - w) -- The nth entry in this list is the absolute value of x_{n} - -- x_{n+1}. -- 2.43.2