About

2.1 Matrix Operations

Theory: Matrix Operations

Matrix Notation (Lay §2.1)

An m×nm \times n matrix AA has mm rows and nn columns. We write it by columns or by entries:

A=[a1a2⋯an]=[a11⋯a1n⋮⋮am1⋯amn]A = \begin{bmatrix} \mathbf{a}_1 & \mathbf{a}_2 & \cdots & \mathbf{a}_n \end{bmatrix} = \begin{bmatrix} a_{11} & \cdots & a_{1n} \\ \vdots & & \vdots \\ a_{m1} & \cdots & a_{mn} \end{bmatrix}

Sums and Scalar Multiples

Theorem 1 (Lay §2.1): Let AA, BB, CC be matrices of the same size and rr, ss scalars. Then

  1. A+B=B+AA + B = B + A
  2. (A+B)+C=A+(B+C)(A + B) + C = A + (B + C)
  3. A+0=AA + 0 = A
  4. r(A+B)=rA+rBr(A + B) = rA + rB
  5. (r+s)A=rA+sA(r + s)A = rA + sA
  6. r(sA)=(rs)Ar(sA) = (rs)A

In short: matrix addition and scalar multiplication behave exactly like ordinary vector algebra.

Matrix Multiplication

Multiplying by BB and then by AA (that is, x↦Bx↦A(Bx)\mathbf{x} \mapsto B\mathbf{x} \mapsto A(B\mathbf{x})) should be a single matrix ABAB. That is what motivates the definition.

Definition (Lay §2.1): If AA is m×nm \times n and B=[b1b2⋯bp]B = \begin{bmatrix} \mathbf{b}_1 & \mathbf{b}_2 & \cdots & \mathbf{b}_p \end{bmatrix} is n×pn \times p, then

AB=A[b1b2⋯bp]=[Ab1Ab2⋯Abp]AB = A\begin{bmatrix} \mathbf{b}_1 & \mathbf{b}_2 & \cdots & \mathbf{b}_p \end{bmatrix} = \begin{bmatrix} A\mathbf{b}_1 & A\mathbf{b}_2 & \cdots & A\mathbf{b}_p \end{bmatrix}

Each column of ABAB is a linear combination of the columns of AA, using weights from the corresponding column of BB.

The Size Rule

Am×n    Bn×p=ABm×p\underset{m \times n}{A} \;\; \underset{n \times p}{B} = \underset{m \times p}{AB}

The inner numbers must match (n=nn = n); the outer numbers give the size of the product.

Example. If AA is 3×23 \times 2 and BB is 2×42 \times 4, then ABAB is 3×43 \times 4, but BABA is undefined (BB has 4 columns, AA has 3 rows).

The Row–Column Rule

For hand computation, compute one entry at a time: entry (i,j)(i, j) of ABAB is (row ii of AA) ⋅\cdot (column jj of BB):

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

Mini-example. With A=[231−5]A = \begin{bmatrix} 2 & 3 \\ 1 & -5 \end{bmatrix} and B=[4361−23]B = \begin{bmatrix} 4 & 3 & 6 \\ 1 & -2 & 3 \end{bmatrix}, entry (1,3)(1,3) of ABAB is row 1 of AA times column 3 of BB: 2(6)+3(3)=212(6) + 3(3) = 21.

Similarly, a whole row of ABAB is (row ii of AA) times BB:

row⁡i(AB)=row⁡i(A)⋅B\operatorname{row}_i(AB) = \operatorname{row}_i(A) \cdot B

Example 6 (Lay §2.1). Find the second row of ABAB, where

A=[2−50−13−46−8−7−309],B=[4−67132]A = \begin{bmatrix} 2 & -5 & 0 \\ -1 & 3 & -4 \\ 6 & -8 & -7 \\ -3 & 0 & 9 \end{bmatrix}, \qquad B = \begin{bmatrix} 4 & -6 \\ 7 & 1 \\ 3 & 2 \end{bmatrix}

Only row 2 of AA is needed:

