用python牛顿迭代法制一个1到50的开方表
时间: 2024-03-06 13:49:34 浏览: 112
基于Python实现的牛顿迭代法求方程根
以下是使用牛顿迭代法制作1到50的开方表的Python代码:
```python
def newton_sqrt(n):
x = n
while True:
y = (x + n / x) / 2
if abs(y - x) < 0.0001:
break
x = y
return x
for i in range(1, 51):
sqrt_i = newton_sqrt(i)
print(f"The square root of {i} is {sqrt_i:.4f}")
```
输出结果如下:
```
The square root of 1 is 1.0000
The square root of 2 is 1.4142
The square root of 3 is 1.7321
The square root of 4 is 2.0000
The square root of 5 is 2.2361
The square root of 6 is 2.4495
The square root of 7 is 2.6458
The square root of 8 is 2.8284
The square root of 9 is 3.0000
The square root of 10 is 3.1623
The square root of 11 is 3.3166
The square root of 12 is 3.4641
The square root of 13 is 3.6056
The square root of 14 is 3.7417
The square root of 15 is 3.8729
The square root of 16 is 4.0000
The square root of 17 is 4.1231
The square root of 18 is 4.2426
The square root of 19 is 4.3589
The square root of 20 is 4.4721
The square root of 21 is 4.5826
The square root of 22 is 4.6904
The square root of 23 is 4.7958
The square root of 24 is 4.8990
The square root of 25 is 5.0000
The square root of 26 is 5.0990
The square root of 27 is 5.1962
The square root of 28 is 5.2915
The square root of 29 is 5.3852
The square root of 30 is 5.4772
The square root of 31 is 5.5678
The square root of 32 is 5.6569
The square root of 33 is 5.7446
The square root of 34 is 5.8310
The square root of 35 is 5.9161
The square root of 36 is 6.0000
The square root of 37 is 6.0828
The square root of 38 is 6.1644
The square root of 39 is 6.2450
The square root of 40 is 6.3246
The square root of 41 is 6.4031
The square root of 42 is 6.4807
The square root of 43 is 6.5574
The square root of 44 is 6.6332
The square root of 45 is 6.7082
The square root of 46 is 6.7823
The square root of 47 is 6.8557
The square root of 48 is 6.9282
The square root of 49 is 7.0000
The square root of 50 is 7.0711
```
阅读全文