Formula for $a\sin(\theta)+b\cos(\theta)$ confusion I've been doing some trig lately and in a reference sheet I was given the following formula that I tried to prove
$$
a\sin(\theta)+b\cos(\theta)=\frac{a}{|a|}\sqrt{a^2+b^2}\sin(\theta+\alpha)
$$
with $\alpha=\arctan\left(\frac{b}{a}\right)$ and $a\neq 0$.
From the standard approach with the sum formula, I was able to get $\sqrt{a^2+b^2}\sin(\theta+\alpha)$ by setting
$$A\sin(\theta+\alpha)\equiv A\sin(\theta)\cos(\alpha)+A\cos(\theta)\sin(\alpha)=a\sin(\theta)+b\cos(\theta)$$
and solving
$$A\cos(\alpha)=a\\A\sin(\alpha)=b$$
which gave $A=\sqrt{a^2+b^2}$ and $\alpha=\arctan\left(\frac{b}{a}\right)$, but I'm unsure where the $\frac{|a|}{a}$ terms comes from nor was I able to determine the reason why the expression depends on the sign of $a$ anywhere during the solution.
 A: 

$$a\sin(\theta)+b\cos(\theta)=\frac{a}{|a|}\sqrt{a^2+b^2}\sin(\theta+\alpha)$$ with $\alpha=\arctan\left(\frac{b}{a}\right)$ and $a\neq 0$.

by setting $$a\sin(\theta)+b\cos(\theta)=A\sin(\theta+\alpha)$$ and solving $$A\cos(\alpha)=a\tag1$$$$A\sin(\alpha)=b\tag2$$ which gave $A=\sqrt{a^2+b^2}$ and $\alpha=\arctan\left(\frac{b}{a}\right)$

Your mistake is right here.
First, notice that $(1)\&(2)$ together implies that $$A=\pm\sqrt{a^2+b^2}$$ rather than $A=\sqrt{a^2+b^2}.$
Next, notice that $\alpha=\arctan\left(\frac{b}{a}\right)$ is a given condition (you didn't have to solve for it), which has designated $\alpha$ to reside within $\left(-\frac\pi2,\frac\pi2\right).$ This means that $\cos\alpha$ is always positive. Thus, from equation $(1)$ and the given restriction $a\ne0,$ $$A\;\text{and}\;a\;\text{have the same sign.}$$
Hence, $$A=\operatorname{sgn}(a)\sqrt{a^2+b^2}\\=\frac a{|a|}\sqrt{a^2+b^2},$$ as required.
A: Let's see what happens if we leave off the $a/|a|$ factor. Put in $\sin\theta+\cos\theta$, and get
$\sin\theta+\cos\theta=\sqrt2(\sin(\theta)+(\pi/4))$
With $\theta=0$, we get $1=1, \theta=\pi/4$ gives $\sqrt2=\sqrt2$, and similarly if we check other values of $\theta$. All is well.
Now try $-\sin\theta+\cos\theta$. We then have
$-\sin\theta+\cos\theta=\sqrt2()\sin(\theta-(\pi/4))$
Now $\theta=0$ gives $-1=+1$, $\theta =\pi/4$ gives $0=0$ (we got lucky), $\theta=\pi/2$ gives $-1=+1$ and we see that we are missing the sign.
We fail in the second case because we do not always have $\alpha=\arctan(b/a)$. It is true that $\tan\alpha=a/b$, but over the course of a period of the sine or cosine we traverse two periods. So $\tan\alpha=b/a$ actually corresponds to two $\alpha$ values with distinct trigonometric function values: $\arctan(b/a)$ and $\arctan(b/a)\pm\pi$ (both signs give equivalent results). So you may have to add or subtract $\pi$ to $\theta+\alpha$, which is equivalent to changing the sign of the sine. That sign change turns out to occur precisely when $a$ is negative, so the formula properly has that sign factor equal to $a/|a|$.
Put that doctor into both my examples above and you can prove everything now works.
A: You're on the right track.  The issue is that the sign of the argument $b/a$ to $\arctan$, is positive if $a$ and $b$ share the same sign, and negative if $a$ and $b$ have opposite signs, so you cannot distinguish which quadrant $\alpha$ lies in by simply knowing $b/a$:  you also need to know another piece of information, such as the sign of $a$ itself.
To illustrate, suppose we have $$f(a,b,\theta) = a \cos \theta + b \sin \theta$$ and consider $f(1, \sqrt{3},\theta)$.  Then we have $\alpha = \arctan \sqrt{3}$, but there are two angles that satisfy this relationship, namely $\alpha \in \{\frac{\pi}{3}, -\frac{2\pi}{3}\}$.  Which one do you choose?  By the sine angle addition identity, you showed that $f$ must take on the form $\sqrt{a^2 + b^2} \sin (\theta + \alpha) = 2 \sin (\theta + \alpha)$.  If $\theta = 0$, then $f(1, \sqrt{3}, 0) = 1$, so we need $2 \sin \alpha = 1$.  Of the two choices, only $\alpha = \pi/3$ makes this true; the other choice gives $-1$.  So we must have $f(1, \sqrt{3}, \theta) = 2 \sin (\theta + \frac{\pi}{3})$.
Similarly, $f(-1, -\sqrt{3}, \theta)$ has $b/a = \sqrt{3}$, and should yield $-2 (\sin \theta + \frac{\pi}{3})$, yet without knowing the sign of $a$, you would not get the negative sign in front.  Alternatively, you could choose $\alpha = -2\pi/3$ and write $$f(-1, -\sqrt{3}, \theta) = 2 \sin (\theta - \tfrac{2\pi}{3})$$ which is also correct, but this is because we chose the angle according to the quadrant in which the point $(a,b)$ lies.
So you have a choice here:  you can either observe the quadrant of $(a,b)$ and choose $\alpha$ to match it, or you can make $\arctan$ a one-to-one function with range in $(-\pi, \pi]$ and then choose the appropriate sign according to the sign of $a$.  This second approach is the reason for $|a|/a$ and is the approach taken by the solution you quoted.
Here is another example:  $$f(-2,2,\theta) = 2\sqrt{2} \sin (\theta + 3\pi/4),$$ if we pay attention to the quadrant in which $(2,-2)$ lies (second quadrant).  Or we can write it as $$f(2,-2,\theta) = -2\sqrt{2} \sin (\theta - \pi/4),$$ if we evaluate $\alpha = \arctan (-2/2) = \arctan (-1) = -\pi/4$, always taking the angle to be between $-\pi$ and $\pi$.
