Euler Equation
\begin{align*}
&\mathbf{I}\,{\dot{\omega}}+\mathbf\omega\times \left(\mathbf{I}\,\mathbf\omega\right)=\mathbf\tau\tag 1
\end{align*}
and the kinematic equation
\begin{align*}
&\mathbf{\dot{\phi}}=\mathbf{A}(\mathbf{\phi})\,\mathbf{\omega}\tag 2
\end{align*}
all vector components and the inertia tensor must be given either in body system or in inertial system
the inertia tensor in inertial system :
\begin{align*}
&\mathbf{I}_I=\mathbf{R}\,\mathbf{I}_B\,\mathbf{R}^T
\end{align*}
equation (2) in inertial system: with
\begin{align*}
& \left[ \begin {array}{ccc} 0&-\omega_{{z}}&\omega_{{y}}
\\ \omega_{{z}}&0&-\omega_{{x}}\\
-\omega_{{y}}&\omega_{{x}}&0\end {array} \right]_B=\mathbf{R}^T\,\mathbf{\dot{R}}\quad\Rightarrow\quad
\mathbf{\omega}_B=\mathbf{J}_R(\mathbf{\phi})\,\mathbf{\dot{\phi}}_B~\Rightarrow~
\mathbf{\dot{\phi}}_B=\underbrace{\mathbf{J}_R^{-1}}_{\mathbf{A}}\,\mathbf{\omega}_B
\end{align*}
\begin{align*}
&\mathbf{\dot{\phi}}_I=\underbrace{\mathbf{R}\,\mathbf{A}\mathbf{R^T\,}}_{\mathbf{A}(\mathbf{\phi})}\mathbf{\omega}_I
\end{align*}
the rotation matrix $~\mathbf{R}~$ can build up from three rotation matrices for example
\begin{align*}
\mathbf{R}&=\mathbf{R}_x\,\mathbf{R}_y\,\mathbf{R}_z\\
&= \left[ \begin {array}{ccc} 1&0&0\\ 0&\cos \left(
\phi_{{x}} \right) &-\sin \left( \phi_{{x}} \right)
\\ 0&\sin \left( \phi_{{x}} \right) &\cos \left(
\phi_{{x}} \right) \end {array} \right]
\,
\left[ \begin {array}{ccc} 1&0&0\\ 0&\cos \left(
\phi_{{y}} \right) &-\sin \left( \phi_{{y}} \right)
\\ 0&\sin \left( \phi_{{y}} \right) &\cos \left(
\phi_{{y}} \right) \end {array} \right]
\,
\left[ \begin {array}{ccc} 1&0&0\\ 0&\cos \left(
\phi_{{z}} \right) &-\sin \left( \phi_{{z}} \right)
\\ 0&\sin \left( \phi_{{z}} \right) &\cos \left(
\phi_{{z}} \right) \end {array} \right]\tag 3
\end{align*}
- $~\mathbf I~$ inertia tensor
- $~\mathbf\omega~$ angular velocity vector
- $~\mathbf\tau~$ external torque vector
- $~\mathbf{\dot{\phi}}~$ angle velocity vector
- $~\mathbf R~$ rotation matrix between B-system and I-system
- $~I~$ inertial system
- $~B~$ body system
with equation (3)
\begin{align*}
&
\mathbf{\omega}_B=\mathbf{J}_R(\mathbf{\phi})\,\mathbf{\dot{\phi}}_B\quad,
\mathbf{J}_R=\left[ \begin {array}{ccc} \cos \left( \phi_{{y}} \right) \cos
\left( \phi_{{z}} \right) &\sin \left( \phi_{{z}} \right) &0
\\ -\cos \left( \phi_{{y}} \right) \sin \left( \phi_
{{z}} \right) &\cos \left( \phi_{{z}} \right) &0\\
\sin \left( \phi_{{y}} \right) &0&1\end {array} \right]
\quad\Rightarrow\\
&\mathbf A_B=\left[ \begin {array}{ccc} {\frac {\cos \left( \phi_{{z}} \right) }{
\cos \left( \phi_{{y}} \right) }}&-{\frac {\sin \left( \phi_{{z}}
\right) }{\cos \left( \phi_{{y}} \right) }}&0\\
\sin \left( \phi_{{z}} \right) &\cos \left( \phi_{{z}} \right) &0
\\ -{\frac {\sin \left( \phi_{{y}} \right) \cos
\left( \phi_{{z}} \right) }{\cos \left( \phi_{{y}} \right) }}&{\frac
{\sin \left( \phi_{{y}} \right) \sin \left( \phi_{{z}} \right) }{\cos
\left( \phi_{{y}} \right) }}&1\end {array} \right]\quad,
\mathbf{A}_I=\left[ \begin {array}{ccc} 1&{\frac {\sin \left( \phi_{{x}} \right)
\sin \left( \phi_{{y}} \right) }{\cos \left( \phi_{{y}} \right) }}&-{
\frac {\cos \left( \phi_{{x}} \right) \sin \left( \phi_{{y}} \right) }
{\cos \left( \phi_{{y}} \right) }}\\ 0&\cos \left(
\phi_{{x}} \right) &\sin \left( \phi_{{x}} \right)
\\ 0&-{\frac {\sin \left( \phi_{{x}} \right) }{\cos
\left( \phi_{{y}} \right) }}&{\frac {\cos \left( \phi_{{x}} \right) }
{\cos \left( \phi_{{y}} \right) }}\end {array} \right]
\end{align*}