An example by Wilkinson[1963] shows that minute alterations in the coefficients of a polynomial may have massive effects on the roots. Let
f(x) = (x − 1)(x − 2) · · · (x − 20)
which has become known as the Wilkinson polynomial. Try to determine what happens to the zero
r = 20
when the function is altered tof(x) − 10^(−8) * x^19
. Hint: use secant method in double precision
所以我想做的是首先f
的零显然是整数1, 2, . . . , 20
。但是我认为我需要使用割线方法来定位(20, 21)
之间的零?我该怎么走?你知道吗
这是我的割线代码:
def SecantMethod(f,x0,x1,nmax,error):
for i in range(nmax):
if f(x1)-f(x0) == 0 or abs(f(x1)-f(x0)) <= error:
return x1
x2 = x1 - (f(x1)*(x1-x0))/(f(x1)-f(x0))
x0 = x1
x1 = x2
return x1
试着解释你的公式,我得到以下解释
迭代序列的结果输出
这是最好的实现作为情节
演示在浮点精度中,-776和752之间没有中间值。你知道吗
相关问题 更多 >
编程相关推荐