Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
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.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
let methods = [
|
||||
( "rect_l", fun f x _ -> f x);
|
||||
( "rect_m", fun f x h -> f (x +. h /. 2.) );
|
||||
( "rect_r", fun f x h -> f (x +. h) );
|
||||
( "trap", fun f x h -> (f x +. f (x +. h)) /. 2. );
|
||||
( "simp", fun f x h -> (f x +. 4. *. f (x +. h /. 2.) +. f (x +. h)) /. 6. )
|
||||
]
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let functions = [
|
||||
( "cubic", (fun x -> x*.x*.x), 0.0, 1.0, 100);
|
||||
( "recip", (fun x -> 1.0/.x), 1.0, 100.0, 1000);
|
||||
( "x to 5e3", (fun x -> x), 0.0, 5000.0, 5_000_000);
|
||||
( "x to 6e3", (fun x -> x), 0.0, 6000.0, 6_000_000)
|
||||
]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
let () =
|
||||
List.iter (fun (s,f,lo,hi,n) ->
|
||||
Printf.printf "Testing function %s:\n" s;
|
||||
List.iter (fun (name,meth) ->
|
||||
Printf.printf " method %s gives %.15g\n" name (integrate f lo hi n meth)
|
||||
) methods
|
||||
) functions
|
||||
Loading…
Add table
Add a link
Reference in a new issue