Trigonometric equations

Every family of solutions

A trigonometric equation has infinitely many solutions. solve returns them as families x0+n px_0 + n\,p, merges families that are really one, and checks every family in the equation as written.

Using it

import { solve } from "@ratmath/symbolic";

String(solve("2sin(x) = 1"));             // x = pi/6 + 2*n*pi,  5*pi/6 + 2*n*pi   (n any whole number)
String(solve("sin(x)*cos(x) = 1/4"));     // x = pi/12 + n*pi,  5*pi/12 + n*pi
String(solve("sin(3x) = 0"));             // x = n*pi/3
String(solve("cos(x) + cos(3x) = 0"));    // x = pi/4 + n*pi/2,  pi/2 + n*pi

const r = solve("sin(x) = a", "x");
String(r);         // x = asin(a) + 2*n*pi,  pi - asin(a) + 2*n*pi, provided abs(a) <= 1
r.conditions;      // ["abs(a) <= 1"]

const s = solve("2sin(x) = 1").solutions[0];
String(s.period);       // "2*pi"
String(s.member(1));    // "13*pi/6"

With { range: [lo, hi] } the families are listed member by member inside the range, as on the Solving page. After solving, within(lo, hi) does the same for any interval: solve("2cos(x)^2 - cos(x) - 1 = 0").within("[0, 2*pi)") is 0,2π3,4π30, \tfrac{2\pi}{3}, \tfrac{4\pi}{3}. Write the ends as text with brackets to choose open or closed ends; each member is placed by an exact comparison with the ends.

The general solution of the basic equations

Each of the three basic equations has a principal solution from the inverse function and a rule for the others:

sin⁡x=a:  x=arcsin⁡a+2nπ or π−arcsin⁡a+2nπ,cos⁡x=a:  x=±arccos⁡a+2nπ,tan⁡x=a:  x=arctan⁡a+nπ. \sin x = a:\; x = \arcsin a + 2n\pi \text{ or } \pi - \arcsin a + 2n\pi, \qquad \cos x = a:\; x = \pm\arccos a + 2n\pi, \qquad \tan x = a:\; x = \arctan a + n\pi.

The first two need ∣a∣≤1|a| \le 1. When aa is a number the library decides that itself; when it is a letter it asks the assumptions, and if they do not settle it the condition abs(a) <= 1 is returned with the answer. At the exact angles (multiples of π/12\pi/12) the inverse function is written as that angle, so arcsin⁡12\arcsin\tfrac12 appears as π/6\pi/6.

When the angle is kx+bkx + b instead of xx, each family is solved for xx: the period becomes 2π/∣k∣2\pi/|k|.

Reducing to the basic equations

Most equations from a course become one of the basic three after a standard move. The solver tries them in turn:

  • One function, polynomially. 2cos⁡2x−3cos⁡x+1=02\cos^2 x - 3\cos x + 1 = 0 is a quadratic in u=cos⁡xu = \cos x: u=1u = 1 or u=1/2u = 1/2, then each is inverted.
  • Homogeneous in sine and cosine. sin⁡x=cos⁡x\sin x = \cos x, or sin⁡2x−3sin⁡xcos⁡x+2cos⁡2x=0\sin^2 x - 3\sin x\cos x + 2\cos^2 x = 0: divide by a power of cos⁡x\cos x and solve for tan⁡x\tan x.
  • Power reduction and double angles. A product or power of sin⁡x\sin x and cos⁡x\cos x is rewritten as sines and cosines of multiples of xx, through sin⁡x=(z−z−1)/2i\sin x = (z - z^{-1})/2i and cos⁡x=(z+z−1)/2\cos x = (z + z^{-1})/2 with z=eixz = e^{ix}. If one multiple is left, that is an equation in one angle: sin⁡xcos⁡x=14\sin x\cos x = \tfrac14 becomes 12sin⁡2x=14\tfrac12\sin 2x = \tfrac14.
  • Angle sums. sin⁡2x=cos⁡x\sin 2x = \cos x is expanded with the double-angle formula and factored: cos⁡x (2sin⁡x−1)=0\cos x\,(2\sin x - 1) = 0.
  • The half-angle substitution. Anything left that is a polynomial in sin⁡x\sin x and cos⁡x\cos x becomes a polynomial in t=tan⁡(x/2)t = \tan(x/2), through sin⁡x=2t/(1+t2)\sin x = 2t/(1+t^2) and cos⁡x=(1−t2)/(1+t2)\cos x = (1-t^2)/(1+t^2). The substitution misses x=πx = \pi, which is tried separately.

Families that are one family

The methods above can return several families with the same period whose starting points are evenly spaced, as sin⁡3x=0\sin 3x = 0 gives 2nπ/32n\pi/3 and π/3+2nπ/3\pi/3 + 2n\pi/3. Those are one family, nπ/3n\pi/3. The library reduces each starting point modulo the period, looks for kk of them spaced exactly p/kp/k apart, and proves the spacing with the normal form before merging them. A family written twice (−π/2+2nπ-\pi/2 + 2n\pi and 3π/2+2nπ3\pi/2 + 2n\pi) is listed once.

What the normal form knows

To check a family with a letter in it, the solution is put back and the difference reduced to zero. That needs a few identities, which the normal form now applies wherever the left side is defined:

sin⁡(arcsin⁡w)=w,cos⁡(arcsin⁡w)=1−w2,sin⁡(arctan⁡w)=w1+w2,sin⁡(w+π)=−sin⁡w,cos⁡(w+π2)=−sin⁡w. \sin(\arcsin w) = w,\quad \cos(\arcsin w) = \sqrt{1-w^2},\quad \sin(\arctan w) = \frac{w}{\sqrt{1+w^2}},\quad \sin(w + \pi) = -\sin w,\quad \cos(w + \tfrac{\pi}{2}) = -\sin w.

The inverse functions themselves are evaluated at the standard exact values: arcsin⁡\arcsin and arccos⁡\arccos at 0,±12,±22,±32,±10, \pm\tfrac12, \pm\tfrac{\sqrt2}2, \pm\tfrac{\sqrt3}2, \pm1, and arctan⁡\arctan at 0,±33,±1,±30, \pm\tfrac{\sqrt3}3, \pm1, \pm\sqrt3. The argument is matched by the normal form, so asin(1/sqrt(2)) is recognised as 22\tfrac{\sqrt2}{2} and simplifies to π4\tfrac{\pi}{4}; asin(-sqrt(3)/2) is −π3-\tfrac{\pi}{3}.

The square roots are right, not just up to sign, because arcsin⁡\arcsin and arctan⁡\arctan take values in [−π/2,π/2][-\pi/2, \pi/2], where the cosine is not negative; arccos⁡\arccos takes values in [0,π][0, \pi], where the sine is not negative.

Try itEdit the code and run it with @ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs