Runge-Kutta method: Difference between revisions

Content deleted Content added
OCaml implementation
Line 412: Line 412:
=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>let y' t y = t *. sqrt y
<lang ocaml>let y' t y = t *. sqrt y
let exact t = let u = 0.25*.t*.t +.1.0 in u*.u
let exact t = let u = 0.25*.t*.t +. 1.0 in u*.u


let rk4_step (y,t) h =
let rk4_step (y,t) h =
Line 423: Line 423:
let rec loop h n (y,t) =
let rec loop h n (y,t) =
if n mod 10 = 1 then
if n mod 10 = 1 then
Printf.printf "t = %f,\ty = %f,\terr = %g\n" t y (abs_float (y-.exact t));
Printf.printf "t = %f,\ty = %f,\terr = %g\n" t y (abs_float (y -. exact t));
if n < 102 then loop h (n+1) (rk4_step (y,t) h)
if n < 102 then loop h (n+1) (rk4_step (y,t) h)