<p>到目前为止,我所拥有的一切,都要感谢许多帮助过我的人:</p>
<pre><code>#defining function that applies the binding model to the data
def binding_model(xdata, Vcell, Ka, n, dH):
#packaging Mt and Xt into one object to abide by curve_fit rules
#avoiding 'divide by 0' errors by truncating lists
Mt[1:] = xdata[0]
Xt[1:] = xdata[1]
#breaking up the equation for simplicity
a = n*Mt*dH*Vcell/2
b = 1+(Xt/(Mt*n))
c = 1/(n*Ka*Mt)
d = 1+(Xt/(n*Mt))+(1/(n*Ka*Mt))
e = 4*Xt/(Mt*n)
#combining variables into the whole equation
return a*(b+c)-(d**2-e**.5)
#fitting molar enthalpy vs. molar ratio data with the binding model
initial_Vcell = 0
initial_Ka = 0
initial_n = 0
initial_dH = 0
initial_paramaters = np.array([initial_Vcell, initial_Ka, initial_n,
initial_dH])
xdata = zip(Mt, Xt)
xdata = np.array(xdata)
parameters, cov = curve_fit(binding_model, xdata, peak_areas, p0=
initial_paramaters)
Vcell = parameters[0]
Ka = parameters[1]
n = parameters[2]
dH = parameters[3]
Ffit = binding_model(xdata, Vcell, Ka, n, dH)
</code></pre>
<p>退货:</p>
<pre><code> File "mygroatitc.py", line 164, in binding_model
Mt[1:] = xdata[0]
ValueError: could not broadcast input array from shape (2) into shape (40)
</code></pre>
<p>有没有人有使用曲线拟合或压缩变量来发现我的错误的经验?你知道吗</p>
<p>Vcell是一个整数,Mt和Xt是大小相等的数组,peak_area(与Mt或Xt大小相等的数组)是curve_fit函数中的y数据。你知道吗</p>