No history yet

Matrix Basics

What is a Matrix?

Think of a matrix as a rectangular grid for organizing numbers. It's like a spreadsheet or a bingo card, with information arranged in rows and columns. This simple structure is incredibly powerful in math, computer science, and engineering.

We describe the size, or dimensions, of a matrix by its number of rows and columns, always in that order. A matrix with 2 rows and 3 columns is called a "2 by 3" matrix, written as 2×32 \times 3.

Each number inside the matrix is called an element. We can locate any element using its row and column number. For a matrix named AA, the element in the ii-th row and jj-th column is denoted as AijA_{ij} or aija_{ij}. For example, in the matrix above, the element a2,1a_{2,1} is in the second row and first column.

Types of Matrices

Matrices come in a few special varieties. Knowing them will help you understand their different roles.

Rectangular and Square Matrices: Any matrix where the number of rows and columns aren't equal is a rectangular matrix. If the number of rows does equal the number of columns, it's a square matrix.

[123456]Rectangular (2x3)[9876]Square (2x2)\underbrace{\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}}_{\text{Rectangular (2x3)}} \quad \underbrace{\begin{bmatrix} 9 & 8 \\ 7 & 6 \end{bmatrix}}_{\text{Square (2x2)}}

Two other important types are special kinds of square matrices.

Diagonal Matrix

noun

A square matrix where all elements are zero except for those on the main diagonal (from the top left to the bottom right).

D=[300050002]D = \begin{bmatrix} 3 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 2 \end{bmatrix}

Identity Matrix

noun

A diagonal matrix where all the elements on the main diagonal are 1. It is denoted by II.

The identity matrix is special because in matrix multiplication, it acts just like the number 1. Multiplying any matrix by an identity matrix of the correct size leaves the original matrix unchanged.

I=[100010001]I = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

Matrix Operations

We can perform familiar arithmetic operations on matrices, but with a few new rules.

Addition and Subtraction: To add or subtract two matrices, they must have the exact same dimensions. The operation is simple: just add or subtract the corresponding elements.

[abcd]+[efgh]=[a+eb+fc+gd+h]\begin{bmatrix} a & b \\ c & d \end{bmatrix} + \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} a+e & b+f \\ c+g & d+h \end{bmatrix}

Here is an example with numbers:

[1523][1201]=[11522031]=[0322]\begin{bmatrix} 1 & 5 \\ 2 & 3 \end{bmatrix} - \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 1-1 & 5-2 \\ 2-0 & 3-1 \end{bmatrix} = \begin{bmatrix} 0 & 3 \\ 2 & 2 \end{bmatrix}

Multiplication is a bit more involved. To multiply matrix AA by matrix BB (in that order, as ABAB), the number of columns in AA must equal the number of rows in BB. If you multiply a m×nm \times n matrix by an n×pn \times p matrix, the result will be an m×pm \times p matrix.

To find the element in row ii and column jj of the resulting matrix, you multiply each element of row ii from the first matrix by the corresponding element of column jj from the second matrix, and then add up all the products. This is often called a dot product.

Let's multiply a 2×32 \times 3 matrix by a 3×23 \times 2 matrix. The result will be a 2×22 \times 2 matrix.

A=[123456],B=[789123]A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}, B = \begin{bmatrix} 7 & 8 \\ 9 & 1 \\ 2 & 3 \end{bmatrix}

Let's find the element in the first row, first column of the product matrix ABAB:

(17)+(29)+(32)=7+18+6=31(1\cdot7) + (2\cdot9) + (3\cdot2) = 7 + 18 + 6 = 31

And the element in the first row, second column:

(18)+(21)+(33)=8+2+9=19(1\cdot8) + (2\cdot1) + (3\cdot3) = 8 + 2 + 9 = 19

By continuing this process for all elements, we get the final result:

AB=[31197955]AB = \begin{bmatrix} 31 & 19 \\ 79 & 55 \end{bmatrix}

A crucial point: Unlike with regular numbers, matrix multiplication is generally not commutative. This means ABAB is not the same as BABA. In fact, sometimes BABA may not even be a valid operation!

Now that you have the basic terms and operations down, let's review.

Ready to test your knowledge?

Quiz Questions 1/5

A matrix has 4 rows and 5 columns. What are its dimensions?

Quiz Questions 2/5

Given the matrix A=[927416]A = \begin{bmatrix} 9 & 2 & 7 \\ 4 & 1 & 6 \end{bmatrix}, what is the value of the element a2,1a_{2,1}?

Understanding these fundamentals is the first step. Next, we'll see how these tools are used to solve more complex problems.