How to solve for the (periodic) roots of $f(x) = a_0 + a_1 \cos(x + \alpha_1) + a_2 \cos(2 x + \alpha_2)$ analytically given $a_0, a_1, a_2, \alpha_1, \alpha_2 \in \mathbb{R}$?
Roots of $a_0 + a_1 \cos(x + \alpha_1) + a_2 \cos(2 x + \alpha_2)$
-
0The linear combination of the sinusoids of different frequencies is non-sinusoidal but periodic. My computer algebra package tells me a function returning the roots exists, which depends on the roots of a 4-th order polynomial. – 2017-01-04
-
0Wolfram Mathematica can find a solution but it is a huge ugly mess of an expression. It found eight solutions. – 2017-01-04
-
0You can expand the cosines then use the [tangent half-angle substitution](https://en.wikipedia.org/wiki/Tangent_half-angle_substitution) to get a [quartic equation](https://en.wikipedia.org/wiki/Quartic_function#Solving_a_quartic_equation) in $t = \tan \frac{x}{2}$ but the roots won't be pretty in the general case. – 2017-01-05
-
0That does the trick. I wonder if there exist approaches without transforming it into a quartic equation. – 2017-01-05
2 Answers
As dxiv proposed in his comment:
- Expand the cosines:
$a_0 + (a_1 \cos \alpha_1) \cos x - (a_1 \sin \alpha_1) \sin x + (a_2 \cos \alpha_2) \cos 2x - (a_2 \sin \alpha_2) \sin 2x = 0$
$a_0 + (a_1 \cos \alpha_1) \cos x - (a_1 \sin \alpha_1) \sin x + (a_2 \cos \alpha_2) (1 - 2 \sin^2 x) - (2 a_2 \sin \alpha_2) \cos x \sin x = 0$
- Tangent half-angle substitution:
Substitute $\sin x = \frac{2t}{1+t^2}$ and $\cos x = \frac{1-t^2}{1 + t^2}$, for which $t = \tan \frac{x}{2}$ holds.
$(a_0 + a_2 \cos \alpha_2) + (a_1 \cos \alpha_1)\frac{1-t^2}{1+t^2} - (a_1 \sin \alpha_1) \frac{2t}{1+t^2} - (2 a_2\cos \alpha_2) \frac{4t^2}{(1+t^2)^2} - (2 a_2 \sin \alpha_2) \frac{2t(1-t^2)}{(1+t^2)^2} = 0$
Multiply by $(1+t^2)^2$.
$(a_0 + a_2 \cos \alpha_2)(1+t^2)^2 + (a_1 \cos \alpha_1)(1-t^4) - (a_1 \sin \alpha_1) 2t(1+t^2) - (2 a_2\cos \alpha_2) 4t^2 - (2 a_2 \sin \alpha_2) 2t(1-t^2) = 0$
Then for each solution $t_i$ of the quartic equation we obtain two possible solutions of the original problem.
$x_{2i,2i+1} = \pm 2\arctan t_i$
Example:
$\cos(x)+\cos(2x)=0$, where $a_0 = \alpha_1 = \alpha_2 = 0$ and $a_1 = a_2 = 1$.
Then we end up with $t_{0,1} = \pm \sqrt{\frac{1}{3}}$ and thus $x_{0,2} = 2\arctan t_{0,1}$. The third root at $x = \pi$ is missing. Note that this is a degenerate case. Additionally checking whether $x=\pi$ solves the initial problem fixes this issue.
-
0Probably we can forget about the would-be solutions $x_{2i+1} = -2\arctan t_i$. – 2017-01-05
-
0Numerically this approach is most likely a disaster unless the solutions are known to be away from $\pi + n2\pi$. – 2017-01-05
Exploit relationship of cosine and sine functions to exponential functions with purely imaginary arguments ($e^{ix} = \cos x + i \sin x$). Then the equation transforms into
$a_0 + \frac{a_1}{2} (e^{i \alpha_1} e^{ix} + e^{-i\alpha_1}(e^{ix})^{-1}) + \frac{a_2}{2}(e^{i\alpha_2} (e^{ix})^2 + e^{-i\alpha_2} (e^{ix})^{-2}) = 0$
Substition of $y = e^{ix}$ and multiplication by $y^2$ leads to the quartic equation with complex coefficients
$\frac{a_2}{2} e^{i\alpha_2} y^4 + \frac{a_1}{2} e^{i \alpha_1} y^3 + a_0 y^2 + \frac{a_1}{2} e^{-i\alpha_1} y + \frac{a_2}{2} e^{-i\alpha_2} = 0,$
which can be solved analytically. Then
$x_i = \operatorname{atan2}(\operatorname{Im}(y_i), \operatorname{Re}(y_i))$
are potential solutions to the original problem.