import Data.List (find)
+import Vector
+
import qualified Roots.Fast as F
-- | Does the (continuous) function @f@ have a root on the interval
-> 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
-- 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 =
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}.