In this question, it is shown that

$$A \sin(x) + B \cos (x) = R \sin ( x + \theta )$$

for $A,B$ real and positive, with

$$R = \sqrt{A^2 + B^2}$$

$$\theta = \arctan \left( \frac{B}{A} \right)$$

This is performed solving the system

$$\left\{ \begin{array}{c} R \cos (\theta) = A\\ R \sin (\theta) = B \end{array} \right. $$

for $R$ and $\theta$. What if, instead, $A$ and/or $B$ are real, but not positive?

Some trivial test on WolframAlpha shows that the $\arctan \left( \frac{B}{A} \right)$ term is computed the same way, considering the sign of $A$ and $B$.

$R$ is instead negative if $A$ or both $A$ and $B$ are negative. It is obtained by squaring and summing the two equations in the system and I can't figure out how a sign can be considered in this operation.


Let $A = R \cos \theta$ and $B = R \sin \theta$

So, $y = A \sin x + B \cos x = R \cos \theta \sin x+ R \sin \theta \cos x = R \sin(x + \theta)$

Also, $R^2 = A^2 + B^2$ or $R = \sqrt{A^2 + B^2}$


$$\alpha = \tan^{-1} \left| \frac{B}{A} \right|$$

so that $\alpha \in [0,\pi/2]$

Let us assume $R$ to be always positive (conventional).

So we now have 4 cases.


$A \ge 0$ and $B \ge 0$

In this case, $R \cos \theta \ge 0$ and $R \sin \theta \ge 0$

Being $R>0$, this implies $\sin \theta \ge 0$ and $\cos \theta \ge 0$

So, $\theta \in [0 ,\pi/2]$


$$\alpha = \theta$$


$A \le 0$ and $B \ge 0$

In this case, $R \cos \theta \le 0$ and $R \sin \theta \ge 0$

As $R>0$, $\sin \theta \ge 0$ and $\cos \theta \le 0$

So, $\theta \in [ \pi/2, \pi]$

$\alpha = \pi - \theta$

or $$\theta = \pi - \alpha$$


$A \le 0$ and $B \le 0$

In this case, $R \cos \theta \le 0$ and $R \sin \theta \le 0$

As $R>0$, $\sin \theta \le 0$ and $\cos \theta \le0$

So, $\theta \in [ \pi, 3\pi/2]$ or $\theta \in [ -\pi/2, -\pi]$.

$$\alpha = \theta - \pi$$

or $$\theta = \alpha + \pi$$


$A \ge 0$ and $B \le 0$

In this case, $R \cos \theta \ge 0$ and $R \sin \theta \le 0$

As $R>0$, $\sin \theta \le 0$ and $\cos \theta \ge 0$

So, $\theta \in [3\pi/2, 2\pi]$ or $\theta \in [-\pi/2,0]$.

$$\alpha = - \theta$$


$$ \theta = - \alpha$$

So, at last $$y = R \sin( x + \theta)$$

Find the signs of $A$ and $B$, then the principal value $\alpha$. Then according to the quadrant, find $\theta$ in terms of $\alpha$ and substitute in the above expression.


Write your term in the form $$\sqrt{A^2+B^2}\left (\frac{A\cos(x)}{\sqrt{A^2+B^2}}+\frac{B\sin(x)}{\sqrt{A^2+B^2}}\right)$$

  • $\begingroup$ Before or after writing the system? Sorry, I can't still figure it out. Also you swapped $A$ and $B$, I guess it is a typo. $\endgroup$ – BowPark May 10 '19 at 10:09

$\newcommand{arccot}{\operatorname{arccot}}$A method is, for all $A,B\in\Bbb R$ such that $A\ne 0\lor B\ne 0$, to consider the following manipulation $$\sqrt{A^2+B^2}\left(\frac A{\sqrt{A^2+B^2}}\sin x+\frac{B}{\sqrt{B^2+A^2}}\cos x\right)=\\=\sqrt{A^2+B^2}\sin\left(x+\theta\left(\frac A{\sqrt{A^2+B^2}},\frac {B}{\sqrt{A^2+B^2}}\right)\right)$$

where $\theta(c,s)$ is, provided that $c^2+s^2=1$, the one and only real number $\theta\in (-\pi,\pi]$ such that $\cos \theta=c\land \sin\theta=s$. There are a number of ways to write such number. Here are a few:

\begin{align}\theta(c,s)&=\begin{cases}\arccos c&\text{if }s\ge 0\\ -\arccos c&\text{if }s<0\end{cases}\\ \theta(c,s)&=\begin{cases}\arctan \frac sc&\text{if }c> 0\\ -\frac\pi2\operatorname{sgn}s&\text{if }c=0\\ \pi+\arctan \frac sc&\text{if }c<0\land s\ge 0\\ -\pi+\arctan\frac sc&\text{if }c<0\land s<0\end{cases}\\ \theta(c,s)&=\begin{cases}\arccot \frac cs&\text{if }s> 0\\ \pi\operatorname{sgn}c&\text{if }s=0\\ -\arccot c&\text{if }s<0\end{cases}\end{align}

Of course, a different choice of range for $\theta(c,s)$ (for instance $[0,2\pi)$) may yield different expressions.

  • $\begingroup$ This is very thorough, but it doesn't show the way these expressions are obtained. Let's focus on the second one: $\theta(c,s)$ in terms of $\arctan$. How to obtain this? $\endgroup$ – BowPark May 10 '19 at 10:23
  • $\begingroup$ Because $\cos\arctan x=\frac{1}{\sqrt{1+x^2}}$ and $\sin\arctan x=\frac{x}{\sqrt{1+x^2}}$. If you apply this to the four cases, you'll obtain $\cos\theta(c,s)=c$ and $\sin\theta(c,s)=s$. Then, you may notice that every so-defined $\theta(c,s)$ will actually be in $(-\pi,\pi]$. $\endgroup$ – Saucy O'Path May 10 '19 at 11:06

For $R$ the signs of $A$ and $B$ do not matter at all.

To get a correct angle for any $(A,B) \ne (0,0)$ you may have a look at the 2-argument arctangent function: $$θ=\rm{atan2}(B, A).$$

For each case in its definition you get the same signs as in your tests with WolframAlpha:

Case $A > 0$: $$R \sin\left(x + \rm{atan2}(B, A)\right) = R \sin\left(x + \arctan\left(\frac A B\right)\right)$$ Case $A < 0$: $$R \sin(x + \rm{atan2}(B, A)) = R \sin\left(x + \arctan\left(\frac A B\right) \pm \pi\right) = -R \sin\left(x + \arctan\left(\frac A B\right)\right)$$

Case $A = 0$ and $B > 0$: $$R \sin\left(x + \rm{atan2}(B, 0)\right) = R \sin\left(x + \frac \pi 2\right) = R \cos(x) = B \cos(x)$$ Case $A = 0$ and $B < 0$: $$R \sin\left(x + \rm{atan2}(B, 0)\right) = R \sin\left(x - \frac \pi 2\right) = -R \cos(x) = B \cos(x)$$


A simpler way of solving this, without restrictions or polar coordinates, is the following:

If $A=0$ there is nothing to prove. Otherwise: $$A \sin(x) + B \cos (x) =A \left( \sin(x) + \frac{B}{A} \cos (x) \right)$$

Now, let $\tan(\theta)=\frac{B}{A}$. Then $$A \sin(x) + B \cos (x) =A \left( \sin(x) + \tan(\theta)\cos (x) \right)=A \left( \sin(x) + \frac{\sin(\theta)}{\cos(\theta)}\cos (x) \right)\\=A \frac{ \sin(x)\cos(\theta) + \sin(\theta)\cos(x)}{\cos(\theta)}=\frac{A}{\cos(\theta)}\sin(x+\theta)$$

  • $\begingroup$ A pretty smart and compact solution. Thanks! $\endgroup$ – BowPark May 10 '19 at 15:59

Take $\theta=\arccos\frac AR$. Then$$\sin^2\theta=1-\cos^2\theta=1-\frac{A^2}{R^2}=\left(\frac BR\right)^2$$amd therefore $R\sin\theta=\pm\frac BR$. If $R\sin\theta=\frac BR$, then that $\theta$ will do. Otherwise, take $-\theta$ instead.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.