Skip to content

Instantly share code, notes, and snippets.

@sergiilagutin
Created March 9, 2016 17:58
Show Gist options
  • Save sergiilagutin/3eb97b452e2718bb4a2d to your computer and use it in GitHub Desktop.
Save sergiilagutin/3eb97b452e2718bb4a2d to your computer and use it in GitHub Desktop.
Trapezoidal rule
integration :: (Double -> Double ) -> Double -> Double -> Double
integration f a b = let
step = (b-a)/1000
helper acc 0 x = acc
helper acc cnt x =
helper (acc + ((f x) + (f next))/2 * step) (cnt - 1) next
where next = x + step
in helper 0 1000 a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment