sympyinequality

Sympy can't solve inequality with radicals


I need to solve this inequality: enter image description here

import sympy as sp
from sympy.abc import x,n

epsilon = 0.01
a = 2/3

xn = (n**3 + n**2)**(1/3) - (n**3 - n**2)**(1/3)

i tried to solve it like this:

ans = sp.solve_univariate_inequality(sp.Abs(xn-a) < epsilon,n,relational=False)

but received:

NotImplementedError: The inequality, Abs((x3 - x2)0.333333333333333 - (x3 + x**2)**0.333333333333333 + 2/3) < 0.01, cannot be solved using solve_univariate_inequality.

And tried so, but it didn't work

ans = sp.solve_poly_inequality(sp.Poly(xn-2/3-0.01, n, domain='ZZ'), '==')

but received:

sympy.polys.polyerrors.PolynomialError: (n3 + n2)**0.333333333333333 contains an element of the set of generators.

Same:

ans = sp.solveset(sp.Abs(xn-2/3) < 0.01, n)

ConditionSet(n, Abs((n3 - n2)0.333333333333333 - (n3 + n**2)**0.333333333333333 + 0.666666666666667) < 0.01, Complexes)

How can this inequality be solved?


Solution

  • from sympy import *
    from sympy.abc import x,n
    a = S(2) / 3
    epsilon = 0.01
    xn = (n**3 + n**2)**(S(1)/3) - (n**3 - n**2)**(S(1)/3)
    ineq = Abs(xn-a) < epsilon
    

    Let's verify where ineq is satisfied with plot_implicit. Note that the left hand side of the inequality is valid only for n>=1.

    plot_implicit(ineq, (n, 0, 5), adaptive=False)
    

    enter image description here

    So, the inequality is satisfied for values of n greater than 3.something.

    We can use a numerical approach to find the root of this equation: Abs(xn-a) - epsilon.

    from scipy.optimize import bisect
    func = lambdify([n], Abs(xn-a) - epsilon)
    bisect(func, 1, 5)
    # out: 3.5833149415284424