题目如下:
代码如下:
def f(x):
y = x**5 - 15*x**4 + 85*x**3 -225*x**2 + 274*x - 121
return y
x1 = 1.5
x2 = 2.4
x3 = (x1+x2)/2
while abs(f(x3)) > 1e-6:
if f(x1) * f(x3) < 0:
x2 = x3
else:
x1 = x3
x3 = (x1 + x2)/2
print('{:.6f}'.format(x3))
运行测试如下:
3008