我正在尝试解决一个值数组,如以下代码中所述。但是我得到这个错误:
Traceback (most recent call last):
File "<ipython-input-842-cf2c76a38adb>", line 25, in <module>
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))
File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 148, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 227, in _root_hybr
ml, mu, epsfcn, factor, diag)
ValueError: The array returned by a function changed size between calls
它没有显示在代码中,但是T是一个先前解决的500个元素的数组。
P = 5000
x1 = np.linspace(0.1,1,500)
x2 = 1-x1
def VLE_2(y1,x1,T):
y2=1-y1
tau12 = a12+b12/T
tau21 = a21+b21/T
G12 = np.exp(-0.4*tau12)
G21 = np.exp(-0.4*tau21)
gamma_1 = np.exp((x2**2)*((tau21*G21**2)/(x1+x2*G21)**2+(tau12*G12)/(x2+x1*G12)**2))
gamma_2 = np.exp((x1**2)*((tau12*G12**2)/(x2+x1*G12)**2+(tau21*G21)/(x1+x2*G21)**2))
Psat1 = np.exp((106.1)-7614.8/T-12.686*np.log(T)+1.0733e-5*T**2)
Psat2 = np.exp((84.912)-6722.2/T-9.5157*np.log(T)+7.2244e-6*T**2)
#sol = np.zeros(2)
return y1*P - x1*gamma_1*Psat1
y1 = np.ones(500)
guess = 0.9
for i in range(0,500):
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))