gpt4 book ai didi

Python SymPy : Error while solving inequality

转载 作者:太空狗 更新时间:2023-10-29 20:31:12 24 4
gpt4 key购买 nike

问题: 我正在尝试解决不等式以获得变量 coeff_rw,它是满足不等式的符号 rw 的值.该值应根据以下代码中定义的其他符号(变量)。我首先求解方程,然后求解不等式(使用来自 this tutorial 的不等式求解器),但是,每次我使用任何求解器获取 coeff_rw 时,我都会得到一个 PolynomialErrortutorial 中所示.

import sympy as sym
#======= define variables as symbols
r, c1, c2, c3, c4, rh, rg, rw, cg, cw, a = sym.symbols('r, c1 c2 c3 c4 rh rg rw cg cw a') # cg = nablaP_g/(4*mu_g); cw = nablaP_w/(4*mu_w); a = mu_g/mu_w
#======= solve system of equations
coeffs = sym.solve((c1*(sym.log(rh)) + c2 + cg*(rh**2), \
c1*(sym.log(rg)) + c2 - c3*(sym.log(rg)) - c4 - (cw - cg)*(rg**2), \
(a*c1) - c3 - 2*(rg**2)*(cw - a*cg), \
c3*(sym.log(rw)) + c4 + cw*(rw**2)), c1, c2, c3, c4)
#======= solve qg and qw
qg = sym.integrate((cg*(r**2) + coeffs[c1]*(sym.log(r)) + coeffs[c2])*(2*sym.pi*r), (r, rh, rg))
qw = sym.integrate((cw*(r**2) + coeffs[c3]*(sym.log(r)) + coeffs[c4])*(2*sym.pi*r), (r, rg, rw))
#======= substitute rg=rh in qw
qwT = qw.subs(rg, rh)
#======= solve the inequality (qw >= qwT) to obtain rw
from sympy.solvers.inequalities import reduce_rational_inequalities
coeff_rw = reduce_rational_inequalities([[qw - qwT >= 0]], rw)]

问题:我想为上面代码中定义的不等式qw >= qwT 获取rw 的值。

最佳答案

有理函数是两个多项式的比率,因此仍然不允许对数。尝试

solve_univariate_inequality

但请注意,有些不等式很难解决。

关于Python SymPy : Error while solving inequality,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39981058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com