[Edu-sig] Halley's Method for nth root of P

Kirby Urner pdx4d@teleport.com
Fri, 12 May 2000 22:37:14 -0700


From the same web page source, this one converges
faster than Halley's looks like.

  def if1(P,n,d=10,x=1.0):
	if d>1:		
	   newx = (((2.0*n-1)*P*x**n + P**2) /
	           ((x**(2*n-1))+(2*n-1)*P*x**(n-1)))
   	   return if1(P,n,d-1,newx)
	else:
	   return x

For computing the nth root of P, as in 

>>> if1(500,2)  # 2nd root of 500
22.360679775
>>> 500 ** 0.5
22.360679775

Kirby