tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
15
Task/Nth-root/Java/nth-root-2.java
Normal file
15
Task/Nth-root/Java/nth-root-2.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
public static double nthroot(int n, double x) {
|
||||
assert (n > 1 && x > 0);
|
||||
int np = n - 1;
|
||||
double g1 = x;
|
||||
double g2 = iter(g1, np, n, x);
|
||||
while (g1 != g2) {
|
||||
g1 = iter(g1, np, n, x);
|
||||
g2 = iter(iter(g2, np, n, x), np, n, x);
|
||||
}
|
||||
return g1;
|
||||
}
|
||||
|
||||
private static double iter(double g, int np, int n, double x) {
|
||||
return (np * g + x / Math.pow(g, np)) / n;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue