我试图用给定的数据将曲线拟合到下面的等式。方程是Rate=k*Concentration^n
。我n
在安装时遇到了麻烦-6
,这是不可能的,所以我试图设置一个界限min=0
。但是,我收到未定义的术语参数错误。任何帮助都会非常感谢。
from IPython import get_ipython
get_ipython().magic('reset -sf')
import numpy as np
from lmfit import Model
import matplotlib.pyplot as plt
# Homework Problem #2
Time = np.array ([0, 48, 76, 124, 204, 238, 289])
Concentration =np.array ([19.04, 17.6, 16.9, 15.8, 14.41, 13.94, 13.37])
# Rate Determination
Rate=Concentration/Time
# Model Definition
def rateEq(Concentration, k, n):
return k*(Concentration)**n
# Model creation
model=Model(rateEq)
# Parameters
params = parameters()
params.add(k=0.001)
params.add(n=0.001)
par.set(min=0)
# Data Fit v
result=model.fit(Rate, params, Concentration=Concentration)
# Print and Plot Results
print(result.fit_report())
result.plot_fit()