How to get a solution of the inequality $5 \sin (\theta)-\frac{1}{2} \sin \left(\frac{5 \theta}{2}\right) \geq 0$ using sympy?
Solution 1:
When I am running:
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
from sympy import S
x, y = sp.symbols("x, y", real=True)
theta = sp.symbols("theta")
d = sp.symbols("d", real=True, positive=True)
y = 5 * sp.sin(theta) - d * sp.sin(sp.Rational(5,2) * theta)
y_with_d_a_half = y.subs(d,1/2)
sp.solveset(y_with_d_a_half >= 0, theta, domain=S.Reals)
we obtain: $\{0\}\cup[2\pi,4\pi)$
Your code looks good except the last line, where you should involve y_with_d_a_half
into your inequality. Otherwise SymPy is left alone with the unknown variable d
.
Additional hint:
You get the same result by using:
from sympy.solvers.inequalities import solve_univariate_inequality
...
solve_univariate_inequality(y_with_d_a_half >= 0, theta, relational=False)
To plot your inequality you can use plot_implicit(y_with_d_a_half >= 0)
, which will generate the following plot: