x=np.arange(1,13,1)
y=np.array([17, 19, 21, 28, 33, 38, 37, 37, 31, 23, 19, 18 ])
plt.plot(x,y)
plt.show()

使用scipy.optimize 的curve_fit函数对观测值拟合

可以看出温度是以周期为12的正弦函数

#构建函数y=a*sin(x*pi/6+b)+c
#使用optimize.curve_fit函数求出a、b、c的值

x=np.arange(1,13,1)
x1=np.arange(1,13,0.1)
ymax=np.array([17, 19, 21, 28, 33, 38, 37, 37, 31, 23, 19, 18 ])

def fmax(x,a,b,c):
    return a*np.sin(x*np.pi/6+b)+c

fita,fitb=optimize.curve_fit(fmax,x,ymax,[1,1,1]) #[1,1,1]是初始化的参数
print(fita) #参数
print(fitb) #参数的协方差矩阵
plt.plot(x,ymax)
plt.plot(x1,fmax(x1,fita[0],fita[1],fita[2]))
plt.show()

使用scipy.optimize 的curve_fit函数对观测值拟合

相关文章:

  • 2021-06-14
  • 2023-03-11
  • 2022-12-23
  • 2021-04-05
  • 2021-05-23
  • 2021-05-21
  • 2021-07-19
  • 2022-12-23
猜你喜欢
  • 2021-11-06
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-07-04
相关资源
相似解决方案