<s>[INST] How to solve the following simultaneous trig equations? Equation 1
$X$ = $a_1\sin(\theta_1) + a_2\cos(\theta_2)$
Equation 2
$Y$ = $a_1\cos(\theta_1) +  a_2\sin(\theta_2)$
where $X, Y, a_1,a_2$ are known.
WHAT I HAVE DONE SO FAR
Let 
$sin(\theta_1) = u_1$
$cos(\theta_1) = v_1$ 
$sin(\theta_2) = u_2$
$cos(\theta_2) = v_2$ 
And hence according  to trig identities,
$u_1^2 + v_1^2 = 1$ (3)
$u_2^2 + v_2^2 = 1$ (4)

substituting (3) and (4) in the original equations, I obtained, 
$a_2^2v_2^2 + a_1^2v_1^2 - 2Xa_2v_2 = a_1^2 - X^2$  (Equation 5) 
$a_1^2v_1^2 + a_2^2v_2^2 - 2Ya_1v_1 = a_2^2 - Y^2$  (Equation 6) 
$a_1^2u_1^2 + a_2^2u_2^2 - 2Xa_1u_1 = a_2^2 - X^2$  (Equation 7) 
$a_1^2u_1^2 + a_2^2u_2^2 - 2Ya_2u_2 = a_2^2 - Y^2$  (Equation 8) 
How do I proceed from here?
These systems of 4 non-linear equation. Is developing an analytical solution possible? Or should try to find a numerical solution using some libraries?
Thanks,
Vino
 [/INST] As I said in the comments, it looks like there is no nice closed-form solution for this. So I plugged your set of equations into Mathematica. The result is:
$$\begin{align}
\sin\theta_1=\frac{({a_1}^3-a_1{a_2}^2)X-\sqrt{-{a_1}^2 Y^2 \left({a_1}^4-2 {a_1}^2
   \left({a_2}^2+X^2+Y^2\right)+\left(-{a_2}^2+X^2+Y^2\right)^2\right)}}{2 {a_1}^2 \left(X^2+Y^2\right)}+\frac X{2a_1}\\
\cos\theta_2=\frac{(a_1{a_2}^2-{a_1}^3)X+\sqrt{-{a_1}^2 Y^2 \left({a_1}^4-2 {a_1}^2
   \left({a_2}^2+X^2+Y^2\right)+\left(-{a_2}^2+X^2+Y^2\right)^2\right)}}{2 {a_1} {a_2}
   \left(X^2+Y^2\right)}+\frac X{2a_2}
\end{align}$$
To simplify it more, let
$$\Delta=2 {a_1}^2\left(X^2+Y^2+{a_2}^2\right)-\left(X^2+Y^2-{a_2}^2\right)^2-{a_1}^4$$
then
$$\begin{align}
\sin\theta_1&=X\left(\frac{a_1^2-a_2^2}{2a_1(X^2+Y^2)}+\frac{1}{2a_1}\right)-Y\frac{\sqrt{\Delta}}{2a_1(X^2+Y^2)}\\
\cos\theta_2&=X\left(\frac{a_2^2-a_1^2}{2a_2(X^2+Y^2)}+\frac{1}{2a_2}\right) +Y\frac{\sqrt{\Delta}}{2a_2(X^2+Y^2)}
\end{align}$$
I hope this helps.
</s>