Q:

Solve: $\sin x - y\cos x = z$ for $x$.

I am working on programming a series of algorithms into a project, however I have run into trouble trying to solve this equation for $x$:
$$
\sin x - y\cos x = z
$$
It should be noted that $y$ and $z$ will be known at runtime and that $0 < x < \pi/2$.
I remember doing something like this in calculus, but it has been a while and searching the web has failed to enlighten me.

A:

This is possible, but it is certainly not trivial. What we need to do to solve it is turn the left hand $\sin(x)-y\cos(x)$ into something of the form $c\sin(x+b)$ for some constants $c$ and $b$ which can be computed from $y$. This is because there is no way we can invert two "special functions" like $\sin$ and $\cos$ at the same time and thus need to find a different identity.
However, it turns out that this is fairly easy to do; using the identity
$$\sin(x+b)=\sin(x)\cos(b)+\cos(x)\sin(b)$$
which, gives, when multiplied by $c$
$$c\sin(x+b)=c\sin(x)\cos(b)+c\cos(x)\sin(b)$$
and we want the above to equal $\sin(x)-y\cos(x)$ - thus, if we get the coefficients of $\sin(x)$ and $\cos(x)$ right, we are really requiring a simultaneous solution to:
$$c\cos(b) = 1$$
$$c\sin(b) = -y$$
What can be seen by squaring and adding the above two equations is
$$c^2(\cos(b)^2+\sin(b)^2)=c^2=1^2+(-y)^2$$
which yields $c=\sqrt{1+y^2}$. Taking the ratio of the two equations gives
$$\tan(b)=-y$$
so $b=\tan^{-1}(-y)$.
This tells us that we can write
$$\sin(x)-y\cos(x)=\sqrt{1+y^2}\sin(x-\tan^{-1}(y))$$
and to solve for the above equalling $z$ we simply undo the operations in order to receive:
$$x=\sin^{-1}\left(\frac{z}{\sqrt{1+y^2}}\right)+\tan^{-1}(y).$$

