python - 函数返回的数组在调用之间改变了大小
问题描述
我正在尝试解决一组值,如以下代码中所述。但我得到这个错误:
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]))
解决方案
推荐阅读
- java - 删除 launch4j 中的 java 选项
- kotlin - Kotlin jvm html DOCTYPE
- arrays - 如何在 Kotlin 中创建可以保存任何数据类型(包括空值)的空数组
- vue.js - DaisyUI:当语言切换到 RTL 之一时,如何将方向切换到 RTL?
- reactjs - 如何使用 history.push 传递多个参数?
- java - 将模块添加到项目时出错:非法字符:> 在索引 23
- python - 将一个张量乘以一个标量得到一个由 Nans 组成的张量
- java - IntelliJ 依赖项 - 规范和实现之间的差异
- c++ - 请求输入时强制用户输入特定模式
- vue.js - 获取上一张图片的宽度和高度,而不是刚刚上传的图片