Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Euler-method/OCaml/euler-method-2.ocaml
Normal file
24
Task/Euler-method/OCaml/euler-method-2.ocaml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(* Wrapping up the parameters in a "cool" function: *)
|
||||
let cool = euler (newton_cooling ~k:0.07 ~tr:20.)
|
||||
|
||||
(* Similarly for the analytic solution: *)
|
||||
let analytic = analytic_solution ~k:0.07 ~tr:20. ~t0:100.
|
||||
|
||||
(* (Just a loop) Apply recurrence function on state, until some condition *)
|
||||
let recur ~until f state =
|
||||
let rec loop s =
|
||||
if until s then ()
|
||||
else loop (f s)
|
||||
in loop state
|
||||
|
||||
(* 'results' generates the specified output starting from initial values t=0, temp=100C; ending at t=100s *)
|
||||
let results fn =
|
||||
Printf.printf "\t time\t euler\tanalytic\n%!";
|
||||
let until (t,y) =
|
||||
Printf.printf "\t%7.3f\t%7.3f\t%9.5f\n%!" t y (analytic t);
|
||||
t >= 100.
|
||||
in recur ~until fn (0.,100.)
|
||||
|
||||
results (cool ~step:10.)
|
||||
results (cool ~step:5.)
|
||||
results (cool ~step:2.)
|
||||
Loading…
Add table
Add a link
Reference in a new issue