For more info on Euler Sequences, notation and convention see the generic entry on Euler angle sequences. \\
R 313 ( ϕ , θ , ψ ) = R 3 ( ψ ) R 1 ( θ ) R 3 ( ϕ ) {\displaystyle R_{313}(\phi ,\theta ,\psi )=R_{3}(\psi )R_{1}(\theta )R_{3}(\phi )} \\
The rotation matrices are
R 3 ( ψ ) = [ c ψ s ψ 0 − s ψ c ψ 0 0 0 1 ] {\displaystyle R_{3}(\psi )=\left[{\begin{matrix}c_{\psi }&s_{\psi }&0\\-s_{\psi }&c_{\psi }&0\\0&0&1\end{matrix}}\right]}
R 1 ( θ ) = [ 1 0 0 0 c θ s θ 0 − s θ c θ ] {\displaystyle R_{1}(\theta )=\left[{\begin{matrix}1&0&0\\0&c_{\theta }&s_{\theta }\\0&-s_{\theta }&c_{\theta }\end{matrix}}\right]}
R 3 ( ϕ ) = [ c ϕ s ϕ 0 − s ϕ c ϕ 0 0 0 1 ] {\displaystyle R_{3}(\phi )=\left[{\begin{matrix}c_{\phi }&s_{\phi }&0\\-s_{\phi }&c_{\phi }&0\\0&0&1\end{matrix}}\right]}
Carrying out the multiplication from right to left \\
R 1 ( θ ) R 3 ( ϕ ) = [ 1 0 0 0 c θ s θ 0 − s θ c θ ] [ c ϕ s ϕ 0 − s ϕ c ϕ 0 0 0 1 ] = [ c ϕ s ϕ 0 − s ϕ c θ c θ c ϕ s θ s θ s ϕ − s θ c ϕ c θ ] {\displaystyle R_{1}(\theta )R_{3}(\phi )=\left[{\begin{matrix}1&0&0\\0&c_{\theta }&s_{\theta }\\0&-s_{\theta }&c_{\theta }\end{matrix}}\right]\left[{\begin{matrix}c_{\phi }&s_{\phi }&0\\-s_{\phi }&c_{\phi }&0\\0&0&1\end{matrix}}\right]=\left[{\begin{matrix}c_{\phi }&s_{\phi }&0\\-s_{\phi }c_{\theta }&c_{\theta }c_{\phi }&s_{\theta }\\s_{\theta }s_{\phi }&-s_{\theta }c_{\phi }&c_{\theta }\end{matrix}}\right]} \\
Finaly leaving us with the Euler 313 sequence \\
R 3 ( ψ ) R 1 ( θ ) R 3 ( ϕ ) = [ c ψ c ϕ − s ψ s ϕ c θ c ψ s ϕ + s ψ c θ c ϕ s ψ s θ − s ψ c ϕ − c ψ s ϕ c θ − s ψ s ϕ + c ψ c θ c ϕ c ψ s θ s θ s ϕ − s θ c ϕ c θ ] {\displaystyle R_{3}(\psi )R_{1}(\theta )R_{3}(\phi )=\left[{\begin{matrix}c_{\psi }c_{\phi }-s_{\psi }s_{\phi }c_{\theta }&c_{\psi }s_{\phi }+s_{\psi }c_{\theta }c_{\phi }&s_{\psi }s_{\theta }\\-s_{\psi }c_{\phi }-c_{\psi }s_{\phi }c_{\theta }&-s_{\psi }s_{\phi }+c_{\psi }c_{\theta }c_{\phi }&c_{\psi }s_{\theta }\\s_{\theta }s_{\phi }&-s_{\theta }c_{\phi }&c_{\theta }\end{matrix}}\right]}