[英]Parameters undefined using lmfit
I am trying to fit a curve to the equation below with the given data. 我正在尝试使用给定的数据拟合以下方程式的曲线。 The equation is Rate=k*Concentration^n
. 公式为Rate=k*Concentration^n
。 I am having trouble as the n
when fitted is -6
, which is not possible so I am trying to set a bound at min=0
. 我遇到麻烦,因为拟合时的n
为-6
,这是不可能的,所以我试图将限制设置为min=0
。 However, I am getting a undefined term parameter errors. 但是,我得到了未定义的术语参数错误。 Any help would be great thanks. 任何帮助将非常感谢。
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()
parameters
is undefined because you do not define it anywhere. parameters
未定义,因为您没有在任何地方定义它。 You use it as params = parameters()
, probably implying a function call, but you do not define or import that function.... Similarly, par
is undefined because you do not define it anywhere. 您可以将其用作params = parameters()
,可能意味着调用了函数,但是您没有定义或导入该函数。...类似地, par
是未定义的,因为您未在任何地方定义它。
You almost certainly want 您几乎可以肯定想要
from lmfit import Model, Parameters # explicitly import Parameters
params = Parameters() # note the capitalization
params.add('k', value=0.001)
params.add('n', value=0.001)
what is less clear (because I cannot guess what par
is) is whether you want 不太清楚(因为我无法猜出什么是par
)的是你是否想要
params['k'].min = 0
or 要么
params['n'].min = 0
Also, just as a warning: Since your time[0]
is 0, your Rate[0]
will be infinite, which will cause trouble when running the fit. 同样,作为警告:由于您的time[0]
为0,因此您的Rate[0]
将是无限的,这会在进行拟合操作时造成麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.