fork download
  1. newtonsMethod :: (Ord a, Num a, Fractional a, Floating a) => (a -> a) -> (a -> a) -> a -> a -> a
  2.  
  3. newtonsMethod f f' x precision
  4. | xIsGoodEnough = x
  5. | otherwise = newtonsMethod f f' x' precision
  6. where
  7. xIsGoodEnough = abs(f x) < precision
  8. x' = x - ((f x)/(f' x))
  9.  
  10. f = (\x -> cos(tan(sin(x))) - x )
  11. f' = (\x -> (-cos(x) * (1/cos(sin(x)))^2 * sin(tan(sin(x)))) - 1 )
  12.  
  13. main = print $ newtonsMethod f f' 1 1.0e-16
Success #stdin #stdout 0s 4628KB
stdin
Standard input is empty
stdout
0.7169229431689353