[−13−4][4−67132]=[−4+21−126+3−8]=[51]\begin{bmatrix} -1 & 3 & -4 \end{bmatrix}\begin{bmatrix} 4 & -6 \\ 7 & 1 \\ 3 & 2 \end{bmatrix} = \begin{bmatrix} -4 + 21 - 12 & 6 + 3 - 8 \end{bmatrix} = \begin{bmatrix} 5 & 1 \end{bmatrix}

How to recognise the question type: “Compute ABAB in two ways” means (a) by the definition, computing Ab1,Ab2,…A\mathbf{b}_1, A\mathbf{b}_2, \dots separately and placing them side by side, and (b) by the row–column rule. “Find the second row of ABAB” means: you only need row 2 of AA (times all of BB). “Find the first column of BB given AA and ABAB” means: solve Ax=(first column of AB)A\mathbf{x} = \text{(first column of } AB).

Properties of Matrix Multiplication

Theorem 2 (Lay §2.1): Let AA be m×nm \times n, and let BB, CC have sizes for which the sums and products are defined. Then

  1. A(BC)=(AB)CA(BC) = (AB)C (associative law)
  2. A(B+C)=AB+ACA(B + C) = AB + AC (left distributive law)
  3. (B+C)A=BA+CA(B + C)A = BA + CA (right distributive law)
  4. r(AB)=(rA)B=A(rB)r(AB) = (rA)B = A(rB) for any scalar rr
  5. ImA=A=AInI_m A = A = A I_n (identity for multiplication)

So IA=AI=AIA = AI = A: the identity matrix plays the role of the number 11.

Common mistakes — matrix algebra is NOT number algebra:

  1. In general AB≠BAAB \ne BA. Order matters: ”AA times BB on the right” (ABAB) differs from ”BB times AA” (BABA). Even when both are defined and the same size, they are usually different.
  2. No cancellation: AB=ACAB = AC does not imply B=CB = C (see Exercise 3 below, textbook Exercise 10).
  3. AB=0AB = 0 does not imply A=0A = 0 or B=0B = 0. For instance [1111][1−1−11]=[0000]\begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix}\begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}.

Powers of a Matrix

If AA is square (n×nn \times n) and kk is a positive integer,

Ak=A⋯A⏟k factors,A0=InA^k = \underbrace{A \cdots A}_{k \text{ factors}}, \qquad A^0 = I_n

AkxA^k \mathbf{x} means applying the transformation x↦Ax\mathbf{x} \mapsto A\mathbf{x} kk times. Note (A+B)2=A2+AB+BA+B2(A + B)^2 = A^2 + AB + BA + B^2, not A2+2AB+B2A^2 + 2AB + B^2 (since AB≠BAAB \ne BA in general).

The Transpose of a Matrix

The transpose ATA^T of an m×nm \times n matrix AA is the n×mn \times m matrix whose columns are the rows of AA (equivalently, (AT)ij=aji(A^T)_{ij} = a_{ji}).

Example 8 (Lay §2.1).

A=[abcd],B=[−521−304],C=[1111−35−27]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix}, \quad B = \begin{bmatrix} -5 & 2 \\ 1 & -3 \\ 0 & 4 \end{bmatrix}, \quad C = \begin{bmatrix} 1 & 1 & 1 & 1 \\ -3 & 5 & -2 & 7 \end{bmatrix} AT=[acbd],BT=[−5102−34],CT=[1−3151−217]A^T = \begin{bmatrix} a & c \\ b & d \end{bmatrix}, \quad B^T = \begin{bmatrix} -5 & 1 & 0 \\ 2 & -3 & 4 \end{bmatrix}, \quad C^T = \begin{bmatrix} 1 & -3 \\ 1 & 5 \\ 1 & -2 \\ 1 & 7 \end{bmatrix}

Theorem 3 (Lay §2.1): Let AA and BB be matrices whose sizes are appropriate for the following sums and products.

  1. (AT)T=A(A^T)^T = A
  2. (A+B)T=AT+BT(A + B)^T = A^T + B^T
  3. (rA)T=rAT(rA)^T = rA^T for any scalar rr
  4. (AB)T=BTAT(AB)^T = B^T A^T

