Trigonometric Equations
An identity holds for every angle; an equation like holds only for some. Because trig functions repeat, a trig equation usually has infinitely many solutions. This lesson shows how to find all of them, how to list those in a given interval, and how to check a computer algebra answer numerically.
One equation, infinitely many solutions
Solve . First isolate the function: . On one turn the unit circle has two points with height : (quadrant I) and (quadrant II). Adding any whole number of turns gives the same points again, so the general solution is
The general recipe for the three basic equations, with the principal value from the inverse function:
| Equation | Principal value | General solution |
|---|---|---|
| , | or | |
| , | ||
| , any |
If , and have no solutions. Tangent needs only one family because its period is .
Solving on an interval
Applications usually want solutions in a window, such as or . Generate the general solution and keep the values that land in the window:
import math
def sin_solutions(c, lo, hi):
"""All x in [lo, hi) with sin x = c."""
if abs(c) > 1:
return []
a = math.asin(c)
out = set()
for k in range(math.floor(lo / (2 * math.pi)) - 1, math.ceil(hi / (2 * math.pi)) + 2):
for x in (a + 2 * k * math.pi, math.pi - a + 2 * k * math.pi):
if lo <= x < hi:
out.add(round(x, 12))
return sorted(out)
print("sin x = 0.5 on [0, 2π):", [round(x / math.pi, 4) for x in sin_solutions(0.5, 0, 2 * math.pi)], "× π")
print("sin x = 0.5 on [0, 6π):", [round(x / math.pi, 4) for x in sin_solutions(0.5, 0, 6 * math.pi)], "× π")
print("sin x = -0.3 on [0, 360°):", [round(math.degrees(x), 3) for x in sin_solutions(-0.3, 0, 2 * math.pi)])sin x = 0.5 on [0, 2π): [0.1667, 0.8333] × π
sin x = 0.5 on [0, 6π): [0.1667, 0.8333, 2.1667, 2.8333, 4.1667, 4.8333] × π
sin x = -0.3 on [0, 360°): [197.458, 342.542]
For , gives about −17.458°, which is outside the window; adding 360° gives 342.542°, and gives 197.458°.
Harder equations: reduce to the basic ones
Quadratic in a trig function. Solve on . Substitute : factors as , so or . That gives and .
Use an identity to get one function. Solve on .
Note: Never divide both sides by here. Dividing throws away exactly the solutions where . Move everything to one side and factor instead.
Multiple angles. For on , solve for first. Since runs over , runs over : three turns, so six solutions , and .
Computer algebra, checked numerically
SymPy's solveset handles many trig equations and can restrict to an interval. It is a great tool, but it is not infallible: for some equations it returns an incomplete set, or a ConditionSet that means "I could not solve this". The older solve returns only a few principal solutions. Always confirm with an independent numeric method, for example by scanning for sign changes and refining each with a root finder.
import numpy as np
import sympy as sp
from scipy.optimize import brentq
x = sp.Symbol("x", real=True)
expr = sp.sin(2 * x) - sp.cos(x)
exact = sp.solveset(expr, x, sp.Interval.Ropen(0, 2 * sp.pi))
print("solveset:", exact)
print("solve :", sp.solve(expr, x))
f = sp.lambdify(x, expr, "numpy")
grid = np.linspace(0, 2 * np.pi, 19_999) # odd spacing, so no grid point is exactly a root
vals = f(grid)
roots = [brentq(f, a, b) for a, b, fa, fb in zip(grid, grid[1:], vals, vals[1:]) if fa * fb < 0]
print("numeric :", [round(r / np.pi, 6) for r in roots], "× π")
print("same count?", len(roots) == len(exact))solveset: {pi/6, pi/2, 5*pi/6, 3*pi/2}
solve : [-pi/2, pi/6, pi/2, 5*pi/6]
numeric : [0.166667, 0.5, 0.833333, 1.5] × π
same count? True
Here everything agrees. Notice that solve returned instead of and gave no general solution: it only lists some representatives. A sign-change scan has its own blind spot: a root where the graph only touches zero (like at , where never changes sign) is invisible to it. Using two different methods is what makes the check trustworthy.
In software
- Event timing. When does a lighthouse beam pointing at angle first hit a ship at bearing ? Solve : for the smallest .
- Threshold crossings. A day/night model crosses 0.5 at the times has solutions; a game spawns night monsters between those times.
- Collision with oscillating objects. A platform at height meets a player at height 4 when .
- Robust solvers. Production code rarely solves trig equations symbolically; it uses closed-form general solutions like the table above, or bracketing root finders (bisection, Brent) on a known interval.
Exercises
Exercise 1: General solution
Find all solutions of , then list those in .
Answer
; in : and .
Solution
Exercise 2: Tangent
Solve on .
Answer
135° and 315°.
Solution
, and has period 180°, so . In the window: gives 135°, gives 315°.
Exercise 3: Quadratic type
Solve on .
Answer
.
Solution
import sympy as sp
x = sp.Symbol("x", real=True)
print(sp.solveset(2*sp.sin(x)**2 + 3*sp.sin(x) + 1, x, sp.Interval.Ropen(0, 2*sp.pi))){7*pi/6, 3*pi/2, 11*pi/6}
Note that is a double-touch point of the graph ( never changes sign), so a sign-change scan alone would miss it.
Exercise 4: Multiple angle
Solve on .
Answer
.
Solution
With in : at . Divide by 2.
Exercise 5: Platform meets player
A platform's height is (metres, in seconds). Find every time in when it is at height 4, and confirm numerically with brentq.
Answer
.
Solution
, so or . The next one, , is beyond 10.
import math
import numpy as np
from scipy.optimize import brentq
f = lambda t: 3 + 2 * math.sin(t) - 4
grid = np.linspace(0, 10, 1001)
roots = [brentq(f, a, b) for a, b in zip(grid, grid[1:]) if f(a) * f(b) < 0]
print([round(r, 4) for r in roots])
print([round(v, 4) for v in (math.pi/6, 5*math.pi/6, 13*math.pi/6, 17*math.pi/6)])[0.5236, 2.618, 6.8068, 8.9012]
[0.5236, 2.618, 6.8068, 8.9012]
Test yourself
How many solutions does have in ?
- 0
- 1
- 2
- Infinitely many
Solving , a student divides by and gets . What went wrong?
- Nothing, is the only solution
- Dividing by lost the solutions where
- They should have squared both sides
- has no solutions
What is the general solution of ?