[Question]
  [
## 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.
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), 54 bytes
```
th3LZ)t,3:q&XdpswP]w-lw/GtY*tXdsGXdsUw-IXy*2/+GtXds*-*
```
[Try it online!](https://tio.run/##y00syfn/vyTD2CdKs0TH2KpQLSKloLg8ILZcN6dc370kUqskIqXYHYhDy3U9Iyq1jPS13UFCWrpa/1UV3PKLFJLz88pS8zJT85JTuVQVog11FAyAyBpEGsIYIHYsSBbI0DUGYiNrkKSuCYQJEjKBKQGKG@koGFsrGIMNAEobgRnGYFlzHQVLoGKwIIgNVgbUaxr7n5DhAA "MATL – Try It Online")
Just to keep it interesting, doesn't use the inbuilt matrix division or determinant functions to do it.
Instead, computes the determinant using the [Rule of Sarrus](https://en.wikipedia.org/wiki/Rule_of_Sarrus).
[![Rule of Sarrus demonstration](https://i.stack.imgur.com/TkVi5.png)](https://i.stack.imgur.com/TkVi5.png)
And the adjugate (transposed cofactor matrix) using [Cayley–Hamilton formula](https://en.wikipedia.org/wiki/Adjugate_matrix#Cayley%E2%80%93Hamilton_formula).
$$ {\displaystyle \operatorname {adj} (\mathbf {A} )={\frac {1}{2}}\left((\operatorname {tr} \mathbf {A} )^{2}-\operatorname {tr} \mathbf {A} ^{2}\right)\mathbf {I} \_{3}-\mathbf {A} \operatorname {tr} \mathbf {A} +\mathbf {A} ^{2}.} $$
### Commented code:
```
% Finding determinant
th    % concatenate the matrix to itself sideways
3LZ)  % chop off the last column (since the Rule of Sarrus doesn't need it)
t     % duplicate this matrix (say S)
,     % do this twice:
  3:q&Xd  % get the first three diagonals of S
  ps      % multiply each diagonal's values and add the results
  wP      % switch and flip the matrix (to get the popposing diagonals next time)
]w    % close loop, switch to have correct order of sums
-     % subtract - we now have the determinant
lw/   % invert that
% Finding adjugate using Cayley–Hamilton formula
GtY*  % A^2 term (last term of the formula)
tXds  % trace(A^2) for term 1 of formula
GXdsU % (trace(A))^2 for term1 of formula
w-    % (trace(A))^2 - trace(A^2)
IXy*  % multiply that by the identity matrix
2/    % divide that by 2 - term 1 complete
+
GtXds* % A*trA for term 2 of formula
-      % subtract to get adj(A)
*      % multiply by the inverse of determinant we found earlier
       % implicit output
```
We could go even ~~more insane~~ purer by replacing the matrix multiplication `GtY*` done for \$ A^2 \$, with something like `3:"Gt!@qYS*!s] 3$v t&v 3:K-&Xd` ([Try it on MATL Online](https://matl.io/?code=tY%2a+%27--%27+3%3A%22Gt%21%40qYS%2a%21s%5D+3%24v+t%26v+3%3AK-%26Xd&inputs=%5B0%2C+-3%2C+-2%3B+1%2C+-4%2C+-2%3B+-3%2C+4%2C+1%5D&version=20.9.1)).
The more direct and obvious way:
## 4 bytes
```
-1Y^
```
[Try it online!](https://tio.run/##y00syfn/X9cwMu6/qoJbfpFCcn5eWWpeZmpeciqXqkK0oY6CARBZg0hDGAPEjgXJAhm6xkBsZA2S1DWBMEFCJjAlQHEjHQVjawVjsAFAaSMwwxgsa66jYAlUDBYEscHKgHpNY/8TMhwA "MATL – Try It Online")
*(-1 byte thanks to @Luis Mendo.)*
`-1` - Push the literal -1
`Y^` - Raise input to that power (implicit input, implicit output)
[Answer]
**APL(Dyalog Classic),1 byte**
```
⌹
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbhEc9O4EMBWMF40e9WwwVDMAQTgMA)
if a flat lis is required this is 8 bytes
```
,∘⌹3 3∘⍴
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbBJ1HHTMe9ew0VjAGMXq3AEUVDBUMwBBOAwA)
[Answer]
# **R, ~~51~~ ~~35~~ ~~27~~ ~~8~~ 5 bytes**
```
solve
```
[Try it online!](https://tio.run/##K/qfpmCj@784P6cs9X@aRm5iSVFmhUayhoGOrrGOrpGOoY6uCYgG8kx0DDV1jIEwRFPz////AA "R – Try It Online")
First go at doing one of these golf challenges. Sorry if my formatting is wrong!
Saved a total additional 11 bytes thanks to Giuseppe!
Saved an additional 19 bytes thanks to JAD!
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 [bytes](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page)
```
æ*-
```
[Try it online!](https://tio.run/##y0rNyan8///wMi3d////R0cb6igYAFGsjkI0kDZEMEG82FgA "Jelly – Try It Online")
Assuming we can take input and provide as a 2D list of integers. If a flat list of integers is really required for both input and output, then [this](https://tio.run/##y0rNyan8/7/Y@PAyLV23////RxvqKBjAEAo7FgA) works for 6 bytes. 
[Answer]
# JavaScript (ES6), 123 bytes
*Saved 2 bytes thanks to @Mr.Xcoder*  
*Saved 1 byte thanks to @ETHproductions*
Takes input as 9 distinct values.
```
(a,b,c,d,e,f,g,h,i)=>[x=e*i-h*f,c*h-b*i,b*f-c*e,y=f*g-d*i,a*i-c*g,d*c-a*f,z=d*h-g*e,g*b-a*h,a*e-d*b].map(v=>v/=a*x+b*y+c*z)
```
[Try it online!](https://tio.run/##ZYzLDoJADEX3fMUsmdJBUbbDjxgX8waDDBFDgJ/HQnBhXNyk9/S0DzWqwbya/i26aN3q5Zoq1GjQokOPAWtsuKxuk3TQiBo8GqiFhgY1eGHA4Sw9BGGJKDIMBLRghCJzkZbcQE4ATaQmw5Gp7/lT9ekoq/EkFUyZhjkzsPDVxG6IrcvbGFKfJoyxAhk779naNhU/bScJ58n/Ka3ElXLB45Eov23jrDxO1w8 "JavaScript (Node.js) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 2 bytes
```
%.
```
Just a built-in primitive
[Try it online!](https://tio.run/##dYyxCoAgAAV3v@IIQ4ISzSIK@haHSKKloblvNyWIlnjD8eC4PYZz1hgmTCx1rEShUWHWipprIpxCrMt2EHA4afAO32LxXWZ6HfYxVEOa@uhIm8p5L/9UOTCmVEtmjvYi3g "J – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 139 bytes
```
def F(a,b,c,d,e,f,g,h,i):x=e*i-f*h;y=f*g-d*i;z=d*h-e*g;print[j/(a*x+b*y+c*z)for j in x,c*h-b*i,b*f-c*e,y,a*i-c*g,c*d-a*f,z,b*g-a*h,a*e-b*d]
```
[Try it online!](https://tio.run/##bZBNboMwEIX3nGJ22JMhrRopUonYdpcTIKSAscFR@JEhFeTydCChjZSuPJ438/z8tWNfNvXHNOXawJdIKSNFOWkyVFBJVoZDpNEGBsvDGBksghzt4RblWAYai4PT/dXV8flNpDhsMhw3Cm/SNA7OYGsYSPFghpYyNIFCTSOlbKewYCUPUjR0Y63gqmRF82yeTJ5xTQXdWLUj2KptXD9fsubSEahOE3TcvVgzPg1uq7R3Vulu3TjO98HzXv4E0eom/BfRl553tPU3D/2HY9Xi@Yzfw11CsJS7cL@W@/AzSTyvdbbuwb8v@ASneyAxN@S2u2YdMxMPuJLZiZnthhlLhigehCWBn@vel6e74a8tIPxZrzzE4404XqInFC/h@VziJ4mc155ysO30Aw "Python 2 – Try It Online") (Has `return` instead of `print` for ease of testing.)
[Answer]
# Python 3, 77 bytes
```
import numpy
lambda l:(numpy.matrix(l).reshape(-1,3)**-1).ravel().tolist()[0]
```
Takes input as a flat list.
It's 63 bytes if input is taken as a 2D array:
```
import numpy
lambda l:(numpy.matrix(l)**-1).ravel().tolist()[0]
```
[Answer]
# [Google Sheets](https://sheets.google.com), 16 bytes
```
=MINVERSE(A1:C3)
```
Input is in the range `A1:C3`
Built-ins are boring
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 143 bytes
```
import StdEnv
$a b c d e f g h i#p=e*i-h*f
#q=f*g-d*i
#r=d*h-g*e
=[v/(a*p+b*q+c*r)\\v<-[p,c*h-b*i,b*f-c*e,q,a*i-c*g,d*c-a*f,r,g*b-a*h,a*e-d*b]]
```
[Try it online!](https://tio.run/##NU45DsIwEOzzipVCAYvNXeIOCiQ6SqBYr49YSkISQiQ@jzEgmtFcGg2XlupY3cyjtFBRqGOomlvXw6k3@3rIRgQaGAxYcOChgJA3ymKQBbosb5VDLw2GLO@UwUJ6tJk6D/MxYTPV2E4Zu8nlMmzluRGcChqD0OgkoxWtoDTE6IVBloROdMKjTqxIiU27@nqNp57SHQUjWMwWINcfWCVYfsjmr77@5mfHF7uS/D3KwzHunjVVge9v "Clean – Try It Online")
[Answer]
# Perl 5, 179 bytes
```
sub{($a,$b,$c,$d,$e,$f,$g,$h,$i)=@_;map$_/($a*$x+$b*$y+$c*$z),$x=$e*$i-$f*$h,$c*$h-$b*$i,$b*$f-$c*$e,$y=$f*$g-$d*$i,$a*$i-$c*$g,$c*$d-$a*$f,$z=$d*$h-$e*$g,$b*$g-$a*$h,$a*$e-$b*$d}
```
[Try it online](https://tio.run/##dY3hSsNAEIT/@xT5MWBz3dPUNEgJJ76Az1AuzSW9ok3oKTQVX924t4c/BAt7yzD7zdzoTq/VjGDm8NF8LmAJDWFHaAmO0BF6wp7gc/O8rd/siO09UwrnJRqFaYmdwiUnnA2cgtfoVOTZ3etIeIq709HhwslEoNdo5WQlwqdeIq2ODn96MRHgBienRiJWmnk7aW6/5vom2Ck7DP6Y3VIcBP20WFFW/M4fnf/P80mX/B4E1@sko7W@HmKSoVIm6RQvr/CPlG2kkLGkU3@V1/P3ML774Rhm/VLdFaviBw "Perl 5 – Try It Online").
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 6 bytes
```
m->1/m
```
Takes multiplicative inverse in the matrix ring \$\mathrm{M}\_n\$.
[Try it online!](https://tio.run/##NYvNCoMwEIRfZfBkIEtNokgJ@iKSgxdFaMoivfTp425aYX@@nZnl9Txo57JhQsk0u0cuK/Pr22bQDD6P90ew0aPB1mZjLJbFWXRSUae7QTmJK5uCtI/qUf9Dlfp/QmRvESJCfRfXVwhqjhZPiVZNuabkc0jJlAs "Pari/GP – Try It Online")
[Answer]
# APL (Dyalog), 7 bytes
```
,⌹3 3⍴⎕
```
Takes input as a flat list and outputs as a flat list
[**Try it online!**](https://tio.run/##SyzI0U2pTMzJT///qKNdofi/zqOencYKxo96tzzqmwoS@1/MZaBwaL0xEBspGAJJEzALJGICAA)
[Answer]
# [Factor](https://factorcode.org/) + `math.matrices.extras`, 5 bytes
```
recip
```
[Try it online!](https://tio.run/##S0tMLskv@v@/KDU5s@D/fwA "Factor – Try It Online")
[![enter image description here](https://i.stack.imgur.com/BDijG.gif)](https://i.stack.imgur.com/BDijG.gif)
[Answer]
# [Ruby](https://www.ruby-lang.org/) + `-rmatrix`, 24 bytes
```
->a{Matrix[*a].inv.to_a}
```
Or, if taking in and outputting a Matrix is apart of standard I/O, then this becomes 10 bytes.
```
->a{a.inv}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpck20km5RbmJJUWaFUuyiNNulpSVpuhY7dO0Sq33BotFaibF6mXlleiX58Ym1EOmb2gVFmXklCmnR0dGGOgpGOgrGsToK0cY6CiAeiGkEZhrHxsZyQbQsWAChAQ)
[Answer]
# Perl, 226 + 4 (`-plF,` flag) = 230 bytes
```
$_=join', ',map$_/($a*$x+$b*$y+$c*$z),$x=($e=$F[4])*($i=$F[8])-($f=$F[5])*($h=$F[7]),($c=$F[2])*$h-($b=$F[1])*$i,$b*$f-$c*$e,$y=$f*($g=$F[6])-($d=$F[3])*$i,($a=$F[0])*$i-$c*$g,$c*$d-$a*$f,$z=$d*$h-$e*$g,$b*$g-$a*$h,$a*$e-$b*$d
```
[Try it online](https://tio.run/##VY7NbsIwEITvPEUOI@GEtQokKe3BV16iihAQ56eiJGp7AB6@7o6tHirZq29mdtee/eelDgEH9z6N16VkS/k4zjg8GRwL3FY4FbivcC7wyAU3Z@Ad9m9VkxcGI/Glya1BR6yjOxB3TS4GZ@JWXQzac6LaUI3CvZ3lXi@4O3Q62DN/jutaYpla9SdU66jiSC@sreUXO8HDoeUL8DHSzX2MBmH1lk4bwkay9d/5xwstttS7jYGtEtKqGKunsowncWosFzvJXmOTGonTTP0zzd/jdP0Kdr7s5Rc).
[Answer]
# Noether, 168 bytes
```
I~aI~bI~cI~dI~eI~fI~gI~hI~iei*fh*-a*di*fg*-b*-dh*eg*-c*+~zei*fh*-z/P","~nPch*bi*-z/PnPbf*ce*-z/PnPfg*di*-z/PnPai*cg*-z/PnPcd*af*-z/PnPdh*eg*-z/PnPbg*ah*-z/PnPae*bd*-z/P
```
[**Try it online**](https://beta-decay.github.io/noether?code=SX5hSX5iSX5jSX5kSX5lSX5mSX5nSX5oSX5pZWkqZmgqLWEqZGkqZmcqLWIqLWRoKmVnKi1jKit-emVpKmZoKi16L1AiLCJ-blBjaCpiaSotei9QblBiZipjZSotei9QblBmZypkaSotei9QblBhaSpjZyotei9QblBjZCphZiotei9QblBkaCplZyotei9QblBiZyphaCotei9QblBhZSpiZCotei9Q&input=MQoyCjMKMwoxCjIKMgoxCjM)
[Answer]
## Clojure, 165 bytes
```
(fn[a b c d e f g h i](let[M map C(M -(M *[e f d c a b b c a][i g h h i g f d e])(M *[f d e b c a c a b][h i g i g h e f d]))](for[i C](/ i(apply +(M *[a b c]C))))))
```
I'm sorry this outputs C in transpose, and I'm feeling lazy to re-do those long character sequences to fix it at the moment.
]