Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created January 29, 2014 10:22
Show Gist options
  • Save kunishi/8685213 to your computer and use it in GitHub Desktop.
Save kunishi/8685213 to your computer and use it in GitHub Desktop.
fun trap(a, b, n, F) =
if n <= 0 orelse b-a <= 0.0 then 0.0
else
let
val delta = (b-a)/real(n)
in
delta * (F(a) + F(a+delta))/2.0 +
trap(a+delta, b, n-1, F)
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment