MAT1041 · Week 2 · - Operations with Matrices

Matrix operations and their properties

You learn matrix addition, scalar multiplication, matrix product, transpose and trace; when a product is defined; and the rules that behave differently from numbers, such as AB ≠ BA.

matrixentrysize (order)square matrixzero matrixidentity matrixscalar multiplematrix productlinear combinationtransposesymmetric matrixtracecommutematrix power

This week we turn the matrix from a table of numbers into an algebraic object: we will add, multiply and take powers. Most of the rules are familiar from numbers. Exam questions come exactly from the places that are not familiar: when a product is defined, why ABAB is not equal to BABA, why (AB)T(AB)^T is BTATB^TA^T.

Golden rules:

  1. Before a product, write the sizes: (m×n)(n×p)=m×p(m \times n)(n \times p) = m \times p. If the inner dimensions are not equal, the product does not exist.
  2. (AB)ij(AB)_{ij} = row ii of AA · column jj of BB. If only one entry is asked, compute only that.
  3. AB≠BAAB \neq BA in general. Leave the habit “order doesn’t matter” from numbers behind here.
  4. Transpose and inverse reverse the order in a product: (AB)T=BTAT(AB)^T = B^TA^T.

Definitions and notation

A matrix with mm rows and nn columns is called an m×nm \times n matrix. The element in row ii, column jj is called aija_{ij} (entry). The notation A=[aij]A = [a_{ij}] expresses this.

NameDefinitionExample
Square matrixm=nm = n2×22 \times 2, 3×33 \times 3
Zero matrix OOall entries are 0A+O=AA + O = A
Identity matrix InI_n1 on the diagonal, 0 elsewhereAI=IA=AAI = IA = A
Diagonal0 off the diagonaldiag⁡(2,−1,5)\operatorname{diag}(2, -1, 5)
Upper triangular0 below the diagonalsquare matrices in REF
Row / column vector1×n1 \times n / m×1m \times 1x=(x1,…,xn)T\mathbf{x} = (x_1, \dots, x_n)^T

Two matrices are equal only if they have the same size and every corresponding entry is equal. So a “matrix equation” is really as many numerical equations as there are entries (Q6).

Addition and scalar multiplication

Two matrices of the same size are added entry by entry. Multiplying by a number cc multiplies every entry by cc.

2[1−230]−3[21−14]=[2−460]−[63−312]=[−4−79−12]2\begin{bmatrix} 1 & -2 \\ 3 & 0 \end{bmatrix} - 3\begin{bmatrix} 2 & 1 \\ -1 & 4 \end{bmatrix} = \begin{bmatrix} 2 & -4 \\ 6 & 0 \end{bmatrix} - \begin{bmatrix} 6 & 3 \\ -3 & 12 \end{bmatrix} = \begin{bmatrix} -4 & -7 \\ 9 & -12 \end{bmatrix}

These operations obey the same rules as numbers: A+B=B+AA + B = B + A, (A+B)+C=A+(B+C)(A + B) + C = A + (B + C), c(A+B)=cA+cBc(A + B) = cA + cB, (c+d)A=cA+dA(c + d)A = cA + dA.

Matrix product

If AA is m×nm \times n and BB is n×pn \times p, then ABAB is an m×pm \times p matrix and

(AB)ij=ai1b1j+ai2b2j+⋯+ainbnj.(AB)_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{in}b_{nj}.

That is, you multiply row ii of AA with column jj of BB entry by entry and add. Example:

A=[12−1034]2×3,B=[21−1035]3×2A = \begin{bmatrix} 1 & 2 & -1 \\ 0 & 3 & 4 \end{bmatrix}_{2 \times 3}, \quad B = \begin{bmatrix} 2 & 1 \\ -1 & 0 \\ 3 & 5 \end{bmatrix}_{3 \times 2}

AB (2x2):
  (1,1): (1, 2, -1)·(2, -1, 3) = 2 - 2 - 3 = -3
  (1,2): (1, 2, -1)·(1, 0, 5)  = 1 + 0 - 5 = -4
  (2,1): (0, 3, 4)·(2, -1, 3)  = 0 - 3 + 12 = 9
  (2,2): (0, 3, 4)·(1, 0, 5)   = 0 + 0 + 20 = 20

AB=[−3−4920],BA=[272−1−2132117]AB = \begin{bmatrix} -3 & -4 \\ 9 & 20 \end{bmatrix}, \qquad BA = \begin{bmatrix} 2 & 7 & 2 \\ -1 & -2 & 1 \\ 3 & 21 & 17 \end{bmatrix}

Both are defined but one is 2×22 \times 2 and the other 3×33 \times 3. Even for square matrices they are generally not equal:

C=[1101], D=[1011]:CD=[2111]≠DC=[1112].C = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix},\ D = \begin{bmatrix} 1 & 0 \\ 1 & 1 \end{bmatrix}: \quad CD = \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} \neq DC = \begin{bmatrix} 1 & 1 \\ 1 & 2 \end{bmatrix}.

When AB=BAAB = BA, AA and BB are said to commute. This is a special case, not the default.

Writing a system as a matrix

A system of mm equations in nn unknowns becomes a single matrix equation: Ax=bA\mathbf{x} = \mathbf{b}. And AxA\mathbf{x} has a nice interpretation: it is a linear combination of the columns of AA, with the components of x\mathbf{x} as coefficients.

[123−104][2−1]=2[130]−1[2−14]=[07−4]\begin{bmatrix} 1 & 2 \\ 3 & -1 \\ 0 & 4 \end{bmatrix}\begin{bmatrix} 2 \\ -1 \end{bmatrix} = 2\begin{bmatrix} 1 \\ 3 \\ 0 \end{bmatrix} - 1\begin{bmatrix} 2 \\ -1 \\ 4 \end{bmatrix} = \begin{bmatrix} 0 \\ 7 \\ -4 \end{bmatrix}

This view will come back in weeks 7 and 9 (span, column space): Ax=bA\mathbf{x} = \mathbf{b} is consistent if and only if b\mathbf{b} is a combination of the columns of AA.

Properties of the product

What is true (when the sizes fit):

PropertyFormula
AssociativeA(BC)=(AB)CA(BC) = (AB)C
Left distributiveA(B+C)=AB+ACA(B + C) = AB + AC
Right distributive(A+B)C=AC+BC(A + B)C = AC + BC
Scalarc(AB)=(cA)B=A(cB)c(AB) = (cA)B = A(cB)
IdentityImA=A=AInI_mA = A = AI_n
PowersArAs=Ar+sA^rA^s = A^{r+s}, (Ar)s=Ars(A^r)^s = A^{rs}, A0=IA^0 = I

What is true for numbers but false for matrices:

For numbersFor matrices
ab=baab = baAB≠BAAB \neq BA in general
ab=0⇒a=0ab = 0 \Rightarrow a = 0 or b=0b = 0[1224][2−4−12]=O\begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}\begin{bmatrix} 2 & -4 \\ -1 & 2 \end{bmatrix} = O
ab=acab = ac, a≠0⇒b=ca \neq 0 \Rightarrow b = cfor P=[1224]P = \begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}, PI=P[3−4−13]PI = P\begin{bmatrix} 3 & -4 \\ -1 & 3 \end{bmatrix} but I≠[3−4−13]I \neq \begin{bmatrix} 3 & -4 \\ -1 & 3 \end{bmatrix}
(a+b)2=a2+2ab+b2(a + b)^2 = a^2 + 2ab + b^2(A+B)2=A2+AB+BA+B2(A + B)^2 = A^2 + AB + BA + B^2

PITFALL · cancelling on both sides. When you see AB=ACAB = AC you can’t “cancel the AA‘s”. This is true only if AA is invertible (next week): you multiply from the left by A−1A^{-1}. The PP above is not invertible (det⁡P=0\det P = 0), which is why cancellation fails.

Transpose

The transpose ATA^T of AA is the matrix with its rows made into columns: (AT)ij=aji(A^T)_{ij} = a_{ji}. The transpose of an m×nm \times n matrix is n×mn \times m.

A=[12−1034]⇒AT=[1023−14]A = \begin{bmatrix} 1 & 2 & -1 \\ 0 & 3 & 4 \end{bmatrix} \quad\Rightarrow\quad A^T = \begin{bmatrix} 1 & 0 \\ 2 & 3 \\ -1 & 4 \end{bmatrix}

Rules: (AT)T=A(A^T)^T = A, (A+B)T=AT+BT(A + B)^T = A^T + B^T, (cA)T=cAT(cA)^T = cA^T and

(AB)T=BTAT.(AB)^T = B^TA^T.

Why does the order reverse? If ABAB is m×pm \times p, then (AB)T(AB)^T is p×mp \times m. BTB^T is p×np \times n, ATA^T is n×mn \times m: only BTATB^TA^T gives this size. In the example above, (AB)T=[−39−420](AB)^T = \begin{bmatrix} -3 & 9 \\ -4 & 20 \end{bmatrix} and BTATB^TA^T gives the same.

Symmetric matrix: AT=AA^T = A. It must be square and aij=ajia_{ij} = a_{ji}: a mirror about the diagonal. ATAA^TA and AATAA^T are symmetric for every matrix, because (ATA)T=AT(AT)T=ATA(A^TA)^T = A^T(A^T)^T = A^TA. Symmetric matrices are the main topic of week 14.

Trace

The trace of a square matrix is the sum of its diagonal entries: tr⁡A=a11+a22+⋯+ann\operatorname{tr}A = a_{11} + a_{22} + \dots + a_{nn}.

  • tr⁡(A+B)=tr⁡A+tr⁡B\operatorname{tr}(A + B) = \operatorname{tr}A + \operatorname{tr}B, tr⁡(cA)=ctr⁡A\operatorname{tr}(cA) = c\operatorname{tr}A, tr⁡(AT)=tr⁡A\operatorname{tr}(A^T) = \operatorname{tr}A.
  • tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA), even when ABAB and BABA have different sizes. In the example above both are 1717.

The trace will return in week 13 as the sum of the eigenvalues.

Powers

For square AA, A2=AAA^2 = AA, A3=AAAA^3 = AAA, and so on. When computing, look for a pattern:

A=[1201]:A2=[1401],A3=[1601],An=[12n01].A = \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix}: \quad A^2 = \begin{bmatrix} 1 & 4 \\ 0 & 1 \end{bmatrix}, \quad A^3 = \begin{bmatrix} 1 & 6 \\ 0 & 1 \end{bmatrix}, \quad A^n = \begin{bmatrix} 1 & 2n \\ 0 & 1 \end{bmatrix}.

The power of a diagonal matrix is the easiest: take the power of each number on the diagonal. diag⁡(2,−1)5=diag⁡(32,−1)\operatorname{diag}(2, -1)^5 = \operatorname{diag}(32, -1). In week 13 the whole point of diagonalization will be to bring every matrix to this easy case.

TIP · a matrix inside a polynomial. If p(x)=x2−5x−2p(x) = x^2 - 5x - 2, then p(A)=A2−5A−2Ip(A) = A^2 - 5A - 2I. The constant term is multiplied by II; you can’t write "−2-2" and subtract a number from a matrix.

Common mistakes

WrongRight
Trying to multiply (2×3)(2×3)(2 \times 3)(2 \times 3)The inner dimensions (3 and 2) are not equal: undefined
Multiplying entry by entryRow · column
Assuming AB=BAAB = BATry a concrete matrix, they usually differ
(AB)T=ATBT(AB)^T = A^TB^T(AB)T=BTAT(AB)^T = B^TA^T
AB=0⇒A=0AB = 0 \Rightarrow A = 0 or B=0B = 0False, there are matrices that are zero divisors
AB=AC⇒B=CAB = AC \Rightarrow B = COnly if AA is invertible
(A+B)2=A2+2AB+B2(A + B)^2 = A^2 + 2AB + B^2A2+AB+BA+B2A^2 + AB + BA + B^2
Writing A2−5A−2A^2 - 5A - 2A2−5A−2IA^2 - 5A - 2I

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

Let AA be 3×43 \times 4 and BB be 4×24 \times 2. What is the size of ABAB? Is BABA defined?

Show answer
3×23 \times 2; BABA is not defined

(3×4)(4×2)(3 \times 4)(4 \times 2): the inner dimensions 4 and 4 are equal, and the result has the outer dimensions 3×23 \times 2.BABA: (4×2)(3×4)(4 \times 2)(3 \times 4), the inner dimensions 2 and 3 are different. Undefined.

Question 2easy

Let X=[1−230]X = \begin{bmatrix} 1 & -2 \\ 3 & 0 \end{bmatrix} and Y=[21−14]Y = \begin{bmatrix} 2 & 1 \\ -1 & 4 \end{bmatrix}. Compute 2X−3Y2X - 3Y.

Show answer
[−4−79−12]\begin{bmatrix} -4 & -7 \\ 9 & -12 \end{bmatrix}

Entry by entry: 2X=[2−460]2X = \begin{bmatrix} 2 & -4 \\ 6 & 0 \end{bmatrix}, 3Y=[63−312]3Y = \begin{bmatrix} 6 & 3 \\ -3 & 12 \end{bmatrix}.
Difference: (2−6,−4−3;6+3,0−12)=[−4−79−12](2-6, -4-3; 6+3, 0-12) = \begin{bmatrix} -4 & -7 \\ 9 & -12 \end{bmatrix}.

Question 3easy

Let A=[2011−13]A = \begin{bmatrix} 2 & 0 & 1 \\ 1 & -1 & 3 \end{bmatrix} and B=[12041−2035]B = \begin{bmatrix} 1 & 2 & 0 \\ 4 & 1 & -2 \\ 0 & 3 & 5 \end{bmatrix}. Find only the entry (AB)23(AB)_{23}.

Show answer
17

(AB)23(AB)_{23} is the dot product of row 2 of AA with column 3 of BB.(1,−1,3)⋅(0,−2,5)=0+2+15=17(1, -1, 3) \cdot (0, -2, 5) = 0 + 2 + 15 = 17.
When only one entry is asked, do not compute the whole product.

Question 4medium

With AA and BB as in the previous question, compute ABAB.

Show answer
[275−31017]\begin{bmatrix} 2 & 7 & 5 \\ -3 & 10 & 17 \end{bmatrix}

(2×3)(3×3)(2 \times 3)(3 \times 3) → 2×32 \times 3.
Row 1 (2,0,1)(2, 0, 1): with the columns, 2+0+0=22 + 0 + 0 = 2, 4+0+3=74 + 0 + 3 = 7, 0+0+5=50 + 0 + 5 = 5.
Row 2 (1,−1,3)(1, -1, 3): 1−4+0=−31 - 4 + 0 = -3, 2−1+9=102 - 1 + 9 = 10, 0+2+15=170 + 2 + 15 = 17.

Question 5medium

With the same AA and BB, find (AB)T(AB)^T. Which product of transposes equals it?

Show answer
[2−3710517]=BTAT\begin{bmatrix} 2 & -3 \\ 7 & 10 \\ 5 & 17 \end{bmatrix} = B^TA^T

Transpose: rows become columns. Since ABAB is 2×32 \times 3, (AB)T(AB)^T is 3×23 \times 2.
The rule is (AB)T=BTAT(AB)^T = B^TA^T, the order reverses. ATBTA^TB^T would be (3×2)(3×3)(3 \times 2)(3 \times 3), not even defined.

Question 6medium

Find xx and yy such that [x23y]+2[1yx1]=[5694]\begin{bmatrix} x & 2 \\ 3 & y \end{bmatrix} + 2\begin{bmatrix} 1 & y \\ x & 1 \end{bmatrix} = \begin{bmatrix} 5 & 6 \\ 9 & 4 \end{bmatrix}.

Show answer
x=3, y=2x = 3,\ y = 2

Equate entry by entry: x+2=5x + 2 = 5, 2+2y=62 + 2y = 6, 3+2x=93 + 2x = 9, y+2=4y + 2 = 4.
The first equation gives x=3x = 3, the second y=2y = 2. The other two also hold (3+6=93 + 6 = 9, 2+2=42 + 2 = 4), so it is consistent.

Question 7medium

Let A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}. Compute A2−5A−2IA^2 - 5A - 2I.

Show answer
[0000]\begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}

A2=[1+62+83+126+16]=[7101522]A^2 = \begin{bmatrix} 1 + 6 & 2 + 8 \\ 3 + 12 & 6 + 16 \end{bmatrix} = \begin{bmatrix} 7 & 10 \\ 15 & 22 \end{bmatrix}.5A=[5101520]5A = \begin{bmatrix} 5 & 10 \\ 15 & 20 \end{bmatrix}, 2I=[2002]2I = \begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix}.7−5−2=07 - 5 - 2 = 0, 10−10=010 - 10 = 0, 15−15=015 - 15 = 0, 22−20−2=022 - 20 - 2 = 0. The zero matrix.
Note: for a 2×22 \times 2 matrix, A2−(trA)A+(det⁡A)I=0A^2 - (\text{tr}A)A + (\det A)I = 0 is always true (Cayley-Hamilton in week 13).

Question 8hard

Find all 2×22 \times 2 matrices BB that commute with C=[1101]C = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}, i.e. CB=BCCB = BC.

Show answer
B=[ab0a]B = \begin{bmatrix} a & b \\ 0 & a \end{bmatrix}, a,b∈Ra, b \in \mathbb{R}

Take B=[abcd]B = \begin{bmatrix} a & b \\ c & d \end{bmatrix}. CB=[a+cb+dcd]CB = \begin{bmatrix} a + c & b + d \\ c & d \end{bmatrix}, BC=[aa+bcc+d]BC = \begin{bmatrix} a & a + b \\ c & c + d \end{bmatrix}.
Equate: a+c=a⇒c=0a + c = a \Rightarrow c = 0; b+d=a+b⇒d=ab + d = a + b \Rightarrow d = a; the others hold automatically.
Result: c=0c = 0, d=ad = a, with aa and bb free.

Question 9hard

True or false: (A+B)2=A2+2AB+B2(A + B)^2 = A^2 + 2AB + B^2 for all n×nn \times n matrices A,BA, B.

Show answer
False

The correct expansion is (A+B)2=A2+AB+BA+B2(A + B)^2 = A^2 + AB + BA + B^2. It becomes 2AB2AB only if AB=BAAB = BA.
Counterexample: C=[1101]C = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}, D=[1011]D = \begin{bmatrix} 1 & 0 \\ 1 & 1 \end{bmatrix}. (C+D)2=[5445](C + D)^2 = \begin{bmatrix} 5 & 4 \\ 4 & 5 \end{bmatrix} but C2+2CD+D2=[6444]C^2 + 2CD + D^2 = \begin{bmatrix} 6 & 4 \\ 4 & 4 \end{bmatrix}.

Question 10medium

Let A=[12−1034]A = \begin{bmatrix} 1 & 2 & -1 \\ 0 & 3 & 4 \end{bmatrix} and B=[21−1035]B = \begin{bmatrix} 2 & 1 \\ -1 & 0 \\ 3 & 5 \end{bmatrix}. Find tr⁡(AB)\operatorname{tr}(AB) and tr⁡(BA)\operatorname{tr}(BA).

Show answer
Both are 17

AB=[−3−4920]AB = \begin{bmatrix} -3 & -4 \\ 9 & 20 \end{bmatrix}, trace −3+20=17-3 + 20 = 17.BA=[272−1−2132117]BA = \begin{bmatrix} 2 & 7 & 2 \\ -1 & -2 & 1 \\ 3 & 21 & 17 \end{bmatrix}, trace 2−2+17=172 - 2 + 17 = 17.
Even when ABAB and BABA have different sizes, tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA) is always true.

Question 11hard

Let A=[1201]A = \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix}. Find A10A^{10}.

Show answer
[12001]\begin{bmatrix} 1 & 20 \\ 0 & 1 \end{bmatrix}

A2=[1401]A^2 = \begin{bmatrix} 1 & 4 \\ 0 & 1 \end{bmatrix}, A3=[1601]A^3 = \begin{bmatrix} 1 & 6 \\ 0 & 1 \end{bmatrix}. Pattern: An=[12n01]A^n = \begin{bmatrix} 1 & 2n \\ 0 & 1 \end{bmatrix} (by induction: the upper right entry of AnAA^nA is 2n+22n + 2).n=10n = 10: upper right 2020.

Question 12easy

For which xx is [1x+12x−34]\begin{bmatrix} 1 & x + 1 \\ 2x - 3 & 4 \end{bmatrix} a symmetric matrix?

Show answer
x=4x = 4

Symmetric: AT=AA^T = A, that is, a12=a21a_{12} = a_{21}. x+1=2x−3⇒x=4x + 1 = 2x - 3 \Rightarrow x = 4.
Check: the matrix is [1554]\begin{bmatrix} 1 & 5 \\ 5 & 4 \end{bmatrix}.

Verification: All matrix products, transposes, powers and traces were computed exactly in node with BigInt fractions; the claims about properties (no commutativity, AB = 0, no cancellation, (AB)^T = B^T A^T) were checked with concrete matrices (verify/MAT1041/02.mjs).

Review card

Size m×n: m rows, n columns. a_ij: row i, column j. Addition/subtraction: ONLY the same size, entry by entry. cA: every entry × c. AB defined ⇔ (m×n)(n×p): inner dimensions equal → result m×p. (AB)_ij = row i of A · column j of B. Ax = x1·(column 1) + x2·(column 2) + ... (a linear combination of the columns) AB ≠ BA in general! (A+B)² = A² + AB + BA + B² AB = 0 is possible with A≠0, B≠0. AB = AC ⇏ B = C (no cancellation). AI = IA = A. A⁰ = I, A^r A^s = A^(r+s). (A^T)^T = A, (A+B)^T = A^T + B^T, (cA)^T = cA^T, (AB)^T = B^T A^T (ORDER REVERSES) Symmetric: A^T = A (square, a_ij = a_ji). A^T A is always symmetric. Trace: tr A = sum of the diagonal. tr(AB) = tr(BA). If only one entry is asked, compute only that.