user238469
user238469

Reputation:

Python SymPy: Error while solving inequality

Problem: I am trying to solve an inequality to obtain a variable coeff_rw, which is the value of the symbol rw satisfying the inequality. This value should be in terms of other symbols (variables) that are defined in the following code. I am first solving the equations and then the inequality (using the inequality solvers from this tutorial), however, I get a PolynomialError each time I use any solver to obtain coeff_rw as given in the 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)]

Question: I would like to obtain the value of rw for the inequality qw >= qwT as defined in the above code.

Upvotes: 10

Views: 1125

Answers (1)

kabanus
kabanus

Reputation: 26005

A rational function is a ratio of two polynomials, so a log is still not allowed. Try

solve_univariate_inequality

but note some inequalities are hard to solve.

Upvotes: 1

Related Questions