Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

n-th Root Algorithm

What is the fastest way to calculate the n-th root of a number?

I'm aware of the Try and Fail method, but I need a faster algorithm.

like image 307
Alon Gubkin Avatar asked Dec 05 '22 01:12

Alon Gubkin


1 Answers

The canonical way to do this is Newton's Method. In case you don't know, the derivative of xn is nxn-1. This will come in handy. 1 is a good first guess. You want to apply it to the function a - xn

IIRC, it's superconvergent on functions of the form a - xn, but either way, it's quite fast. Also, IIRC, the warning in the wiki about it failing to converge would apply to more complex functions that have properties that the 'nice' functions you are interested in lack.

like image 102
aaronasterling Avatar answered Dec 19 '22 06:12

aaronasterling