尝试将数据拟合到 7 个参数的二次指数函数中

问题描述 投票:0回答:0

这里有一些时间 t 的数据和相应的 f(t) 值。

time_before = [0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.25, 0.3, 0.35, 0.4, 0.5, 0.6, 0.8, 1, 1.5, 2, 3, 4.5, 6] #in min/10 time_after = [np.exp(-z) for z in xx] Cp_data = [2.148738, 24.88158, 61.81409, 82.55928, 79.09638, 79.45628, 28.19074, 18.6571, 16.04993, 14.16715, 11.87659, 9.680828, 7.948303, 8.233573, 7.285041, 6.576602, 6.100967, 5.581709, 5.389457]

我正在尝试将其放入函数中:

`

def Cp(x, A1, A2, A3, L1, L2, L3, L4):   
    if Cp.count!=-1 :
        Cp.count += 1
    L=[]
    if Cp.count > 1 :
         print(f"Iteration {Cp.count-1}: A1 = {A1}, A2 = {A2}, A3 = {A3},L1 = {L1}, L2 = {L2}, L3 = {L3}, L4= {L4}")
    for t in x:
         L.append(A1 * t**L1 + A2 * t**L2 + A3 * t**L3 - (A1+A2+A3)*t**L4)
    return L`

所以最后,Cp(t) 函数给出:

Cp(t) = A1 * exp(-L1t) + A2 * exp(-L2t) + A3 * exp(-L3t) - (A1+A2+A3)exp(-L4t) `

想法是减少时间(time_before 已经除以 10)并将 exp(-t) 作为时间范围(在“time after”列表中),以便适合的函数是 exp 的多项式( -t),我猜这会提高准确性。

但问题是 python 上的 curve_fit 模块不起作用,因为“ValueError:模型函数生成 NaN 值并且拟合中止!请检查您的模型函数和/或在适用的参数上设置边界。在这种情况下,使用“nan_policy='omit'”可能不起作用。”

你能帮我从数据中得到一个拟合函数吗?

谢谢!

python curve-fitting data-fitting
© www.soinside.com 2019 - 2024. All rights reserved.