I need help with a partial derivative I was given a function and I need to find a partial derivative of it. The result I got is different from the answer, and I don't know why. Here's the function:
$$sin(\theta_{a}) = \frac{\sqrt{[R_Y\sin(a) - R_Z\cos(a)\cos(A)]^2 + [R_X\sin(a) + R_Z\sin(A)\cos(a)]^2 + [R_Y\sin(A)\cos(a) + R_X\cos(A)\cos(a)]^2}}{\mid R \mid}$$
where $$ R = \sqrt{R_X^2 + R_Y^2 + R_Z^2} $$
Here's what I need to do:
$$ \frac{\partial \sin(\theta_{a})}{\partial R_Z} $$
The correct answer is:
$$ \frac{\partial \sin(\theta_{a})}{\partial R_Z} = \frac{1}{2} \frac{1}{\mid R \mid} \frac{1}{\sqrt{...}}\big\{-2\cos(a)\sin(A)[R_Y\sin(a)-R_Z\cos(a)\cos(A)] + 2\sin(A)\cos(a)[R_X\sin(a)+R_Z\sin(A)\cos(a)]\big\}$$
Where $ \sqrt{...} $ is the numerator of the function.
My result fallows this derivation principle:
$$ \frac{f'(x) \cdot g(x) - f(x) \cdot g'(x)}{g(x)^2}$$
However the only way to get the result shown above is by not deriving the denominator $\mid R \mid $ by $ R_Z $ but considering it instead as constant.  Is there a reason why I shouldn't do it or am I mistaken somewhere?
 A: I can tell you that for the problem as currently phrased, you are correct. I've made some hopefully obvious variable name substitutions. Its easier to compute $\partial_{r_z}(\sin \theta_a)^2$,
$$F(r_z) := (\sin \theta_a)^2 = \frac{(r_ys_a - r_z c_a c_A)^2 + (r_x s_a + r_z s_A c_a)^2 + (r_ys_A c_a + r_xc_Ac_a)^2}{|r|^2}$$
$$ F'(r_z) = {\scriptsize \frac{2|r|^2(-c_a c_A(r_ys_a - r_z c_a c_A) + s_Ac_a (r_x s_a + r_z s_A c_a)) - 2r_z \left((r_ys_a - r_z c_a c_A)^2 + (r_x s_a + r_z s_A c_a)^2 + (r_ys_A c_a + r_xc_Ac_a)^2\right)}{|r|^4}} $$
Then note that they are claiming that
$$ F'(r_z) = 2\partial_{r_z}(\sin \theta_a)\sin \theta_a = \frac{2(-c_a c_A(r_ys_a - r_z c_a c_A) + s_Ac_a (r_x s_a + r_z s_A c_a))}{|r|^2}$$
which is only true if you  enforce that the denominator is constant. This can be done, but as written, you are correct.
One example of such a scenario is if you consider $F$ along a path $r=r(t)$ where $|r|=C$ is constant. Then
$$ \frac{d}{dt} F(r(t)) = \frac{d}{dt} \frac{(...)}{|r(t)|^2} = \frac{d}{dt} \frac{(...)}{C^2} = \frac{d/dt (...)}{C^2}  $$
Even still, this turns $r_x,r_y$ into functions of $t$ so the derivative is not as given (e.g. $F(\sqrt{R^2-r_y^2-r_z^2},r_y,r_z)$)
Without any constraints, the full derivative is
$$ \partial_{r_z}\sin(\theta_a) = \frac{F'}{2\sin(\theta_a)} =
\frac{ \frac{2|r|^2(-c_a c_A(r_ys_a - r_z c_a c_A) + s_Ac_a (r_x s_a + r_z s_A c_a)) - 2r_z \left((r_ys_a - r_z c_a c_A)^2 + (r_x s_a + r_z s_A c_a)^2 + (r_ys_A c_a + r_xc_Ac_a)^2\right)}{|r|^4}}{2\sqrt{ \frac{(r_ys_a - r_z c_a c_A)^2 + (r_x s_a + r_z s_A c_a)^2 + (r_ys_A c_a + r_xc_Ac_a)^2}{|r|^2}}} = 
\frac{\scriptsize |r|^2(-c_a c_A(r_ys_a - r_z c_a c_A) + s_Ac_a (r_x s_a + r_z s_A c_a)) - r_z \left((r_ys_a - r_z c_a c_A)^2 + (r_x s_a + r_z s_A c_a)^2 + (r_ys_A c_a + r_xc_Ac_a)^2\right)}{|r|^3\sqrt{(r_ys_a - r_z c_a c_A)^2 + (r_x s_a + r_z s_A c_a)^2 + (r_ys_A c_a + r_xc_Ac_a)^2}}\\$$
