问题:我正在尝试解决不等式以获取变量coeff_rw
,这是满足不等式的符号rw
的值。此值应该是以下代码中定义的其他符号(变量)。我首先求解方程然后求解不等式(使用来自this tutorial的不等式求解器),然而,每当我使用任何求解器获得PolynomialError
时,我得到coeff_rw
。 tutorial
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)]
问题:我想获得上述代码中定义的不等式rw
的{{1}}值。
答案 0 :(得分:1)
有理函数是两个多项式的比率,因此仍然不允许日志。尝试
solve_univariate_inequality
但请注意,一些不平等很难解决。