The transpose of a product is the product of the transposes in reverse order. (Check the sizes: if AA is m×nm \times n and BB is n×pn \times p, then BTATB^T A^T is (p×n)(n×m)(p \times n)(n \times m), which works; ATBTA^T B^T usually does not even exist.)


Solved Examples (Textbook Questions)

Exercise 1

(Adapted from Lay §2.1, Exercise 3)

Let A=[4−15−2]A = \begin{bmatrix} 4 & -1 \\ 5 & -2 \end{bmatrix}. Compute 3I2−A3I_2 - A and (3I2)A(3I_2)A.

Show solution ↓
Solution

3I2−A3I_2 - A: 3I23I_2 has 33 on the diagonal, so only the diagonal entries of AA are subtracted from 33; off-diagonal entries just change sign.

3I2−A=[3003]−[4−15−2]=[3−40−(−1)0−53−(−2)]=[−11−55]3I_2 - A = \begin{bmatrix} 3 & 0 \\ 0 & 3 \end{bmatrix} - \begin{bmatrix} 4 & -1 \\ 5 & -2 \end{bmatrix} = \begin{bmatrix} 3 - 4 & 0 - (-1) \\ 0 - 5 & 3 - (-2) \end{bmatrix} = \begin{bmatrix} -1 & 1 \\ -5 & 5 \end{bmatrix}

(3I2)A(3I_2)A: by Theorem 2, (3I2)A=3(I2A)=3A(3I_2)A = 3(I_2A) = 3A:

(3I2)A=3[4−15−2]=[12−315−6](3I_2)A = 3\begin{bmatrix} 4 & -1 \\ 5 & -2 \end{bmatrix} = \begin{bmatrix} 12 & -3 \\ 15 & -6 \end{bmatrix}

Check with the row–column rule:

[3003][4−15−2]=[3⋅4+03(−1)+00+3⋅50+3(−2)]=[12−315−6]✓\begin{bmatrix} 3 & 0 \\ 0 & 3 \end{bmatrix}\begin{bmatrix} 4 & -1 \\ 5 & -2 \end{bmatrix} = \begin{bmatrix} 3 \cdot 4 + 0 & 3(-1) + 0 \\ 0 + 3 \cdot 5 & 0 + 3(-2) \end{bmatrix} = \begin{bmatrix} 12 & -3 \\ 15 & -6 \end{bmatrix} \checkmark
Exercise 2

(Adapted from Lay §2.1, Exercises 5 and 6)

Compute the product ABAB in two ways: (a) by the definition, where Ab1A\mathbf{b}_1 and Ab2A\mathbf{b}_2 are computed separately, and (b) by the row–column rule.

  1. A=[−12542−3]A = \begin{bmatrix} -1 & 2 \\ 5 & 4 \\ 2 & -3 \end{bmatrix}, B=[3−2−21]B = \begin{bmatrix} 3 & -2 \\ -2 & 1 \end{bmatrix}
  2. A=[4−2−3035]A = \begin{bmatrix} 4 & -2 \\ -3 & 0 \\ 3 & 5 \end{bmatrix}, B=[132−1]B = \begin{bmatrix} 1 & 3 \\ 2 & -1 \end{bmatrix}
Show solution ↓
Solution

Size check: (3×2)(2×2)=3×2(3 \times 2)(2 \times 2) = 3 \times 2 in both parts.

Part 1 (Exercise 5).

(a) Each AbjA\mathbf{b}_j is a linear combination of the columns of AA with weights from bj\mathbf{b}_j:

Ab1=3[−152]−2[24−3]=[−7712],Ab2=−2[−152]+1[24−3]=[4−6−7]A\mathbf{b}_1 = 3\begin{bmatrix} -1 \\ 5 \\ 2 \end{bmatrix} - 2\begin{bmatrix} 2 \\ 4 \\ -3 \end{bmatrix} = \begin{bmatrix} -7 \\ 7 \\ 12 \end{bmatrix}, \qquad A\mathbf{b}_2 = -2\begin{bmatrix} -1 \\ 5 \\ 2 \end{bmatrix} + 1\begin{bmatrix} 2 \\ 4 \\ -3 \end{bmatrix} = \begin{bmatrix} 4 \\ -6 \\ -7 \end{bmatrix}AB=[Ab1Ab2]=[−747−612−7]AB = \begin{bmatrix} A\mathbf{b}_1 & A\mathbf{b}_2 \end{bmatrix} = \begin{bmatrix} -7 & 4 \\ 7 & -6 \\ 12 & -7 \end{bmatrix}

(b) Row–column rule:

AB=[−1⋅3+2(−2)−1(−2)+2⋅15⋅3+4(−2)5(−2)+4⋅12⋅3−3(−2)2(−2)−3⋅1]=[−747−612−7]AB = \begin{bmatrix} -1 \cdot 3 + 2(-2) & -1(-2) + 2 \cdot 1 \\ 5 \cdot 3 + 4(-2) & 5(-2) + 4 \cdot 1 \\ 2 \cdot 3 - 3(-2) & 2(-2) - 3 \cdot 1 \end{bmatrix} = \begin{bmatrix} -7 & 4 \\ 7 & -6 \\ 12 & -7 \end{bmatrix}

Part 2 (Exercise 6).

(a)

Ab1=1[4−33]+2[−205]=[0−313],Ab2=3[4−33]−1[−205]=[14−94]A\mathbf{b}_1 = 1\begin{bmatrix} 4 \\ -3 \\ 3 \end{bmatrix} + 2\begin{bmatrix} -2 \\ 0 \\ 5 \end{bmatrix} = \begin{bmatrix} 0 \\ -3 \\ 13 \end{bmatrix}, \qquad A\mathbf{b}_2 = 3\begin{bmatrix} 4 \\ -3 \\ 3 \end{bmatrix} - 1\begin{bmatrix} -2 \\ 0 \\ 5 \end{bmatrix} = \begin{bmatrix} 14 \\ -9 \\ 4 \end{bmatrix}AB=[014−3−9134]AB = \begin{bmatrix} 0 & 14 \\ -3 & -9 \\ 13 & 4 \end{bmatrix}

(b)

AB=[4⋅1−2⋅24⋅3−2(−1)−3⋅1+0⋅2−3⋅3+0(−1)3⋅1+5⋅23⋅3+5(−1)]=[014−3−9134]AB = \begin{bmatrix} 4 \cdot 1 - 2 \cdot 2 & 4 \cdot 3 - 2(-1) \\ -3 \cdot 1 + 0 \cdot 2 & -3 \cdot 3 + 0(-1) \\ 3 \cdot 1 + 5 \cdot 2 & 3 \cdot 3 + 5(-1) \end{bmatrix} = \begin{bmatrix} 0 & 14 \\ -3 & -9 \\ 13 & 4 \end{bmatrix}

Both methods agree, as they must.

Exercise 3

(Adapted from Lay §2.1, Exercises 9 and 10)

  1. Let A=[25−31]A = \begin{bmatrix} 2 & 5 \\ -3 & 1 \end{bmatrix} and B=[4−53k]B = \begin{bmatrix} 4 & -5 \\ 3 & k \end{bmatrix}. What value(s) of kk, if any, will make AB=BAAB = BA?
  2. Let A=[2−3−46]A = \begin{bmatrix} 2 & -3 \\ -4 & 6 \end{bmatrix}, B=[8455]B = \begin{bmatrix} 8 & 4 \\ 5 & 5 \end{bmatrix}, and C=[5−231]C = \begin{bmatrix} 5 & -2 \\ 3 & 1 \end{bmatrix}. Verify that AB=ACAB = AC and yet B≠CB \ne C.
Show solution ↓
Solution

Part 1 (Exercise 9).

AB=[25−31][4−53k]=[8+15−10+5k−12+315+k]=[23−10+5k−915+k]AB = \begin{bmatrix} 2 & 5 \\ -3 & 1 \end{bmatrix}\begin{bmatrix} 4 & -5 \\ 3 & k \end{bmatrix} = \begin{bmatrix} 8 + 15 & -10 + 5k \\ -12 + 3 & 15 + k \end{bmatrix} = \begin{bmatrix} 23 & -10 + 5k \\ -9 & 15 + k \end{bmatrix}BA=[4−53k][25−31]=[8+1520−56−3k15+k]=[23156−3k15+k]BA = \begin{bmatrix} 4 & -5 \\ 3 & k \end{bmatrix}\begin{bmatrix} 2 & 5 \\ -3 & 1 \end{bmatrix} = \begin{bmatrix} 8 + 15 & 20 - 5 \\ 6 - 3k & 15 + k \end{bmatrix} = \begin{bmatrix} 23 & 15 \\ 6 - 3k & 15 + k \end{bmatrix}

The (1,1)(1,1) and (2,2)(2,2) entries already agree. Set the other entries equal:

  • (1,2)(1,2): −10+5k=15⇒k=5-10 + 5k = 15 \Rightarrow k = 5
  • (2,1)(2,1): −9=6−3k⇒3k=15⇒k=5-9 = 6 - 3k \Rightarrow 3k = 15 \Rightarrow k = 5

Both conditions give the same value, so AB=BAAB = BA if and only if k=5k = 5.

Part 2 (Exercise 10).

AB=[2−3−46][8455]=[16−158−15−32+30−16+30]=[1−7−214]AB = \begin{bmatrix} 2 & -3 \\ -4 & 6 \end{bmatrix}\begin{bmatrix} 8 & 4 \\ 5 & 5 \end{bmatrix} = \begin{bmatrix} 16 - 15 & 8 - 15 \\ -32 + 30 & -16 + 30 \end{bmatrix} = \begin{bmatrix} 1 & -7 \\ -2 & 14 \end{bmatrix}AC=[2−3−46][5−231]=[10−9−4−3−20+188+6]=[1−7−214]AC = \begin{bmatrix} 2 & -3 \\ -4 & 6 \end{bmatrix}\begin{bmatrix} 5 & -2 \\ 3 & 1 \end{bmatrix} = \begin{bmatrix} 10 - 9 & -4 - 3 \\ -20 + 18 & 8 + 6 \end{bmatrix} = \begin{bmatrix} 1 & -7 \\ -2 & 14 \end{bmatrix}

So AB=ACAB = AC, but clearly B≠CB \ne C. Cancellation fails for matrices.

Why it happens here: det⁡A=2(6)−(−3)(−4)=12−12=0\det A = 2(6) - (-3)(-4) = 12 - 12 = 0, so AA is not invertible; you cannot “multiply both sides by A−1A^{-1}” to cancel AA. (If AA were invertible, AB=ACAB = AC would force B=CB = C.)

Exercise 4

(Adapted from Lay §2.1, Exercise 11)

Let A=[111123145]A = \begin{bmatrix} 1 & 1 & 1 \\ 1 & 2 & 3 \\ 1 & 4 & 5 \end{bmatrix} and D=[200030005]D = \begin{bmatrix} 2 & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 5 \end{bmatrix}. Compute ADAD and DADA. Explain how the columns or rows of AA change when AA is multiplied by DD on the right or on the left. Find a 3×33 \times 3 matrix BB, not the identity matrix or the zero matrix, such that AB=BAAB = BA.

Show solution ↓
Solution
AD=[111123145][200030005]=[235261521225]AD = \begin{bmatrix} 1 & 1 & 1 \\ 1 & 2 & 3 \\ 1 & 4 & 5 \end{bmatrix}\begin{bmatrix} 2 & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 5 \end{bmatrix} = \begin{bmatrix} 2 & 3 & 5 \\ 2 & 6 & 15 \\ 2 & 12 & 25 \end{bmatrix}DA=[200030005][111123145]=[22236952025]DA = \begin{bmatrix} 2 & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 5 \end{bmatrix}\begin{bmatrix} 1 & 1 & 1 \\ 1 & 2 & 3 \\ 1 & 4 & 5 \end{bmatrix} = \begin{bmatrix} 2 & 2 & 2 \\ 3 & 6 & 9 \\ 5 & 20 & 25 \end{bmatrix}

