牛顿勘根法是计算平方跟的一个算法。
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实现代码。该方法通过迭代逼近的方式找到平方根的近似值。
牛顿勘根法是计算平方跟的一个算法。
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
被折叠的 条评论
为什么被折叠?