我必须计算一个方程来翻译两个不同字段中的坐标。通过 Geogebra,我得出了这个方程,我检查过并且是正确的:
该方程的输入和输出如下:
输入 | 输出 |
---|---|
0 | 6 |
1 | 7 |
2 | 8 |
3 | 11 |
4 | 12 |
5 | 13 |
6 | 16 |
7 | 17 |
8 | 18 |
如前所述,方程是正确的。
为了测试这个方程,我将其实现到 python 中
import math
import colorful
def polynom(x):
return 0.0036 * pow(x,7) - 0.1 * pow(x,6) + 1.1 * pow(x,5) - 6 * pow(x,4) + 16.7583 * pow(x,3) - 21.9 * pow(x,2) + 11.1381 * x + 6
# To test the equation with the input and the expected output
for i in range (0,9):
result = polynom(i)
if result == exp[i]:
print(colorful.green(str(i) + " : " + str(result)))
else:
print(colorful.red(str(i) + " : " + str(result)))
奇怪的是,这个脚本给了我以下输出:
0 : 6.0
1 : 7.0
2 : 8.003399999999996
3 : 11.061599999999942
4 : 12.465999999999973
5 : 15.228000000000364
6 : 23.99099999999936
7 : 40.51839999999771
8 : 77.90159999999871
只有两个是正确的,而其余的给出了越来越奇怪的解决方案。
现在我的问题:
python 给你的结果是正确的。问题出在你的输入和预期输出表上。
我在 Wolfram 网站中检查了以下结果:
0.0036 * xˆ7 - 0.1 * xˆ6 + 1.1 * xˆ5 - 6 * xˆ4 + 16.7583 * xˆ3 - 21.9 * xˆ2 + 11.1381 * x + 6
:P(x)=8的方程结果链接,并且给我的结果与你的 python 测试相同。
我认为你需要重新计算你的产出预期。
我认为您已经从 GeoGebra 复制了方程,而没有增加舍入设置。尝试使用 15 位有效数字