Module 39 of 39

Matrices: dimensions, products, and transposes

Read matrix dimensions, multiplication, transposes, and inverse conditions before using matrix algorithms.

A matrix is a rectangular arrangement of values. A matrix with r rows and c columns has shape r × c. We name its entry in row i, column j as Aᵢⱼ. The notation makes a formula compact, but the dimensions are what prevent many mistakes.

Background for this page. You need basic multiplication and addition. A matrix has rows and columns. A vector can be treated as a matrix with one column when multiplying it by a matrix. Related explanations: Matrix algorithms: Gaussian elimination and linear systems · Polynomial multiplication, convolution, and the FFT.

Two matrices can be added entry by entry only when they have the same shape. If A is r × s and B is s × c, then the product AB has shape r × c. Entry (i, j) of the product is the sum of AᵢₖBₖⱼ over the shared index k. Matrix multiplication is generally not commutative: AB may differ from BA, and one product may exist while the other does not.

A two by three matrix times a three by two matrix gives a two by two matrix. Its top-left entry uses the first row of A and first column of B.

The transpose Aᵀ exchanges rows and columns, so an r × c matrix becomes c × r. A square identity matrix I has ones on its diagonal and zeros elsewhere; multiplying a compatible matrix by I leaves it unchanged. A square matrix has an inverse only when it is nonsingular. Then A⁻¹A = AA⁻¹ = I. Not every square matrix has one.

The expression Ax = b represents a system of linear equations. If A is r × c, x must have c entries, and b has r. A solution may be unique, absent, or one of many, depending on the matrix and right-hand side. When there are more equations than unknowns and no exact solution, least squares looks for an x that minimizes the squared residuals.

Matrix algorithms have two kinds of correctness to think about. The algebraic method must solve the stated problem in exact mathematics. A computer implementation must also manage finite-precision arithmetic. A result can be mathematically well defined yet numerically sensitive to small errors in its inputs.

Compute one product entry and check its dimensions

For A with first row [1,2,3] and B with first column [7,9,11], the top-left product entry is 1·7+2·9+3·11=58. The three paired terms explain why A’s column count must equal B’s row count. The resulting matrix has one row for each A row and one column for each B column.

Order matters. Even when both AB and BA exist, they can differ. For two-by-two examples, let A scale the first coordinate by two and B exchange the coordinates. Scaling then exchanging gives a different result from exchanging then scaling. Matrix multiplication represents an ordered composition of operations.

Transposing exchanges rows and columns. It reverses product order: (AB)ᵀ=BᵀAᵀ, provided the original product is defined.

Practice. If A is 2 × 3 and B is 3 × 4, what is the shape of AB? Can BA be formed? What is the shape of Aᵀ?

Answer. AB is 2 × 4. BA cannot be formed because the inner dimensions 4 and 2 do not match. Aᵀ is 3 × 2.

Try another case. Can two nonzero matrices have product zero?

Reasoning. Yes. For A with rows [1,0] and [0,0], and B with rows [0,0] and [0,1], every row-by-column product is zero. Matrix arithmetic does not inherit every cancellation rule for ordinary numbers.

View the full course and choose another topic.

Image preview

Fit