【发布时间】:2018-11-24 08:37:18
【问题描述】:
我想通过给出值来生成一个多项式方程并得到一个方程。然而,当我用给定的 x 值控制它时,我从方程中得到不同的值,这是我的代码和输出:
points = np.array([(1, 1), (2, 4), (3, 1), (9, 3)])
x = points[:,0]
y = points[:,1]
# calculate polynomial
z = np.polyfit(x, y, 2)
f = np.poly1d(z)
它给了我这个等式:-0.001416*x^2 + 0.1504*x + 1.72
输出
x expected(y) returned(y)
1 1 1.868984
2 4 2.015136
3 1 2.158456
9 3 2.9589040000000004
是我错了还是我读错了?
【问题讨论】:
-
一个流行的 Python 绘图库是Matplotlib。
标签: python python-3.x numpy