<s>[INST] $ A\sin\alpha + B\cos\alpha=C$ solution confusion The solution of equation:
$$ A\sin\alpha + B\cos\alpha=C$$
according to python is:
$$\alpha=2\arctan\left[\frac{A \pm \sqrt{A^2+B^2-C^2}}{B+C}\right]$$
My question is why two answers or in otherwords in which situations we choose the postive and which the negative ? Can we get rid of the plus minus sign to outside of the function inside the $\arctan$ to outside?
 [/INST] Starting with:
$$Asin(\alpha) + Bcos(\alpha) = C,$$
divide by $cos(\alpha)$ on both sides:
$$Atan(\alpha) + B = Csec(\alpha).$$
Then, square both sides:
$$A^2tan^2(\alpha) + 2ABtan(\alpha) + B^2 = C^2sec^2(\alpha).$$
Apply a variant of the Pythagorean identity to the RHS to get:
$$A^2tan^2(\alpha)+2ABtan(\alpha) + B^2 = C^2(tan^2(\alpha)+1).$$
Regroup to get quadratic in $tan(\alpha)$:
$$(A^2 - C^2)[tan(\alpha)]^2+(2AB)[tan(\alpha)] + (B^2-C^2) = 0.$$
Apply quadratic formula and simplify:
$$tan(\alpha) = \frac{-2AB\pm\sqrt{4A^2B^2 - 4(A^2-C^2)(B^2 - C^2)}}{2(A^2 - C^2)}$$
$$ = \frac{-AB\pm \sqrt{A^2B^2 - A^2B^2+A^2C^2+B^2C^2-C^4}}{A^2-C^2}$$
$$ = \frac{-AB\pm C\sqrt{A^2+B^2-C^2}}{A^2-C^2}.$$
Hence:
$$\alpha = arctan\bigg(\frac{-AB\pm C\sqrt{A^2+B^2-C^2}}{A^2-C^2}\bigg).$$

So the plus and minus comes from the quadratic formula and represents two arguments provided $A^2+B^2\neq C^2$ (i.e. that the discriminant is nonzero). If it is zero of course there is one argument for arctan. The $\pm$ can't pull out. The quadrant in which $\alpha$ lies depends on the sign of the numerator and denominator.
</s>