Python中的曲线拟合不适合我的曲线

时间:2014-12-12 22:20:04

标签: python graph

我目前正在对要输入的某些数据进行曲线拟合。我的功能是(其中Ti是最初的热温度Ta是冷温度,c是半衰期):

def extract_parameters(Ts, ts):
    def model(t, Ti, Ta, c):
        return (Ti - Ta)*math.e**(-t / c) + Ta
    popt, pcov = cf(model, ts, Ts, p0 = (10, 7, 6))
    Ti, Ta, c = popt
    xfine = np.linspace(0, 10, 101)
    yfitted = model(xfine, *popt)
    pl.plot(Ts, ts, 'o', label = 'data point')
    pl.plot(xfine, yfitted, label = 'fit')
    pylab.legend()
    pylab.show() 

当我进入时:

extract_parameters(np.array([1,2,3,4,5,6,7,8,9,10]), np.array([10.0,9.0,8.5,8.0,7.5,7.3,7.0,6.8,6.6,6.3]))

我的图表开始适合最后但是当我的数据从10开始时,我的曲线从大约240开始然后向下扫描,这不是我想要的。我认为设置p0会有所帮助,但它似乎没有任何帮助。

example of failed fit

1 个答案:

答案 0 :(得分:1)

您已将参数中的Tsts换成cf。它应该是Ts(自变量),后跟ts(因变量)。

popt, pcov = cf(model, Ts, ts, p0 = (10, 7, 6))
相关问题