0
from sympy import *

x = symbols('x', real=True)

solve(Abs(2 + 36/(x - 2)) - 6)

I've already set real=True, but it still says solving Abs(2 + 36/(x - 2)) when the argument is not real or imaginary.

However, solving Abs(36/(x - 2)) - 6 is fine.

What's the problem?

k1eran
  • 3
  • 1

1 Answers1

0

Sometimes, dealing with Abs leads to "suprise" moments, like you experienced. For your particular case, a possible way to make it works is to manipulate the expression. In particular, make abs(x / y) = abs(x) / abs(y):

from sympy import *
x = symbols('x', real=True)
expr = Abs(2 + 36/(x - 2)) - 6
expr = expr.simplify()

def repl_Abs(t):
    num, den = fraction(t)
    return Abs(num) / Abs(den)

solve(expr.replace(Abs, repl_Abs))
# out: [-5/2, 11]
Davide_sd
  • 10,578
  • 3
  • 18
  • 30