Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Task1_2 where
  2.  
  3. newtonMethod :: (Double -> Double) -> (Double -> Double) -> Double -> Double -> Double
  4. newtonMethod f df x eps
  5.   | abs (xNext - x) < eps = f xNext
  6.   | otherwise             = newtonMethod f df xNext eps
  7.   where xNext = x - (f x) / (df x)
  8.  
  9.  
  10. goldenSection :: (Double -> Double) -> Double -> Double -> Double -> Double
  11. goldenSection f a b eps
  12.   | abs (b - a) < eps     = f ((a + b) /2)
  13.   | f xFirst >= f xSecond = goldenSection f xFirst b eps
  14.   | otherwise             = goldenSection f a xSecond eps
  15.   where xFirst  = b - ((b - a) / psi)
  16.         xSecond = a + ((b - a) / psi)
  17.         psi     = (1 + sqrt 5) / 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement