nth_root <- function ( a, n, tol = 1 / 1000 ) #*****************************************************************************80 # ## nth_root computes the n-th root of a number. # # Licensing: # # Copyright 2016 James P. Howard, II # # The computer code and data files on this web page are distributed under # https://opensource.org/licenses/BSD-2-Clause, the BSD-2-Clause license. # # Modified: # # 03 February 2020 # # Author: # # Original R version by James Howard. # Modifications by John Burkardt. # # Reference: # # James Howard, # Computational Methods for Numerical Analysis with R, # CRC Press, 2017 # ISBN13: 978-1-4987-2363-3. # # Input: # # real A: the number whose n-th root is desired. # # integer N: the root desired. # 2 <= N. # # real TOL; a convergence tolerance, with a default of 1/1000. # # Output: # # real X: the value of the n-th root of A. { x <- 1.0 deltax <- tol * 10.0 while ( abs ( deltax ) > tol ) { deltax <- ( 1.0 / n ) * ( a / x ^ ( n - 1 ) - x ) x <- x + deltax } return ( x ) }