牛顿勘根法是计算平方跟的一个算法。
python代码实现如下:
def sqrt(n):
approx = n/2.0
better = (approx + n/approx)/2.0
while better != approx:
approx = better
better = (approx + n/approx)/2.0
return approx
牛顿勘根法是计算平方跟的一个算法。
python代码实现如下:
def sqrt(n):
approx = n/2.0
better = (approx + n/approx)/2.0
while better != approx:
approx = better
better = (approx + n/approx)/2.0
return approx