<s>[INST] Solving $ a \cos x + b \sin x = u $, $ -a \sin x + b \cos x = v $ in a different way gives me a solution that does not work for $ x = n\pi $ I am solving the following equations to find $ a $ and $ b $:
\begin{align*}
a \cos x + b \sin x &= u \\
-a \sin x + b \cos x &= v
\end{align*}
Solution 1
Multiplying the first equation with $ \cos x $ and the second one with $ -\sin x $ and then adding them both I get
$$
a(\cos^2x + \sin^2 x) + b(\sin x \cos x - \sin x \cos x) = u \cos x - v \sin x.
$$
So
$$
a = u \cos x - v \sin x.
$$
Multiplying the first equation with $ \sin x $ and the second one with $ \cos x $ I get
$$
a(\sin x \cos x - \sin x \cos x) + b(\sin^2 x + \cos^2 x) = u \sin x + v \cos x
$$
So
$$
b = u \sin x + v \cos x.
$$
Solution 2
I obtain $ a = u \cos x - v \sin x $ as described in the previous solution.
Now I substitute $ a = u \cos x - v \sin x $ in the first equation to get
$$
(u \cos x - v \sin x) \cos x + b \sin x = u.
$$
Simplifying we get
$$
u \cos^2 x - v \sin x \cos x + b \sin x = u.
$$
So
$$
b = \frac{u - u \cos^2 x + v \sin x \cos x}{\sin x} = \frac{u \sin^2 x + v \sin x \cos x}{\sin x}
$$
When $ \sin x \ne 0 $, we divide both numerator and denominator by $ \sin x $ to get
$$
b = u \sin x + v \cos x.
$$
My Question
In solution 2, we have got the solution $ b = u \sin x + b \cos x $ but we got this solution only for the case when $ \sin x \ne 0 $, i.e. $ x \ne n\pi $ for integers $ n $. In solution 1, we got the same solution for all values of $ x $.
Why did I get an incomplete solution in solution 2? How do I ensure that I get a complete solution in solution 2?
 [/INST] All you have to do to complete the second solution is work in cases:
Case 1: $\sin x\ne 0$
.
.
.
$$b = \frac{u - u \cos^2 x + v \sin x \cos x}{\sin x} = \frac{u \sin^2 x + v \sin x \cos x}{\sin x} = u \sin x + v \cos x$$
Case 2: $\sin x = 0$. Then $\cos^2 x =1$ and the original equations become
\begin{align*}
a \cos x &= u \\
b \cos x &= v
\end{align*}
Multipliying by $\cos x$ both equations we get
\begin{align*}
a &= u \cos x = u \cos x - v \sin x\\
b &= v \cos x = u \sin x + v \cos x
\end{align*}
</s>