<s>[INST] How can simultaneous sinusoidal equations be solved? I have come across a set of simultaneous equations which I can't figure out how to solve. I have 3 equations and only two unknowns, but they are angular quantities and feature in the equations as sinusoidal functions of the angular quantities.
The system of equations is:
$$ \begin{Bmatrix}\cos\psi\sin\theta+\cos\theta\sin\phi\sin\psi \\ \sin\psi\sin\theta-\cos\psi\cos\theta\sin\phi \\ \cos\phi\cos\theta \end{Bmatrix} = \begin{Bmatrix} x \\ y \\ z \end{Bmatrix} $$
Where: x, y, z and psi are known and phi and theta are unknown.
Is it possible to rearrange these equations to solve for theta and phi using the other terms?
 [/INST] The system is not always solvable. The two first equations factor as
$$\tag{1} \begin{pmatrix} \cos\psi & \sin\psi \\ \sin\psi & -\cos\psi \end{pmatrix}
\begin{pmatrix} \sin\theta \\ \cos\theta \sin\phi \end{pmatrix}
= \begin{pmatrix} x \\ y \end{pmatrix} $$
where the first factor is just a reflection in a line through the origin, so
$$ \sin^2\theta + \cos^2\theta\sin^2\phi = x^2 + y^2 $$
Squaring the third equation gives
$$ \cos^2\theta \cos^2\phi = z^2 $$
and adding these equations give
$$ x^2+y^2+z^2 = \sin^2\theta + \cos^2\theta(\sin^2\phi + \cos^2\phi) = 1 $$
so your system only has a solution when $(x,y,z)$ is a point on the unit sphere.
If your constants satisfy this, a natural approach would be to divide out the reflection matrix in $(1)$, producing
$$ \begin{cases} \sin \theta = x' \\ \cos\theta\sin\phi = y' \\ \cos\theta \cos\phi = z \end{cases} $$
for some $x'$ and $y'$. From here you get $\theta = \arcsin x'$ and and $\phi = \arctan \frac{y'}{z}$, both up to a choice of quadrants that have to be made in a matching way, possibly just by trial and error.
</s>