tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
6
Task/Nth-root/Erlang/nth-root-1.erl
Normal file
6
Task/Nth-root/Erlang/nth-root-1.erl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
fixed_point(F, Guess, Tolerance) ->
|
||||
fixed_point(F, Guess, Tolerance, F(Guess)).
|
||||
fixed_point(_, Guess, Tolerance, Next) when abs(Guess - Next) < Tolerance ->
|
||||
Next;
|
||||
fixed_point(F, _, Tolerance, Next) ->
|
||||
fixed_point(F, Next, Tolerance, F(Next)).
|
||||
4
Task/Nth-root/Erlang/nth-root-2.erl
Normal file
4
Task/Nth-root/Erlang/nth-root-2.erl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
nth_root(N, X) -> nth_root(N, X, 1.0e-5).
|
||||
nth_root(N, X, Precision) ->
|
||||
F = fun(Prev) -> ((N - 1) * Prev + X / math:pow(Prev, (N-1))) / N end,
|
||||
fixed_point(F, X, Precision).
|
||||
Loading…
Add table
Add a link
Reference in a new issue