From: Michael Orlitzky Date: Sun, 14 Oct 2012 18:05:59 +0000 (-0400) Subject: Change the type signature of fixed_point to work on Vectors. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=28229a385d660108f9cc87e307512a07d6356b98;p=numerical-analysis.git Change the type signature of fixed_point to work on Vectors. --- 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}.