CP 3.1, 3.2 - Matrix arithmetic, zero and identity matrices

CP 3.1, 3.2 - Matrix arithmetic, zero and identity matrices

A matrix keeps a whole collection of numbers in a useful order. You will add, subtract, scale and multiply matrices (CP 3.1), then use the zero and identity matrices to see which familiar algebraic rules survive and which need care (CP 3.2).

Rows, columns and conformability

Two cafés sell the same three drinks. Their prices and Monday's sales are recorded as

P=(234345),q=(10205)\mathbf{P}=\begin{pmatrix}2&3&4\\3&4&5\end{pmatrix},\qquad \mathbf{q}=\begin{pmatrix}10\\20\\5\end{pmatrix}

The rows of P\mathbf{P} refer to the cafés; its columns refer, in order, to tea, coffee and chocolate. Both cafés sell the numbers in q\mathbf{q}. Can one calculation find both cafés' takings? By the end you will find the answer without losing track of which price belongs to which drink.

A matrix is more than a bag of numbers. Moving an entry changes its meaning: the first café's coffee costs 33, while the second café's chocolate costs 55. The order matters even when no context is supplied.

Matrix and order

A matrix is a rectangular array of entries. Its order is the number of rows followed by the number of columns. Thus P\mathbf{P} has order 2×32\times3, and q\mathbf{q} has order 3×13\times1. The entry pijp_{ij} is in row ii, column jj; for example, p23=5p_{23}=5. A square matrix has the same number of rows as columns. A row matrix has one row; a column matrix has one column.

Two matrices are equal precisely when they have the same order and every corresponding entry agrees. For example,

(a2−1b)=(32−14)⟺a=3, b=4\begin{pmatrix}a&2\\-1&b\end{pmatrix} = \begin{pmatrix}3&2\\-1&4\end{pmatrix} \quad\Longleftrightarrow\quad a=3,\ b=4

The matrices (12)\begin{pmatrix}1&2\end{pmatrix} and (12)\begin{pmatrix}1\\2\end{pmatrix} are not equal: one has order 1×21\times2, the other 2×12\times1. Before calculating, ask whether the shapes fit the operation.

Conformable matrices

Matrices are conformable for an operation when their orders allow it. Addition and subtraction require the same order. For multiplication, the number of columns of the left matrix must equal the number of rows of the right matrix.

For multiplication the matching middle numbers disappear from the order calculation:

(m×n)(n×p)⟶m×p(m\times n)(n\times p)\longrightarrow m\times p

This size rule is not in the formula booklet: learn it. It predicts the shape before you do any arithmetic.

Key idea

Read matrix orders as rows then columns. For a product, match the inner dimensions and keep the outer dimensions.

Test the shape first; there is no need to invent entries for this check.

Adding, subtracting and scaling

Addition combines corresponding entries; multiplication by a scalar changes every entry by the same factor.

For example, two days' sales tables can be added only if their rows and columns refer to the same things in the same order. Algebraically, equal shapes are essential. A scalar is simply an ordinary number, rather than a matrix.

Entrywise arithmetic

For matrices A\mathbf{A} and B\mathbf{B} of the same order and a scalar kk,

(A±B)ij=aij±bij,(kA)ij=kaij(\mathbf{A}\pm\mathbf{B})_{ij}=a_{ij}\pm b_{ij},\qquad (k\mathbf{A})_{ij}=ka_{ij}

Not in the formula booklet: learn it.

Treat each position as a separate small calculation. Subtracting a matrix means subtracting every one of its entries, including negative ones.

Worked example 1: a linear combination

Question. Given A=(2−134)\mathbf{A}=\begin{pmatrix}2&-1\\3&4\end{pmatrix} and B=(−152−3)\mathbf{B}=\begin{pmatrix}-1&5\\2&-3\end{pmatrix}, find 2A−B2\mathbf{A}-\mathbf{B}.

Plan. Double every entry of A\mathbf{A}, then subtract the corresponding entry of B\mathbf{B}.

2A−B=(4−268)−(−152−3)scale first=(4−(−1)−2−56−28−(−3))match positions=(5−7411)\begin{aligned} 2\mathbf{A}-\mathbf{B} &=\begin{pmatrix}4&-2\\6&8\end{pmatrix}-\begin{pmatrix}-1&5\\2&-3\end{pmatrix}&&\text{scale first}\\ &=\begin{pmatrix}4-(-1)&-2-5\\6-2&8-(-3)\end{pmatrix}&&\text{match positions}\\ &=\begin{pmatrix}5&-7\\4&11\end{pmatrix} \end{aligned}

Why this step? Keeping the negative entries in brackets prevents 8−(−3)8-(-3) from becoming 8−38-3.

Answer. 2A−B=(5−7411)2\mathbf{A}-\mathbf{B}=\begin{pmatrix}5&-7\\4&11\end{pmatrix}.

Check. Adding B\mathbf{B} to the answer gives (4−268)=2A\begin{pmatrix}4&-2\\6&8\end{pmatrix}=2\mathbf{A}.

The second example changes one feature: the matrix itself is unknown. The same entrywise rules let you rearrange a matrix equation.

Worked example 2: an unknown matrix

Question. Given 3X+B=2A3\mathbf{X}+\mathbf{B}=2\mathbf{A}, where A=(14−23)\mathbf{A}=\begin{pmatrix}1&4\\-2&3\end{pmatrix} and B=(5−120)\mathbf{B}=\begin{pmatrix}5&-1\\2&0\end{pmatrix}, determine X\mathbf{X}.

Plan. Subtract B\mathbf{B}, then multiply every entry by 13\frac13.

3X=2A−Bsubtract B=(2−58−(−1)−4−26−0)entrywise arithmetic=(−39−66)X=(−13−22)divide all entries by 3\begin{aligned} 3\mathbf{X}&=2\mathbf{A}-\mathbf{B}&&\text{subtract }\mathbf{B}\\ &=\begin{pmatrix}2-5&8-(-1)\\-4-2&6-0\end{pmatrix}&&\text{entrywise arithmetic}\\ &=\begin{pmatrix}-3&9\\-6&6\end{pmatrix}\\ \mathbf{X}&=\begin{pmatrix}-1&3\\-2&2\end{pmatrix}&&\text{divide all entries by }3 \end{aligned}

Why this step? Division by the scalar 33 is ordinary scalar multiplication by 13\frac13; no matrix division is involved.

Answer. X=(−13−22)\mathbf{X}=\begin{pmatrix}-1&3\\-2&2\end{pmatrix}.

Check. 3X+B=(28−46)=2A3\mathbf{X}+\mathbf{B}=\begin{pmatrix}2&8\\-4&6\end{pmatrix}=2\mathbf{A}.

A minus sign outside a matrix acts on the entire array.

Watch out

Wrong: −(2−314)=(−2−314)-\begin{pmatrix}2&-3\\1&4\end{pmatrix}=\begin{pmatrix}-2&-3\\1&4\end{pmatrix}. Right: −(2−314)=(−23−1−4)-\begin{pmatrix}2&-3\\1&4\end{pmatrix}=\begin{pmatrix}-2&3\\-1&-4\end{pmatrix}. Every entry changes sign.

The next equation changes the scalar coefficient, so divide only after collecting the matrices.

Multiplying matrices

Matrix multiplication pairs a row from the left matrix with a column from the right matrix: multiply matching entries and add the products.

The café question supplies a concrete reason. The first café's takings are 2(10)+3(20)+4(5)=1002(10)+3(20)+4(5)=100; the second café's are 3(10)+4(20)+5(5)=1353(10)+4(20)+5(5)=135. Both calculations fit inside

(234345)(10205)=(100135)\begin{pmatrix}2&3&4\\3&4&5\end{pmatrix}\begin{pmatrix}10\\20\\5\end{pmatrix} =\begin{pmatrix}100\\135\end{pmatrix}

The three entries of each price row match the three sales entries. This explains the conformability rule: each row-column calculation needs the same number of entries on both sides.

Row by column

If A\mathbf{A} has order m×nm\times n and B\mathbf{B} has order n×pn\times p, then AB\mathbf{A}\mathbf{B} has order m×pm\times p, with

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

Not in the formula booklet: learn it.

A product of two matrices is usually not the matrix of entrywise products. Each output entry collects a whole row-column calculation.

Worked example 3: a rectangular product

Question. Find AB\mathbf{A}\mathbf{B}, where A=(12−1032)\mathbf{A}=\begin{pmatrix}1&2&-1\\0&3&2\end{pmatrix} and B=(21−1430)\mathbf{B}=\begin{pmatrix}2&1\\-1&4\\3&0\end{pmatrix}.

Plan. The orders (2×3)(3×2)(2\times3)(3\times2) give a 2×22\times2 answer; calculate its four entries row by column.

AB=(1(2)+2(−1)+(−1)(3)1(1)+2(4)+(−1)(0)0(2)+3(−1)+2(3)0(1)+3(4)+2(0))=(−39312)sum each entry\begin{aligned} \mathbf{A}\mathbf{B} &=\begin{pmatrix}1(2)+2(-1)+(-1)(3)&1(1)+2(4)+(-1)(0)\\0(2)+3(-1)+2(3)&0(1)+3(4)+2(0)\end{pmatrix}\\ &=\begin{pmatrix}-3&9\\3&12\end{pmatrix}&&\text{sum each entry} \end{aligned}

Why this step? The upper-right entry uses row 11 of A\mathbf{A} and column 22 of B\mathbf{B}, so it is 1+8+01+8+0, not the product of the two upper-right entries.

Answer. AB=(−39312)\mathbf{A}\mathbf{B}=\begin{pmatrix}-3&9\\3&12\end{pmatrix}.

Check. The answer has two rows and two columns, and its lower-left entry is −3+6=3-3+6=3.

The second product changes the left matrix from rectangular to square. The rule stays exactly the same, and now produces three rows.

Worked example 4: a three-row product

Question. Calculate (102−131210)(210−132)\begin{pmatrix}1&0&2\\-1&3&1\\2&1&0\end{pmatrix}\begin{pmatrix}2&1\\0&-1\\3&2\end{pmatrix}.

Plan. Use each of the three left rows with each of the two right columns.

AB=(2+0+61+0+4−2+0+3−1−3+24+0+02−1+0)row-column sums=(851−241)\begin{aligned} \mathbf{A}\mathbf{B} &=\begin{pmatrix}2+0+6&1+0+4\\-2+0+3&-1-3+2\\4+0+0&2-1+0\end{pmatrix}&&\text{row-column sums}\\ &=\begin{pmatrix}8&5\\1&-2\\4&1\end{pmatrix} \end{aligned}

Why this step? There are two output columns because the right matrix has two columns. A 3×33\times3 left matrix does not force a square answer.

Answer. (851−241)\begin{pmatrix}8&5\\1&-2\\4&1\end{pmatrix}.

Check. The orders are (3×3)(3×2)(3\times3)(3\times2), leaving 3×23\times2. The middle-right entry is (−1)(1)+3(−1)+1(2)=−2(-1)(1)+3(-1)+1(2)=-2.

The order also matters algebraically. For C=(1101)\mathbf{C}=\begin{pmatrix}1&1\\0&1\end{pmatrix} and D=(2001)\mathbf{D}=\begin{pmatrix}2&0\\0&1\end{pmatrix}, row-column multiplication gives

CD=(2101),DC=(2201)\mathbf{C}\mathbf{D}=\begin{pmatrix}2&1\\0&1\end{pmatrix},\qquad \mathbf{D}\mathbf{C}=\begin{pmatrix}2&2\\0&1\end{pmatrix}

Thus matrix multiplication is generally not commutative. It is associative, so (AB)C=A(BC)(\mathbf{A}\mathbf{B})\mathbf{C}=\mathbf{A}(\mathbf{B}\mathbf{C}) when conformable, and distributive: A(B+C)=AB+AC\mathbf{A}(\mathbf{B}+\mathbf{C})=\mathbf{A}\mathbf{B}+\mathbf{A}\mathbf{C}. These rules are not in the formula booklet: learn them. You may change brackets, but you may not silently reverse factors.

Watch out

Wrong: “AB=BA\mathbf{A}\mathbf{B}=\mathbf{B}\mathbf{A} because ordinary multiplication commutes.” The two products can differ, and one may not even exist. Right: keep the written order and use rows from the left factor.

Try the same three-term row-column sums with new entries.

Zero matrices, identity matrices and powers

The zero matrix plays the additive role of zero, while the identity matrix plays the multiplicative role of one.

For a 2×22\times2 example, adding (0000)\begin{pmatrix}0&0\\0&0\end{pmatrix} leaves each entry unchanged. Multiplying on the right by (1001)\begin{pmatrix}1&0\\0&1\end{pmatrix} selects the original first and second columns in turn.

Zero and identity matrices

A zero matrix, 0\mathbf{0}, has every entry zero; it can have any order. The identity matrix, In\mathbf{I}_n, is square of order n×nn\times n, with ones on the main diagonal and zeros elsewhere. For example,

I3=(100010001)\mathbf{I}_3=\begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}

The matrix (1111)\begin{pmatrix}1&1\\1&1\end{pmatrix} is not an identity matrix.

Use the size needed for each operation: for an m×nm\times n matrix A\mathbf{A}, the identities on its two sides have different orders when m≠nm\ne n.

Zero, identity and powers

For conformable matrices,

A+0=A,A−A=0,A0=0,0A=0,ImA=AIn=A\mathbf{A}+\mathbf{0}=\mathbf{A},\quad \mathbf{A}-\mathbf{A}=\mathbf{0},\quad \mathbf{A}\mathbf{0}=\mathbf{0},\quad \mathbf{0}\mathbf{A}=\mathbf{0},\quad \mathbf{I}_m\mathbf{A}=\mathbf{A}\mathbf{I}_n=\mathbf{A}

For square A\mathbf{A}, A2=AA\mathbf{A}^2=\mathbf{A}\mathbf{A} and A3=A2A\mathbf{A}^3=\mathbf{A}^2\mathbf{A}; positive integer powers are repeated matrix products. Not in the formula booklet: learn it.

A scalar in a matrix polynomial means a scalar multiple of the identity: the matrix version of a constant term 66 is 6I6\mathbf{I}.

Worked example 5: evaluating a matrix polynomial

Question. For M=(1203)\mathbf{M}=\begin{pmatrix}1&2\\0&3\end{pmatrix}, calculate M2−4M\mathbf{M}^2-4\mathbf{M}.

Plan. Square by row-column multiplication, then subtract four times each entry.

M2=(1203)(1203)=(12+609)=(1809)row by columnM2−4M=(1−48−809−12)=−3I2subtract entrywise\begin{aligned} \mathbf{M}^2&=\begin{pmatrix}1&2\\0&3\end{pmatrix}\begin{pmatrix}1&2\\0&3\end{pmatrix}\\ &=\begin{pmatrix}1&2+6\\0&9\end{pmatrix}=\begin{pmatrix}1&8\\0&9\end{pmatrix}&&\text{row by column}\\ \mathbf{M}^2-4\mathbf{M}&=\begin{pmatrix}1-4&8-8\\0&9-12\end{pmatrix}=-3\mathbf{I}_2&&\text{subtract entrywise} \end{aligned}

Why this step? M2\mathbf{M}^2 means MM\mathbf{M}\mathbf{M}, so its upper-right entry is 88, not 222^2.

Answer. M2−4M=−3I2\mathbf{M}^2-4\mathbf{M}=-3\mathbf{I}_2.

Check. Adding 4M4\mathbf{M} to −3I2-3\mathbf{I}_2 gives (1809)=M2\begin{pmatrix}1&8\\0&9\end{pmatrix}=\mathbf{M}^2.

The next example changes one feature: an entry is unknown. An identity-matrix equation tells you that both off-diagonal entries must vanish.

Worked example 6: equating matrix entries

Question. Let N=(213t)\mathbf{N}=\begin{pmatrix}2&1\\3&t\end{pmatrix}. Given N2−5N=kI2\mathbf{N}^2-5\mathbf{N}=k\mathbf{I}_2, determine tt and kk.

Plan. Multiply out and compare the off-diagonal entries with zero before finding the diagonal constant.

N2−5N=(72+t6+3t3+t2)−(105155t)=(−3t−33t−9t2−5t+3)collect entriest−3=0⟹t=3upper-right entryk=−3upper-left entry\begin{aligned} \mathbf{N}^2-5\mathbf{N} &=\begin{pmatrix}7&2+t\\6+3t&3+t^2\end{pmatrix}-\begin{pmatrix}10&5\\15&5t\end{pmatrix}\\ &=\begin{pmatrix}-3&t-3\\3t-9&t^2-5t+3\end{pmatrix}&&\text{collect entries}\\ t-3&=0\quad\Longrightarrow\quad t=3&&\text{upper-right entry}\\ k&=-3&&\text{upper-left entry} \end{aligned}

Why this step? An off-diagonal equation is linear in tt, and the second one checks it. Using only the lower-right entry can introduce an unwanted value.

Answer. t=3t=3 and k=−3k=-3.

Check. The lower-left entry is 9−9=09-9=0; the lower-right entry is 9−15+3=−3=k9-15+3=-3=k.

Here is a small surprise: two non-zero matrices can multiply to zero. In fact,

U=(0100)≠0,U2=(0000)\mathbf{U}=\begin{pmatrix}0&1\\0&0\end{pmatrix}\ne\mathbf{0},\qquad \mathbf{U}^2=\begin{pmatrix}0&0\\0&0\end{pmatrix}

So AB=0\mathbf{A}\mathbf{B}=\mathbf{0} does not force either factor to be zero. Nor can you cancel an arbitrary non-zero matrix as though it were a non-zero number. Inverse matrices, studied later, tell you when cancellation is justified.

Watch out

Wrong: M2=(1409)\mathbf{M}^2=\begin{pmatrix}1&4\\0&9\end{pmatrix} in Worked example 5. Squaring entries is a different operation. Right: calculate MM=(1809)\mathbf{M}\mathbf{M}=\begin{pmatrix}1&8\\0&9\end{pmatrix}.

The opening café calculation is now ordinary matrix multiplication: Pq=(100135)\mathbf{P}\mathbf{q}=\begin{pmatrix}100\\135\end{pmatrix}. It gives both takings at once, with rows preserving the café labels.

Quick Recap

  • Matrix orders count rows then columns; equal matrices have equal corresponding entries.
  • Add, subtract and scale entry by entry. Multiply row by column, matching the inner dimensions.
  • Matrix multiplication is associative and distributive, but generally not commutative.
  • A zero matrix adds nothing; an identity matrix leaves a conformable factor unchanged. Matrix powers use repeated matrix multiplication.
  • Non-zero matrices can multiply to zero, so ordinary cancellation needs care.

The two cafés take 100100 and 135135: one product Pq\mathbf{P}\mathbf{q} keeps both calculations organised.