指数拟合返回不合理的振幅,但绘制时看起来不错

问题描述

我正在尝试拟合我的指数数据,但无法获得一个不错的答案。我正在使用scipy和以下代码

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import glob
import scipy.optimize
import pylab


def exponential(x,a,k,b):
    return a*np.exp(-x/k) + b
def main():
    filename = 'tek0071ALL.csv'
    df = pd.read_csv(filename,skiprows=14)
    t = df['TIME']
    ch3 = df['CH3']
    idx1 = df.index[df['TIME']==-0.32]
    idx2 = df.index[df['TIME']==-0.18]

    t= t[idx1.values[0]:idx2.values[0]]
    data=ch3[idx1.values[0]:idx2.values[0]]
    popt_exponential,pcov_exponential = scipy.optimize.curve_fit(exponential,t,data,p0=[1,.1,0])
   # print(popt_exponential,pcov_exponential)

    print(popt_exponential[0])
    print(popt_exponential[1])
    print(popt_exponential[2])
    plt.plot(t,'.')
    plt.plot(t,exponential(t,popt_exponential[0],popt_exponential[1],popt_exponential[2]))
    plt.show()
    plt.legend(['Data','Fit'])
main()

这是合适的样子:

enter image description here

,我认为这实际上很合适。我认为我的时间常数是正确的,这就是我要提取内容。但是,振幅确实给我带来了麻烦-通过检查,我希望振幅约为0.5,但是我得到了方程A*exp(-t/K)+C的以下值:

A:1.2424893552249658e-07
K:0.0207112474466181
C: 0.010623336832120528

我只是想知道这是否正确,而我的振幅确实应该小得足以说明指数行为。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)