How do you obtain this formula?

I saw this in my textbook that asin(x)+bcos(x) can be written as Rsin(x+@). And there is a similar formula for cosine as well. It also says that R^{2}=a^{2}+b^{2}. How and why do we obtain these relations? And what about putting in some variations like putting powers on the trig functions. In the textbook these types of questions continually keep cropping up like: convert 3sin(x)+2cos(x) in the form Rsin(x+@). Can you explain how doing it by using double angle or addition formulae of trig functions, if possible. Or what if we have to convert it to Rcos(x+@).Or if there are powers on trig functions.

Re: How do you obtain this formula?

Let $\displaystyle f \left( x \right)=a \sin x+b \cos x$

Divide both members by $\displaystyle \sqrt{a^2+b^2}$:

$\displaystyle \frac{f \left( x \right)}{\sqrt{a^2+b^2}}=\frac{a}{\sqrt{a^2+b^2}}\ sin x+\frac{b}{\sqrt{a^2+b^2}}\cos x$

We have that $\displaystyle \left(\frac{a}{\sqrt{a^2+b^2}}\right)^2+\left( \frac{b}{\sqrt{a^2+b^2}}\right)^2=1$ and $\displaystyle \frac{a}{\sqrt{a^2+b^2}}, \ \frac{b}{\sqrt{a^2+b^2}}\in \left[ -1,1\right]$.

Then $\displaystyle \exists \phi\in \mathcal{R}$ such as $\displaystyle \cos\phi = \frac{a}{\sqrt{a^2+b^2}}$ and $\displaystyle \sin\phi = \frac{b}{\sqrt{a^2+b^2}}$

So $\displaystyle \frac{f\left( x \right)}{\sqrt{a^2+b^2}}=\sin x\cos\phi+\sin\phi\cos x=\sin\left(x+\phi\right)$

and $\displaystyle f \left( x \right)=\sqrt{a^2+b^2}\sin\left(x+\phi\right)$

If we note $\displaystyle R^2=a^2+b^2$ then $\displaystyle a\sin x+b\cos x=R\sin\left(x+\phi\right)$