Coordinate systems/Derivation of formulas/Cartesian from spherical unit vectors

From Wolfram Mathworld, we have the following relations for the unit vectors in a Spherical coordinate system:

$$\begin{align}

\hat{\mathbf r}&=\sin\theta\cos\phi\hat{\mathbf x}+\sin\theta\sin\phi\hat{\mathbf y}+\cos\theta\hat{\mathbf z} \\ \hat{\boldsymbol\theta}&=\cos\theta\cos\phi\hat{\mathbf x}+\cos\theta\sin\phi\hat{\mathbf y}-\sin\theta\hat{\mathbf z} \\ \hat{\boldsymbol\phi}&=-\sin\phi\hat{\mathbf x}+\cos\phi\hat{\mathbf y} \end{align}$$

We first write this as a matrix equation:

$$ \begin{pmatrix} \hat{\mathbf r} \\ \hat{\boldsymbol\theta} \\ \hat{\boldsymbol\phi} \end{pmatrix} = \begin{pmatrix} \sin\theta\cos\phi & \sin\theta\sin\phi & \cos\theta \\ \cos\theta\cos\phi & \cos\theta\sin\phi & -\sin\theta \\ -\sin\phi & \cos\phi & 0 \end{pmatrix} \begin{pmatrix} \hat{\mathbf x} \\ \hat{\mathbf y} \\ \hat{\mathbf z} \end{pmatrix} $$

We can then find the inverse of the matrix to make $$\hat{\mathbf x},\hat{\mathbf y},\hat{\mathbf z}$$ the subjects.

$$ \begin{pmatrix} \hat{\mathbf x} \\ \hat{\mathbf y} \\ \hat{\mathbf z} \end{pmatrix} = \begin{pmatrix} \sin\theta\cos\phi & \cos\theta\cos\phi & -\sin\phi\\ \sin\theta\sin\phi & \cos\theta\sin\phi & \cos\phi\\ \cos\theta & -\sin\theta & 0 \end{pmatrix} \begin{pmatrix} \hat{\mathbf r} \\ \hat{\boldsymbol\theta} \\ \hat{\boldsymbol\phi} \end{pmatrix} $$

Which was what we set out to show.