Udemy | Introductory Programming Course | Math Prerequisite

The Matrix — not the movie

Prerequisites for Programming and Algorithms

Kaivalya Vanguri
5 min readAug 26, 2024
Image Source: TMDB https://www.themoviedb.org/movie/603-the-matrix/images/posters

This blog is to discuss the Matrix, and yes, I am not talking about the famous Sci-fi Movie Matrix. It is the Mathematical Structure, an Array of Numeric Values, that is called a Matrix, and that’s what we are going to learn. If you haven’t gone through the other concepts, you can check them out in Math Prerequisites link.

A matrix can hence be defined as a rectangular array of numbers.

Whereas a vector is a one-dimensional array of numbers.

A row vector

or column vector

are examples of vector.

Matrices can be of any order. Depending on the order, type, determinant and other features there are classified into several types of Matrices, a few useful ones are:

A zero Matrix of different orders 1x1, 1x2, 2x2, 2x1 will look something like this.

A diagonal Matrix will have non-zero elements only on the principal diagonal.

An identity Matrix

In a upper-triangular matrix all elements with i≥j have a value 0.

In a lower-triangular matrix all elements with i≤j have a value 0.

A permutation Matrix is about having only 1 element with the value 1 for every row and column.

The symmetric Matrix is having the same element value at aᵢⱼ and aⱼᵢ.

aᵢⱼ = aⱼᵢ

The skew-symmetric Matrix is having the negative of aⱼᵢ element at the aᵢⱼ position.

aᵢⱼ = -aⱼᵢ

Basic Matrix Operations

For both Matrix Addition and Matrix Subtraction the two matrices performing the operation must have the same number of rows and columns. The following examples show the steps to perform these two operations.

Matrix Addition

Matrix Subtraction

Matrix Multiplication

Matrix Multiplication happens only when two matrices are compatible. Matrix Multiplication requires the order of the two matrices to be m x n and n x p. Where the number of columns of the first matrix is the same as the number of rows of the second matrix.

The following steps show how the multiplication of two matrices occur. It is crucial to remember that Matrix Multiplication is not commutative.

Matrix Determinants

The determinant of a matrix is a scalar value that is computed from the elements of a matrix. The determinant of a matrix exists only when it is a square matrix.

Below is the step wise demonstration of finding det for a 3x3 matrix

Matrix Inverse

Cofactor Matrix: The cofactor matrix C of a matrix A is a matrix where each element Cᵢⱼ is the cofactor of the element aᵢⱼ in A

Adjoint (or Adjugate) Matrix: The adjoint (or adjugate) matrix adj(A) is the transpose of the cofactor matrix C

Inverse of a matrix can be defined as follows in terms of adjoint of a Matrix.

The inverse of a matrix (A) can also be defined as a matrix A⁻¹ when A is multiplied by A⁻¹ and the result is the identity matrix I. Mathematically, this can be expressed as:

A⋅A⁻¹=A⁻¹⋅A=I

Here is an example of how to find an inverse of a 2x2 matrix:

Matrix Ranks

The rank of a matrix is the maximum number of linearly independent row or column vectors in the matrix. It represents the dimension of the vector space spanned by its rows or columns. To understand this better try to understand what a row echelon form of the matrix is.

Row Echelon Matrix can be created by converting the matrix to its row echelon form using Gaussian elimination. The number of non-zero rows in this form is the rank of the matrix.

Although this Matrix has all its elements non zero, Its Rank is 2 Because its Row Echelon form will look like this:

From this the number of non-zero rows can be concluded as 2, hence the rank will be 2.

Hope this gives a brief overview of what Matrices look like. There are a lot of Matrix properties that haven’t been covered. But this article is to serve as a Base for the learning components in our

Course on Competitive Programming and deriving Algorithms.

--

--