Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Nth-root/R/nth-root.r
Normal file
12
Task/Nth-root/R/nth-root.r
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
nthroot <- function(A, n, tol=sqrt(.Machine$double.eps))
|
||||
{
|
||||
ifelse(A < 1, x0 <- A * n, x0 <- A / n)
|
||||
repeat
|
||||
{
|
||||
x1 <- ((n-1)*x0 + A / x0^(n-1))/n
|
||||
if(abs(x1 - x0) > tol) x0 <- x1 else break
|
||||
}
|
||||
x1
|
||||
}
|
||||
nthroot(7131.5^10, 10) # 7131.5
|
||||
nthroot(7, 0.5) # 49
|
||||
Loading…
Add table
Add a link
Reference in a new issue