'Is it possible to let a sympy symbolic variable be element of a specific interval?

Im trying to solve some inequations containing absolute values and I want to use sympy to make my life a bit easier.

There are some conditions for the given variable to be followed, for example:

Let x be element of [-1, 0). Find the zero point of `f(x) = |-2.5x^3-3x^2-0.5x|`

where |...| indicates the absolute value.

I've tried different things like:

import sympy as sp

x = sp.Symbol('x', real=True)
i = sp.Interval.Ropen(-1, 0)
f = sp.Abs(-2.5*x**3 - 3*x**2 - 0.5*x)
print(sp.imageset(x, f, i))

Apparently the imageset function has some problems with absolute values. Also I don't know if imageset is the right function at all.

Is there a way like:

import sympy as sp

i = sp.Interval.Ropen(-1, 0)
x = sp.Symbol('x', real=True, element_of=i)
f = sp.Abs(-2.5*x**3 - 3*x**2 - 0.5*x)
print(sp.solve(f))

to print a set of solutions??



Solution 1:[1]

If you are trying to get positive or negative solutions, give that assumption to your variable and use solve:

>>> x = Symbol('x', negative=True)
>>> solve(x**2 - 1)
[-1]

If you really want to specify a domain/interval that is not just positive or negative, then pass that interval to solveset:

>>> solveset((x-3)**2-1,x)
{2, 4}
>>> solveset((x-3)**2-1,x,Interval(1,3))
{2}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 smichr