【发布时间】:2018-06-07 06:50:33
【问题描述】:
我正在尝试使用以下代码拟合一些数据:
import numpy as np
import scipy.optimize
import matplotlib.pyplot as plt
def fseries(x, a0, a1, b1, w):
f = a0 + (a1 * np.cos(w * x)) + (b1 * np.sin(w * x))
return f
x = np.arange(0, 10)
y = [-45.0, -17.0, -33.0, 50.0, 48.0, -3.0, -1.0, 2.0, 84.0, 71.0]
res = scipy.optimize.curve_fit(fseries, x, y, maxfev=10000)
xt = np.linspace(0, 10, 100)
yt = fseries(xt, res[0][0], res[0][1], res[0][2], res[0][3])
plt.plot(x,y)
plt.plot(xt, yt, 'r')
plt.show()
这使得这个情节:
对我不理解或做错了什么有什么想法?
【问题讨论】:
-
它并没有那么糟糕,只是你在每个系列中的样本数量严重不匹配,即 n=10 与 n=100 相比,所以当 n=100 时你有更多的空白填充
标签: python-3.x scipy curve-fitting