Guest User

Untitled

a guest
May 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.29 KB | None | 0 0
  1.  
  2. let accuracy = 0.00001
  3.  
  4. let rec iterate x a =
  5.     let diff = x - a*a
  6.     if abs diff <= accuracy then
  7.         a
  8.     else
  9.         iterate x ((a + x/a) / 2.0)
  10.  
  11. let newtonSqrt x =
  12.     iterate x (x/2.0)
  13.  
  14. let squared = 10.0
  15. printfn "square root of %A = %A" squared (newtonSqrt squared)
Add Comment
Please, Sign In to add comment