Determinant and Inverse of a 2x2 Matrix

Calculates the determinant of the matrix [[a, b], [c, d]] as ad − bc and the four entries of its inverse. When the determinant is zero there is no inverse.

For a two by two matrix both the determinant and the inverse have short closed forms, so there is no need for elimination or any general algorithm.

A=(abcd),detA=adbcA = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, \quad \det A = ad - bc
A1=1adbc(dbca)A^{-1} = \dfrac{1}{ad - bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}

To build the inverse: swap aa and dd, flip the signs of bb and cc, then divide everything by the determinant.

Example

Take a=4a = 4, b=7b = 7, c=2c = 2, d=6d = 6. The determinant is

detA=4×67×2=2414=10\det A = 4 \times 6 - 7 \times 2 = 24 - 14 = 10

It is not zero, so an inverse exists:

A1=110(6724)=(0.60.70.20.4)A^{-1} = \dfrac{1}{10} \begin{pmatrix} 6 & -7 \\ -2 & 4 \end{pmatrix} = \begin{pmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{pmatrix}

Notes