Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 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