Created
June 6, 2014 07:59
-
-
Save vigdorchik/3c9a6d5e31cc4059ca7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude> let eps = 0.00000001 | |
Prelude> let fix f x_1 x_2 = let f_x = x_1 - (f x_1)*(x_1 - x_2)/((f x_1) - (f x_2)) in if abs (f_x - x_1) < eps then f_x else fix f f_x x_1 | |
Prelude> let root a = fix ((flip (-)) a . flip (^) 3) (a-1) (a+1) | |
Prelude> root 27 | |
3.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prelude> let eps = 0.00000001
Prelude> let n = 10000
Prelude> let fix f x y m = let z = x - (f x)*(x-y)/((f x) - (f y)) in if abs (z - x) < eps || m>n then z else fix f z x (m+1)
Prelude> let root a = fix ((flip (-)) a . flip (^) 3) (a-1) (a+1) 0
Prelude> root 27
3.0
Prelude> root 6000000000000000000000000
NaN