提问人: 提问时间:11/3/2023 最后编辑:tripleee 更新时间:11/3/2023 访问量:85
使用 while 循环找到 f(x)=x^2 – 50 的根
Find the root of f(x)=x^2 – 50 using a while loop
问:
我有这个作业。但我不知道该怎么做。
我们用一个循环来做到这一点。for
f=lambda x: (x**2)-27
fd=lambda x:x*2
a=50
for i in range(1,100):
a = a - (f(a)/fd(a))
print(i, ". root in step - ", a)
我认为我们被要求把它变成一个循环并做到这一点。while
答:
1赞
blhsing
11/3/2023
#1
循环应继续进行,直到每个步骤之间的增量小于浮点数的精度:while
a = 50
while a > (a := a - f(a) / fd(a)):
print(a)
这将输出:
25.27
13.169230312623665
7.609732014284865
5.578910083156939
5.2092825345429645
5.196168970075266
5.19615242273298
5.196152422706632
评论
f(a)