ricardoreich
ricardoreich

Reputation: 11

Solve absolute equality with sympy

i want to solve Abs(x - 3) + Abs(x - 4) == 9, but python returns me an empty list. []

im trying:

sym.solve(sym.Abs(x - 3) + sym.Abs(x - 4) == 0)

where am i wrong? thanks

Upvotes: 0

Views: 388

Answers (2)

Oscar Benjamin
Oscar Benjamin

Reputation: 14480

The == sign does not do what you want here: https://docs.sympy.org/latest/tutorial/gotchas.html#equals-signs

Also you'll need to declare x as real for this example.

In [3]: x = Symbol('x', real=True)

In [4]: solve(Eq(Abs(x-3)+Abs(x-4), 9), x)
Out[4]: [-1, 8]

Upvotes: 2

Who Knows
Who Knows

Reputation: 68

First, please provide a full example.

I do not seem to have any problems... What exactly did you try?

import sympy as sym
from sympy.abc import x, y
sym.solve(sym.Abs(x - 3) + sym.Abs(x - 4) == 0)

Upvotes: 1

Related Questions