Prove that for every positive integer $n$ and any real numbers $a_1,a_2,\cdots , a_n, b_1,\cdots, b_n $, the equation \begin{equation} \phantom{=}a_1 \sin(x)+a_2 \sin(2x)+\cdots +a_n \sin(nx) \\ = b_1 \cos(x)+b_2 \cos(2x)+\cdots +b_n \cos(nx)\end{equation} has at least one real solution.
I have tried to use the Intermediate Value Theorem and induction to solve this, but can't really prove it. My idea was to show that
\begin{equation}
g_n(x)=\sum_{k=1}^n a_k \sin(kx)-b_k\cos(kx)
\end{equation}
Is greater than zero at one point and less than zero at another one.
However, I got stuck at the inductive step, as it is not really clear to me whether
\begin{equation}
g_{n+1}(x)=a_{n+1}\sin([n+1]x)-b_{n+1}\cos([n+1]x)+g_n(x)
\end{equation}
Has the property that for some $x_1$ and $x_2$ in $\mathbb{R}$, $g_{n+1}(x_1)\geq 0$, and $g_{n+1}(x_2)\leq 0$ provided that $g_n(x)$ has this property.
I haven't taken any complex variable course yet, so I don't know if this would involve Fourier series or something related.
Another idea that I had was to integrate the function $g_n(x)$ from $0$ to $2\pi$ and show that it's zero. But I'm not sure if that works for every $a_i$ and $b_i$.
I would really appreciate any hint or sketch of proof.
Edits: I added my attempts of proving this.