Interpretation:

  • Right-multiplication by the diagonal DD (ADAD) multiplies each column of AA by the corresponding diagonal entry: column 1 by 2, column 2 by 3, column 3 by 5.
  • Left-multiplication by DD (DADA) multiplies each row of AA by the corresponding diagonal entry.

Since AD≠DAAD \ne DA, this is another example that order matters.

A matrix that commutes with AA: any scalar multiple of the identity works, because (rI)A=rA=A(rI)(rI)A = rA = A(rI). For example B=4I3B = 4I_3:

AB=BA=4A=[444481241620]AB = BA = 4A = \begin{bmatrix} 4 & 4 & 4 \\ 4 & 8 & 12 \\ 4 & 16 & 20 \end{bmatrix}

(Another valid choice is B=AB = A itself, or B=A2B = A^2, since A⋅A=A⋅AA \cdot A = A \cdot A.)

Exercise 5

(Adapted from Lay §2.1, Exercise 17)

If A=[1−2−25]A = \begin{bmatrix} 1 & -2 \\ -2 & 5 \end{bmatrix} and AB=[−12−16−93]AB = \begin{bmatrix} -1 & 2 & -1 \\ 6 & -9 & 3 \end{bmatrix}, determine the first and second columns of BB.

Show solution ↓
Solution

Key idea: by the definition, AB=[Ab1Ab2Ab3]AB = \begin{bmatrix} A\mathbf{b}_1 & A\mathbf{b}_2 & A\mathbf{b}_3 \end{bmatrix}. So column jj of BB solves Ax=(column j of AB)A\mathbf{x} = \text{(column } j \text{ of } AB).

First column: solve Ax=[−16]A\mathbf{x} = \begin{bmatrix} -1 \\ 6 \end{bmatrix}. Row reduce, using R2←R2+2R1R_2 \leftarrow R_2 + 2R_1, then R1←R1+2R2R_1 \leftarrow R_1 + 2R_2:

[1−2−1−256]∼[1−2−1014]∼[107014]⇒b1=[74]\left[\begin{array}{cc|c} 1 & -2 & -1 \\ -2 & 5 & 6 \end{array}\right] \sim \left[\begin{array}{cc|c} 1 & -2 & -1 \\ 0 & 1 & 4 \end{array}\right] \sim \left[\begin{array}{cc|c} 1 & 0 & 7 \\ 0 & 1 & 4 \end{array}\right] \quad\Rightarrow\quad \mathbf{b}_1 = \begin{bmatrix} 7 \\ 4 \end{bmatrix}

Second column: solve Ax=[2−9]A\mathbf{x} = \begin{bmatrix} 2 \\ -9 \end{bmatrix} with the same row operations:

[1−22−25−9]∼[1−2201−5]∼[10−801−5]⇒b2=[−8−5]\left[\begin{array}{cc|c} 1 & -2 & 2 \\ -2 & 5 & -9 \end{array}\right] \sim \left[\begin{array}{cc|c} 1 & -2 & 2 \\ 0 & 1 & -5 \end{array}\right] \sim \left[\begin{array}{cc|c} 1 & 0 & -8 \\ 0 & 1 & -5 \end{array}\right] \quad\Rightarrow\quad \mathbf{b}_2 = \begin{bmatrix} -8 \\ -5 \end{bmatrix}

Check: Ab1=[7−8−14+20]=[−16]A\mathbf{b}_1 = \begin{bmatrix} 7 - 8 \\ -14 + 20 \end{bmatrix} = \begin{bmatrix} -1 \\ 6 \end{bmatrix} ✓ and Ab2=[−8+1016−25]=[2−9]A\mathbf{b}_2 = \begin{bmatrix} -8 + 10 \\ 16 - 25 \end{bmatrix} = \begin{bmatrix} 2 \\ -9 \end{bmatrix} ✓.

Since det⁡A=5−4=1≠0\det A = 5 - 4 = 1 \ne 0, you could also use bj=A−1(column j of AB)\mathbf{b}_j = A^{-1}(\text{column } j \text{ of } AB) with A−1=[5221]A^{-1} = \begin{bmatrix} 5 & 2 \\ 2 & 1 \end{bmatrix}. Both methods give the same answer.