def f(x):
return x**2 - n
def fd(x):
return 2*x
def newton(f, fd, k):
x = n/2
for i in range(100):
g = x - f(x)/fd(x)
if abs(x - g) < k:
print i
break
x = g
print i, x
while True:
try:
n = float(input("please input a number:"))
newton(f, fd, 1e-10)
except NameError:
break
python 牛顿迭代小游戏
最新推荐文章于 2024-05-26 23:31:43 发布