I sometimes have trouble remembering mathematical matrix syntax and the order of matrix multi­pli­cation, and I'm sure others do too, so here's a quick summary.

Matrix size and indexing is written row-first: an m-by-n matrix has m rows and n columns. (This is the exact opposite of the x,y notation in computer graphics, where the column x is specified first.) A vector of k elements is represented either as a 1-by-k row matrix or a k-by-1 column matrix.

An example 2-by-3 matrix:

−34−2
−874

Matrix multi­pli­cation multi­plies an m-by-n matrix with an n-by-p matrix, producing an m-by-p matrix: the second matrix ("matrix B") must have as many rows as the first matrix ("matrix A") has columns, and the result has the same number of rows that matrix A has and the number of columns that B has. (AB has A's rows and B's columns.)

Recall the dot product (or scalar product), that takes in two equal-length vectors and returns one number. If the two vectors (of length k) are v and w, then to get their dot product, we multiply corresponding entries of v and w and sum the resulting products together. Mathematically:

vw=i=1kviwi

Dot product example:

v =18−25−2
w =162−8−5
Product:1+48+−4+−40+10=15

To multiply two matrixes (A and B), we take single rows of A and single columns of B, then compute their dot product and put that in the inter­section. Cell i,j of the product matrix AB is calculated with row i of A and column j of B.

ABij=Ai1B1j+Ai2B2j++AinBnj=k=1nAikBkj

A couple of examples, including an illustration of when a column vector is multiplied by a row vector and not vice-versa:

b11b12
b21b22
a11a12a11b11 +
a12b21
a11b12 +
a12b22
a21a22a21b11 +
a22b21
a21b12 +
a22b22
w1
w2
w3
v1v2v3v1w1 + v2w2 + v3w3
w1w2w3
v1v1w1v1w2v1w3
v2v2w1v2w2v2w3
v3v3w1v3w2v3w3

In linear algebra, a linear function (or linear map) of n variables is often expressed as Ax, with x being a column vector of n variables and A being an n×n matrix. How this works is quite clear when the multi­plication is carried out, in this example for n=3:

x1
x2
x3
3103x1 + 1x2 + 0
0-250 − 2x2 + 5x
0060 + 0 + 6x3

Geometric rotations are also done with matrix multiplication. For 2d points, rotated around the origin, the following matrix is used (with θ being the rotation angle); it is then multiplied with the column vector of an (x, y) point. The result is a new column vector, with the newly rotated x and y. This is so common that GPUs have in-built hardware for this; it's what they're made for.

cos θ−sin θ
sin θcos θ

2D rotation only has one axis and one angle, but for 3D rotation there are three axes that a point can be rotated around.

100
0cos θ−sin θ
0sin θcos θ
Rotation around x-axis
Rotation around y-axis
cos θ0sin θ
010
−sin θ0cos θ
Rotation around z-axis
cos θ−sin θ0
sin θcos θ0
001

created 2022-11-18, edited 2022-11-18. index.