Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Nth-root/OCaml/nth-root.ocaml
Normal file
12
Task/Nth-root/OCaml/nth-root.ocaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
let nthroot ~n ~a ?(tol=0.001) () =
|
||||
let nf = float n in let nf1 = nf -. 1.0 in
|
||||
let rec iter x =
|
||||
let x' = (nf1 *. x +. a /. (x ** nf1)) /. nf in
|
||||
if tol > abs_float (x -. x') then x' else iter x' in
|
||||
iter 1.0
|
||||
;;
|
||||
|
||||
let () =
|
||||
Printf.printf "%g\n" (nthroot 10 (7131.5 ** 10.0) ());
|
||||
Printf.printf "%g\n" (nthroot 5 34.0 ());
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue