Warm tip: This article is reproduced from stackoverflow.com, please click
python solver sympy

solving equations with simpy sympy.core.relational.Equality

发布于 2021-01-02 13:39:56

I have two equations in sympy.core.relational.Equality type: enter image description here

I also know that V_du = 250e-6. Analitically it is possible to substitute S on D and solve the equation for S. I want to know if there is any way to do it using sympy solvers.

Thank in advance

Questioner
guiprado
Viewed
0
mathfux 2020-08-28 18:42

At the beginning you have 3 variables unknown and 2 equations so you're able to solve it for S and D. There are contains 3 pairs of solutions of the form (f(V), g(V)) where f and g are expressions that contains V. Then you can iterate these pairs and use a substitution:

import sympy as sp
S, D, Vdu = sp.symbols('S D Vdu')

eq1 = sp.Eq(S, D)
eq2 = sp.Eq(Vdu, sp.pi**2*S*D**2/4)

solution = sp.solve((eq1, eq2), (S, D))
substituted_solution = [(s.subs({Vdu : 250e-6}), d.subs({Vdu : 250e-6})) for s, d in solution]