Skip to content

Instantly share code, notes, and snippets.

@PhDP
Created June 24, 2013 12:42
Show Gist options
  • Save PhDP/5849775 to your computer and use it in GitHub Desktop.
Save PhDP/5849775 to your computer and use it in GitHub Desktop.
The bisection algorithm in Haskell.
bisection f a b e = if a < b then bis a b else bis b a
where err = if e < 1e-15 then 1e-15 else e
bis a b = let d = (b - a) / 2; m = (b + a) / 2 in
if d < err then
m
else if f a * f m < 0.0 then
bis a m
else
bis m b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment