RosettaCodeData/Task/Numerical-integration/OCaml/numerical-integration-1.ocaml
2023-07-01 13:44:08 -04:00

7 lines
217 B
Text

let integrate f a b steps meth =
let h = (b -. a) /. float_of_int steps in
let rec helper i s =
if i >= steps then s
else helper (succ i) (s +. meth f (a +. h *. float_of_int i) h)
in
h *. helper 0 0.