Challenge
Given nine numbers, a, b, c, d, e, f, g, h, i
, as input which correspond to the square matrix:
$$\mathbf{M} = \begin{pmatrix}a& b& c\\ d& e& f\\ g& h& i\end{pmatrix}$$
Find the inverse of the matrix, \$\mathbf{M}^{-1}\$ and output its components.
Inverse Matrix
The inverse of a matrix 3 by 3 obeys the following equation:
$$\mathbf{MM}^{-1} = \mathbf{M}^{-1}\mathbf{M} = \mathbf{I} = \begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}$$
And can be calculated as:
$$\mathbf{M}^{-1} = \frac{1}{\det(\mathbf{M})}\mathbf{C}^T$$
Where \$\mathbf{C}\$ is the matrix of cofactors:
$$\mathbf{C}=\begin{pmatrix}ei-fh&fg-di&dh-eg\\ch-bi&ai-cg&bg-ah\\bf-ce&cd-af&ae-bd\end{pmatrix}$$
And \$\mathbf{C}^T\$ is the transpose of \$\mathbf{C}\$:
$$\mathbf{C}^T = \begin{pmatrix}ei-fh&ch-bi&bf-ce\\fg-di&ai-cg&cd-af\\dh-eg&bg-ah&ae-bd\end{pmatrix}$$
And \$\det(\mathbf{M})\$ is the determinant of \$\mathbf{M}\$:
$$\det(\mathbf{M}) = a(ei-fh)-b(di-fg)+c(dh-eg)$$
Worked Example
For example, let's say the input is 0, -3, -2, 1, -4, -2, -3, 4, 1
. This corresponds to the matrix:
$$\mathbf{M} = \begin{pmatrix}0&-3&-2\\1&-4&-2\\-3&4&1\end{pmatrix}$$
Firstly, let's calculate what's known as the determinant using the formula above:
$$\det(\mathbf{M}) = 0(-4\times1-(-2)\times4) - (-3)(1\times1-(-2)\times-3) + (-2)(1\times4-(-4)\times-3) = 1$$
Next let's calculate the matrix of cofactors:
$$\mathbf{C} = \begin{pmatrix}-4\times1-(-2)\times4& -(1\times1-(-2)\times-3)&1\times4-(-4)\times-3\\-(-3\times1-(-2)\times4)&0\times1-(-2)\times-3&-(0\times4-(-3)\times-3)\\-3\times-2-(-2)\times-4&-(0\times-2-(-2)\times1)&0\times-4-(-3)\times1\end{pmatrix}$$
$$= \begin{pmatrix}4&5&-8\\-5&-6&9\\-2&-2&3\end{pmatrix}$$
We then need to transpose \$\mathbf{C}\$ (flip the rows and columns) to get \$\mathbf{C}^T\$:
$$\mathbf{C}^T = \begin{pmatrix}4&-5&2\\5&-6&-2\\-8&9&3\end{pmatrix}$$
Finally, we can find the inverse as:
$$\mathbf{M}^{-1} = \frac{1}{\det(\mathbf{M})}\mathbf{C}^T = \frac{1}{1}\begin{pmatrix}4&-5&2\\5&-6&-2\\-8&9&3\end{pmatrix}=\begin{pmatrix}4&-5&2\\5&-6&-2\\-8&9&3\end{pmatrix}$$
So the output would be 4, -5, -2, 5, -6, -2, -8, 9, 3
.
Rules
The given matrix will always have an inverse (i.e. non-singular). The matrix may be self-inverse
The given matrix will always be a 3 by 3 matrix with 9 integers
The numbers in the input will always be integers in the range \$-1000 \leq n \leq 1000\$
Non-integer components of the matrix may be given as a decimal or a fraction
Examples
Input > Output
1, 0, 0, 0, 1, 0, 0, 0, 1 > 1, 0, 0, 0, 1, 0, 0, 0, 1
0, -3, -2, 1, -4, -2, -3, 4, 1 > 4, -5, -2, 5, -6, -2, -8, 9, 3
1, 2, 3, 3, 1, 2, 2, 1, 3 > -1/6, 1/2, -1/6, 5/6, 1/2, -7/6, -1/6, -1/2, 5/6
7, 9, 4, 2, 7, 9, 3, 4, 5 > -1/94, -29/94, 53/94, 17/94, 23/94, -55/94, -13/94, -1/94, 31/94
Winning
The shortest code in bytes wins.