I'm trying to solve the following equation using sympy:
.
The code I am using to find the solution to the equation for Vr is the following:
import sympy as sp
Vr, Vs, gamma, l, Zc, P, Q = sp.symbols('Vr Vs gamma l Zc P Q', complex=true)
eqn = sp.Eq(abs(Vr)**2 - sp.conjugate(Vr) * Vs/sp.cosh(gamma * l) + Zc*(P - 1j*Q)*sp.tanh(gamma * l), 0)
S = sp.solve(eqn, Vr)
print(S)
When I run it I get the following error:
NotImplementedError Traceback (most recent call last)
<ipython-input-1-4eabc418c1ea> in <cell line: 10>()
8
9 # Resuelve la ecuación
---> 10 S = sp.solve(eqn, Vr)
11
12 # Imprime la solución
/usr/local/lib/python3.10/dist-packages/sympy/solvers/solvers.py in solve(f, *symbols, **flags)
1005 for e in fi.find(Abs):
1006 if e.has(*symbols):
-> 1007 raise NotImplementedError('solving %s when the argument '
1008 'is not real or imaginary.' % e)
1009
NotImplementedError: solving Abs(Vr) when the argument is not real or imaginary.
The problem seems to be related to the fact that the equation is complex and as I tried by removing the magnitude of the term |Vr|^2 the code solves the equation.
I want to know if there is another library that allows me to solve the equation or if I am implementing the code incorrectly.
If you use
V*conjugate(V)rather thanabs(V)then you can get an answer from solve. It is much faster if you disable checking: