Matrix Operations, Algebraic Properties and Special Matrix Classes

A matrix is a rectangular array of numbers; matrices of the same size are added entrywise, a matrix is multiplied by a number entrywise, and the product AB of an m × n matrix by an n × p matrix is the m × p matrix whose entry in row i and column j is the dot product of row i of A with column j of B. In brief: with A = [[1, 2], [3, 4]] and B = [[0, 1], [1, 0]], AB = [[2, 1], [4, 3]] but BA = [[3, 4], [1, 2]], so matrix multiplication is generally not commutative. Transposing reverses the order: (AB)T = BTAT.

Matrices organize linear data: systems of equations, transformations, networks and tables. This guide defines the basic operations, lists their algebraic properties (and the ones that fail), and describes the special classes of square matrices: diagonal, triangular, symmetric, skew-symmetric, orthogonal, idempotent, nilpotent and involutory, with worked examples and a table. Matrices are written row by row, so [[1, 2], [3, 4]] has the rows (1, 2) and (3, 4).

How do you add and scale matrices?

An m × n matrix has m rows and n columns; its entry aij is in row i, column j. Two matrices of the same size are added entrywise, and a number k multiplies every entry. The zero matrix O has all entries 0, and −A = (−1)A.

Example 1: sum and scalar multiple

A = [[1, 2], [3, 4]], B = [[0, 1], [1, 0]]: A + B = [[1, 3], [4, 4]], 3A = [[3, 6], [9, 12]], A − 2B = [[1, 0], [1, 4]].

1234 + 0110 = 1344 3 · 1234 = 36912 1234 − 0220 = 1014

How do you multiply matrices?

The product AB exists only when the number of columns of A equals the number of rows of B. The entry (AB)ij = ai1b1j + ai2b2j + … + ainbnj, the dot product of row i with column j. An m × n matrix times an n × p matrix gives m × p.

Example 2: a 2 × 3 times a 3 × 2

C = [[1, 0, 2], [−1, 3, 1]], D = [[3, 1], [2, 1], [1, 0]]. CD has the first row (1 · 3 + 0 · 2 + 2 · 1, 1 · 1 + 0 · 1 + 2 · 0) = (5, 1) and the second row (−3 + 6 + 1, −1 + 3 + 0) = (4, 2). So CD = [[5, 1], [4, 2]]. The product DC is a 3 × 3 matrix, so CD and DC cannot be equal.

102 −131 31 21 10 51 42 · = 1 · 3 + 0 · 2 + 2 · 1 = 5

Example 3: noncommutativity

AB = [[1 · 0 + 2 · 1, 1 · 1 + 2 · 0], [3 · 0 + 4 · 1, 3 · 1 + 4 · 0]] = [[2, 1], [4, 3]], while BA = [[3, 4], [1, 2]]. Multiplying by B on the right swaps the columns of A; on the left it swaps the rows.

1234 · 0110 = 2143 0110 · 1234 = 3412

Example 4: powers

A2 = AA = [[1 + 6, 2 + 8], [3 + 12, 6 + 16]] = [[7, 10], [15, 22]]. A0 = I by convention. Powers of the same matrix always commute: AmAn = Am+n.

1234 · 1234 = 7101522 1 · 1 + 2 · 3 = 7

Which algebraic laws hold?

For matrices of compatible sizes and numbers k:

Several familiar laws fail: AB ≠ BA in general; AB = O does not imply A = O or B = O; and AB = AC does not imply B = C. Consequently (A + B)2 = A2 + AB + BA + B2, not A2 + 2AB + B2.

Example 5: zero divisors

[[1, 0], [0, 0]] · [[0, 0], [0, 1]] = [[0, 0], [0, 0]], although neither factor is zero.

1000 · 0001 = 0000

Example 6: the binomial formula fails

For A and B above, A + B = [[1, 3], [4, 4]] and (A + B)2 = [[13, 15], [20, 28]]. But A2 + 2AB + B2 = [[7, 10], [15, 22]] + [[4, 2], [8, 6]] + [[1, 0], [0, 1]] = [[12, 12], [23, 29]], which is different. The correct expansion A2 + AB + BA + B2 = [[7 + 2 + 3 + 1, 10 + 1 + 4 + 0], [15 + 4 + 1 + 0, 22 + 3 + 2 + 1]] = [[13, 15], [20, 28]] ✓.

(A + B)2 = 1344 · 1344 = 13152028 A2 + 2AB + B2 = 7101522 + 4286 + 1001 = 12122329 ≠ 13152028

What are the transpose and the trace?

The transpose AT swaps rows and columns: (AT)ij = aji. Rules: (A + B)T = AT + BT, (kA)T = kAT, (AT)T = A and (AB)T = BTAT. The trace of a square matrix, tr A, is the sum of the diagonal entries; it satisfies tr(A + B) = tr A + tr B and tr(AB) = tr(BA).

A = 1234 AT = 1324 tr A = 1 + 4 = 5

Example 7: transpose of a product

For A and B above, (AB)T = [[2, 4], [1, 3]]. And BTAT = [[0, 1], [1, 0]] · [[1, 3], [2, 4]] = [[2, 4], [1, 3]] ✓. By contrast, ATBT = [[1, 3], [2, 4]] · [[0, 1], [1, 0]] = [[3, 1], [4, 2]], not equal.

(AB)T = 2413 BT AT = 0110 · 1324 = 2413 AT BT = 1324 · 0110 = 3142

Example 8: the trace identity

tr(AB) = 2 + 3 = 5 and tr(BA) = 3 + 2 = 5, although AB ≠ BA.

AB = 2143 BA = 3412 tr = 2 + 3 = 3 + 2 = 5

Which special matrix classes are important?

Example 9: decomposing a matrix

A = [[1, 2], [3, 4]]: the symmetric part is [[1, 2.5], [2.5, 4]] and the skew-symmetric part is [[0, −0.5], [0.5, 0]]. Their sum is A ✓.

A = 12.52.54 + 0−0.50.50 (A + AT)/2 + (A − AT)/2

Example 10: recognizing classes

R = [[0, −1], [1, 0]] is orthogonal: RTR = [[0, 1], [−1, 0]] · [[0, −1], [1, 0]] = I. N = [[0, 1], [0, 0]] is nilpotent: N2 = O. P = [[1/2, 1/2], [1/2, 1/2]] is idempotent: P2 = [[1/2, 1/2], [1/2, 1/2]] = P; it projects onto the line y = x. J = [[0, 1], [1, 0]] is involutory: J2 = I.

RT R = 01−10 · 0−110 = 1001 N2 = 0100 · 0100 = 0000 P2 = 1/21/21/21/2 · 1/21/21/21/2 = 1/21/21/21/2 J2 = 0110 · 0110 = 1001

Table of special classes

Special classes of square matrices
Class Condition Example
symmetricAT = A[[1, 2], [2, 5]]
skew-symmetricAT = −A[[0, 3], [−3, 0]]
orthogonalATA = I[[0, −1], [1, 0]]
idempotentA2 = A[[1/2, 1/2], [1/2, 1/2]]
nilpotentAk = O[[0, 1], [0, 0]]
involutoryA2 = I[[0, 1], [1, 0]]

Where do matrices come from?

Arrays of coefficients were used to solve systems of equations in ancient China (the text Nine Chapters on the Mathematical Art, which describes a procedure equivalent to elimination). The word “matrix” was introduced by James Joseph Sylvester in 1850, and Arthur Cayley developed the algebra of matrices in 1858, including the multiplication rule, which he motivated by the composition of linear substitutions. Matrix mechanics in physics (Heisenberg, Born and Jordan, 1925) gave matrices a central role in quantum theory.

Where are matrices used?

Matrices represent systems of equations, geometric transformations in graphics, adjacency of networks, transition probabilities of Markov chains and the data tables of statistics and machine learning. The determinant of a square matrix, studied, detects whether the matrix is invertible.

Which mistakes are common?

Multiplying entrywise

The matrix product is not the entrywise product. Use rows times columns.

Assuming commutativity

AB and BA can differ in value or even in size. Keep the order, and expand (A + B)2 with four terms.

Cancelling a matrix factor

From AB = AC you cannot conclude B = C unless A is invertible.

Wrong order after transposing

(AB)T = BTAT; the order reverses.