I'm trying my best figuring out what is going wrong with my code. So I'm trying to solve the inequality: $$5 \sin (\theta)-\frac{1}{2} \sin \left(\frac{5 \theta}{2}\right) \geq 0$$ with sympy, but I just keep getting my question back. Could someone please help me.
This is my code:
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 >= 0, theta, domain=S.Reals)
when I run it, it returns $$$\left{\theta \mid \theta \in \mathbb{R} \wedge-d \sin \left(\frac{5 \theta}{2}\right) 5 \sin (\theta) \geq 0\right}$$
CodePudding user response:
When you did the substitution you created a new expression and did not change the original expression (y) and the expression for y cannot be solved in closed form. If you check the plot you will see there are roots and if you check the periodicity you will find that it is periodic. So you can get numerical values for the roots in the period and add or subtract 4pi to get all others.
>>> from sympy import S, sign, periodicity, nsolve
>>> eq = y.subs(d, S.Half);eq
5*sin(theta) - sin(5*theta/2)/2
>>> periodicity(eq,theta)
4*pi
>>> [nsolve(eq, 3*i).round(3) for i in range(5)]
[0, 3.044, 6.283, 9.522, 12.566]
Those are the zeros -- test the regions in between to find where the function is positive, e.g.
>>> sign(eq.subs(theta,1))
1
>>> sign(eq.subs(theta,4))
-1
