Sympy is returning multiple answers despite specifying positive answers only

Viewed 23

after specifying:

KEQ1,KEQ2,KEQ3,H2O, CO, CO2, H2, CH4  =s.symbols('KEQ1,KEQ2,KEQ3,H2O, CO, CO2, H2, CH4',positive=True)
~6 equations that I can't share~
s.nonlinsolve(functions,variables)

Sympy solves for H2O, CO, CO2, H2, CH4 properly and leaves them in terms of H2O and the KEQs, which is expected since two of the equations are linearly dependent. I know the KEQs and substitute them in.

However Sympy is returning two sets of solutions. I specified that all of the variables are positive. I don't know why this is, since it should be able to simplify any square roots based on the positive condition. If I can narrow it down to 6 linearly dependent equations I can just solve it numerically within an acceptable tolerance.

Thanks

1 Answers

A simple test shows that nonlinsolve does not pay attention to the attributes of the symbols:

enter image description here

So you will have to filter your results by hand.

Note, too, that you can use nsolve to solve a system of equations.

Related