0
我想用一個最小二乘法找到適合下列數據的拋物線方程。下面的代碼工作顯然是錯誤的等式。我是否使用錯誤的功能來做到這一點?我的數組是(x,y)格式。拋物線擬合數據
import numpy as np
points = np.array ([(0.05, 0.957), (0.12, 0.851), (0.15, 0.832), (0.30, 0.720),
(0.45, 0.583), (0.70, 0.378), (0.84, 0.295), (1.05, 0.156)])
x = points[:,0]
y = points[:,1]
a = np.polyfit(x, y, 2)
b = np.poly1d(a)
print(a)
print (b)
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.plot(b)
plt.show()
b是可調用的,你可能想將它應用到x –