Skip to content

Matrices and Basic Matrix Operations

In this lesson you’ll learn what matrices are and how to perform basic operations on them (addition, subtraction, and scalar multiplication). Matrices are one of the most important tools in linear algebra and are used everywhere in graphics and games.

A matrix is a rectangular array of numbers arranged in rows and columns.

Example of a 2×32 \times 3 matrix:

A=[123456]A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}
  • The size is written as rows ×\times columns (this one is 2×32 \times 3).
  • Individual entries are called elements and are denoted aija_{ij} (row ii, column jj).
  1. Addition and Subtraction: Matrices can be added or subtracted only if they have the same dimensions. Add/subtract corresponding elements.
A 1 2 3 4 + B 5 6 7 8 = A + B 6 8 10 12 row 1, col 1 row 1, col 2 row 2, col 1 row 2, col 2

In the diagram: two 2×22 \times 2 matrices are added element-by-element. Matching colors show how each position in AA and BB maps to the same position in the result.

  1. Scalar Multiplication: Multiply every element of the matrix by a number (scalar).
3 × 1 2 3 4 = 3 6 9 12 3 × 1 = 3 3 × 2 = 6 3 × 3 = 9 3 × 4 = 12 Every entry is multiplied by the scalar (3)

Every entry gets multiplied by the scalar (3 in this case). The annotations on the right show each individual multiplication.

  1. Transpose: The transpose ATA^T flips rows and columns.
A=[123456]AT=[135246]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{bmatrix} \quad \Rightarrow \quad A^T = \begin{bmatrix} 1 & 3 & 5 \\ 2 & 4 & 6 \end{bmatrix}
C (2 × 3) 1 2 3 4 5 6 R1 R2 T Cᵀ (3 × 2) 1 4 2 5 3 6 C1 C2 Row 1 of C becomes Column 1 of Cᵀ, Row 2 becomes Column 2

Row 1 of the original becomes Column 1 of the transpose, and Row 2 becomes Column 2. The color-coded highlights make it easy to track where each entry ends up.

Example 1: Matrix Addition

Let A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, B=[5678]B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix}

A+B=[1+52+63+74+8]=[681012]A + B = \begin{bmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{bmatrix} = \begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix}

Each entry is the sum of the entries in the same position.

Example 2: Scalar Multiplication

3A=3[1234]=[36912]3A = 3 \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} = \begin{bmatrix} 3 & 6 \\ 9 & 12 \end{bmatrix}

Every element gets multiplied by 3.

Example 3: Transpose

Let C=[123456]C = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}

CT=[142536]C^T = \begin{bmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{bmatrix}

Rows become columns and columns become rows.

Matrices are the backbone of 3D graphics and game engines:

  • Transformation matrices are used to move, rotate, and scale objects
  • Model matrix = position/rotation/scale of an object
  • View matrix = camera position and orientation
  • Projection matrix = converts 3D world to 2D screen

Every frame, the graphics card multiplies many matrices together to figure out where every vertex should appear on your screen.

Example: When you rotate your character in a game, the engine applies a rotation matrix to every vertex of the model.

Two matrices can be added only if they have:
Scalar multiplication means:
The transpose of a $2 \times 3$ matrix is:
In game development, matrices are primarily used for:
If $A$ is $2 \times 3$ and $B$ is $2 \times 3$, then $A + B$ is: