Jorge Valle

Jorge Valle

Jorge Valle is a front end developer with a particular passion for, and expertise in, JavaScript and user interfaces. Lately, he's also been diving into machine learning.

Finding the determinant of a 2 x 2 matrix

Finding the determinant of a square matrix, both mathematically, and programmatically using Numpy.

Matrices used

Here are the 2 matrices that I will be referring to.

$$ A = \begin{bmatrix} 1, & 2 \\ 3, & 4 \end{bmatrix} \\ B = \begin{bmatrix} 4, & 2 \\ 10, & 5 \end{bmatrix} $$
Figure 1: Matrices used.

The determinant

To find the determinant, we first identify the elements of the matrix as such.

$$ A = \begin{bmatrix} a & b \\ c & d \end{bmatrix} $$
Figure 2: Labeling the elements.

Then, we get the products of the diagonals, and subtract the product of the off-diagonal from the product of the main diagonal.

$$ \begin{align} det(A) & = ad - bc \\ & = (1 \times 4) - (2 \times 3) \\ & = 4 - 6 \\ & = -2 \end{align} $$
Figure 3: Getting the products of diagonals, and subtracting.

This yields a single number: the determinant.

Singular matrices

Now, let's calculate the determinant of B.

$$ \begin{align} det(B) & = ad - bc \\ & = (4 \times 5) - (2 \times 10) \\ & = 20 - 20 \\ & = 0 \end{align} $$
Figure 4: Doing the same to B.

This results in a determinant of 0, which tells us that the matrix B is singular. Singular matrices have no inverses.

Numpy implementation

Here are the above calculations, implemented in Numpy. Even though the linear algebra package makes this trivially easy, it's cool to understand the maths behind it.


Books, patrons and coffee in Caffè San Marco, Trieste