Skip to main content
added 242 characters in body
Source Link
Doug Currie
  • 41.4k
  • 1
  • 103
  • 121

Here it is in Lua using Newton-Raphson method

> function nthroot (x, n) local r = 1; for i = 1, 16 do r = (((n - 1) * r) + x / (r ^ (n - 1))) / n end return r end > return nthroot(125,3) 5 > 

Python version

>>> def nthroot (x, n): ... r = 1 ... for i in range(16): ... r = (((n - 1) * r) + x / (r ** (n - 1))) / n ... return r ... >>> nthroot(125,3) 5 >>> 

Here it is in Lua using Newton-Raphson method

> function nthroot (x, n) local r = 1; for i = 1, 16 do r = (((n - 1) * r) + x / (r ^ (n - 1))) / n end return r end > return nthroot(125,3) 5 > 

Here it is in Lua using Newton-Raphson method

> function nthroot (x, n) local r = 1; for i = 1, 16 do r = (((n - 1) * r) + x / (r ^ (n - 1))) / n end return r end > return nthroot(125,3) 5 > 

Python version

>>> def nthroot (x, n): ... r = 1 ... for i in range(16): ... r = (((n - 1) * r) + x / (r ** (n - 1))) / n ... return r ... >>> nthroot(125,3) 5 >>> 
Source Link
Doug Currie
  • 41.4k
  • 1
  • 103
  • 121

Here it is in Lua using Newton-Raphson method

> function nthroot (x, n) local r = 1; for i = 1, 16 do r = (((n - 1) * r) + x / (r ^ (n - 1))) / n end return r end > return nthroot(125,3) 5 >