+
+
+
+-- | The sequence x_{n} of values obtained by applying Newton's method
+-- on the function @f@ and initial guess @x0@.
+newton_iterations :: (Fractional a, Ord a)
+ => (a -> a) -- ^ The function @f@ whose root we seek
+ -> (a -> a) -- ^ The derivative of @f@
+ -> a -- ^ Initial guess, x-naught
+ -> [a]
+newton_iterations f f' x0 =
+ iterate next x0
+ where
+ next xn =
+ xn - ( (f xn) / (f' xn) )
+
+
+
+newtons_method :: (Fractional a, Ord a)
+ => (a -> a) -- ^ The function @f@ whose root we seek
+ -> (a -> a) -- ^ The derivative of @f@
+ -> 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
+ where
+ x_n = newton_iterations f f' x0