Pm1–Pm3 - Adding and multiplying matrices

Pm1–Pm3 - Adding and multiplying matrices

A matrix lets you organise several numbers and calculate with them as one object. You learn the arithmetic in Pm1, equality and the zero and identity matrices in Pm2, and the multiplication rules in Pm3. The important change from ordinary algebra is that the order of a product can change its value.

Entries, equality and scalar arithmetic

Can two non-zero matrices multiply to give a matrix containing nothing but zeros?

For ordinary real numbers, a zero product forces at least one factor to be zero. Matrices will provide a surprise. First, you need to know what their entries mean and how their arithmetic works.

The array (2−14035)\begin{pmatrix}2&-1&4\\0&3&5\end{pmatrix} has two horizontal rows and three vertical columns. Its entry in row 11, column 33 is 44. Keeping each entry in its own place matters: swapping two entries usually changes the matrix.

Matrix and equality

A matrix is a rectangular array of entries. Its order is the number of rows followed by the number of columns: the array above is a 2×32\times3 matrix. Two matrices are equal precisely when they have the same order and every pair of corresponding entries is equal. For example, (1234)≠(1324)\begin{pmatrix}1&2\\3&4\end{pmatrix}\ne\begin{pmatrix}1&3\\2&4\end{pmatrix}, although they contain the same four numbers.

Addition and subtraction combine corresponding entries, so the two matrices must have the same order. Multiplication by a scalar, an ordinary number, multiplies every entry. These operations keep the order of the original matrix.

Entry-by-entry arithmetic

For matrices A=(aij)\mathbf{A}=(a_{ij}) and B=(bij)\mathbf{B}=(b_{ij}) of the same order, and a scalar kk:

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

The subscripts i,ji,j mean row ii, column jj.

Not in the formula booklet: learn it.

Treat a matrix subtraction like a bracket subtraction: the minus sign reaches every entry of the second matrix.

Worked example 1: combining two arrays

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

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

2A=(4−260)multiply each entry by 22A−B=(4−1−2−46−(−2)0−5)keep matching positions=(3−68−5)simplify each entry\begin{aligned} 2\mathbf{A}&=\begin{pmatrix}4&-2\\6&0\end{pmatrix}&&\text{multiply each entry by }2\\ 2\mathbf{A}-\mathbf{B}&=\begin{pmatrix}4-1&-2-4\\6-(-2)&0-5\end{pmatrix}&&\text{keep matching positions}\\ &=\begin{pmatrix}3&-6\\8&-5\end{pmatrix}&&\text{simplify each entry} \end{aligned}

Why this step? The lower-left entry of B\mathbf{B} is negative, so subtracting it adds 22.

Answer. 2A−B=(3−68−5)2\mathbf{A}-\mathbf{B}=\begin{pmatrix}3&-6\\8&-5\end{pmatrix}.

Check. Adding B\mathbf{B} back gives (4−260)=2A\begin{pmatrix}4&-2\\6&0\end{pmatrix}=2\mathbf{A}.

The next example changes one feature: two entries are unknown. Equality lets you turn the matrix statement into ordinary equations.

Worked example 2: unknown entries

Question. Determine xx and yy, given

2(x−13y)−(14−25)=(7−681)2\begin{pmatrix}x&-1\\3&y\end{pmatrix}-\begin{pmatrix}1&4\\-2&5\end{pmatrix} =\begin{pmatrix}7&-6\\8&1\end{pmatrix}

Plan. Form the left-hand matrix, then equate corresponding entries.

Left side=(2x−1−682y−5)entry-by-entry arithmetic2x−1=7,2y−5=1equal matricesx=4,y=3solve the two equations\begin{aligned} \text{Left side}&=\begin{pmatrix}2x-1&-6\\8&2y-5\end{pmatrix}&&\text{entry-by-entry arithmetic}\\ 2x-1&=7,\qquad 2y-5=1&&\text{equal matrices}\\ x&=4,\qquad y=3&&\text{solve the two equations} \end{aligned}

Why this step? Matrix equality requires all four entries to agree. The other two entries already agree and impose no further condition.

Answer. x=4x=4 and y=3y=3.

Check. Substitution gives 2x−1=72x-1=7 and 2y−5=12y-5=1, while the off-diagonal entries remain −6-6 and 88.

A matrix equation can contain redundant information. Check every entry, because a conflicting entry would mean that no solution exists.

Watch out

Wrong: −(1−324)=(−1−3−2−4)-\begin{pmatrix}1&-3\\2&4\end{pmatrix}=\begin{pmatrix}-1&-3\\-2&-4\end{pmatrix}. The upper-right sign was missed. Right: the upper-right entry is −(−3)=3-(-3)=3, so every entry changes sign.

In the next equation the known entries give a useful consistency check before you solve for the unknowns.

Multiplying rows by columns

A matrix product combines a row of the first matrix with a column of the second, rather than multiplying entries in matching positions.

Suppose a row (213)\begin{pmatrix}2&1&3\end{pmatrix} lists quantities and a column (452)\begin{pmatrix}4\\5\\2\end{pmatrix} lists their prices. The total is 2(4)+1(5)+3(2)=192(4)+1(5)+3(2)=19. A matrix product collects many such totals at once.

Conformable matrices

Matrices are conformable for multiplication in a given order when the first has as many columns as the second has rows. A p×qp\times q matrix multiplied by a q×rq\times r matrix gives a p×rp\times r matrix. For example, (2×3)(3×2)(2\times3)(3\times2) is defined; (2×3)(2×3)(2\times3)(2\times3) is not.

The matching inner dimensions count how many products go into each entry. The outer dimensions tell you the shape of the answer.

Row-by-column multiplication

If A\mathbf{A} is p×qp\times q and B\mathbf{B} is q×rq\times r, then

(AB)ij=∑k=1qaikbkj(\mathbf{A}\mathbf{B})_{ij}=\sum_{k=1}^{q}a_{ik}b_{kj}

Multiply matching entries of row ii and column jj, then add their products.

Not in the formula booklet: learn it.

The diagram singles out one entry. Its row number comes from the first matrix; its column number comes from the second.

[DIAGRAM: asset_name: A row meets a column; asset_slug: matrix_row_column; caption: Row 1 of A and column 2 of B produce entry 1,2 of AB; description: The first row 2, 1, 3 of a two by three matrix A is highlighted blue. The second column 1, minus 2, 0 of a three by two matrix B is highlighted clay. A separate calculation gives 2 times 1 plus 1 times minus 2 plus 3 times 0 equals 0. In the product matrix with rows 19, 0 and 6, minus 5, the top-right entry 0 is highlighted sage.]
Row 1 of A and column 2 of B produce entry 1,2 of AB

Worked example 3: a rectangular product

Question. Find AB\mathbf{A}\mathbf{B}, where

A=(213−120),B=(415−220)\mathbf{A}=\begin{pmatrix}2&1&3\\-1&2&0\end{pmatrix},\qquad \mathbf{B}=\begin{pmatrix}4&1\\5&-2\\2&0\end{pmatrix}

Plan. Check the dimensions, then calculate the four row-by-column totals.

(2×3)(3×2)⟶2×2inner dimensions agree(AB)11=2(4)+1(5)+3(2)=19row 1, column 1(AB)12=2(1)+1(−2)+3(0)=0row 1, column 2(AB)21=−1(4)+2(5)+0(2)=6row 2, column 1(AB)22=−1(1)+2(−2)+0(0)=−5row 2, column 2\begin{aligned} (2\times3)(3\times2)&\longrightarrow2\times2&&\text{inner dimensions agree}\\ (\mathbf{A}\mathbf{B})_{11}&=2(4)+1(5)+3(2)=19&&\text{row }1,\text{ column }1\\ (\mathbf{A}\mathbf{B})_{12}&=2(1)+1(-2)+3(0)=0&&\text{row }1,\text{ column }2\\ (\mathbf{A}\mathbf{B})_{21}&=-1(4)+2(5)+0(2)=6&&\text{row }2,\text{ column }1\\ (\mathbf{A}\mathbf{B})_{22}&=-1(1)+2(-2)+0(0)=-5&&\text{row }2,\text{ column }2 \end{aligned}

Why this step? A row and a column must contain the same number of entries. That is why the dimension condition comes before the arithmetic.

Answer. AB=(1906−5)\mathbf{A}\mathbf{B}=\begin{pmatrix}19&0\\6&-5\end{pmatrix}.

Check. Multiplying B\mathbf{B} by (10)\begin{pmatrix}1\\0\end{pmatrix} selects its first column; applying A\mathbf{A} gives (196)\begin{pmatrix}19\\6\end{pmatrix}, the first column of the answer.

The next example changes the size to 3×33\times3. The rule is identical: there are nine entries to find, each made from three products. A calculator can check the complete product, but you should be able to produce it by hand too.

Worked example 4: a three-by-three product

Question. Find CD\mathbf{C}\mathbf{D}, where

C=(1200−13211),D=(2011100−21)\mathbf{C}=\begin{pmatrix}1&2&0\\0&-1&3\\2&1&1\end{pmatrix},\qquad \mathbf{D}=\begin{pmatrix}2&0&1\\1&1&0\\0&-2&1\end{pmatrix}

Plan. Work across each row of the answer in turn, keeping all three terms in every dot product.

(CD)11=1(2)+2(1)+0(0)=4(CD)12=1(0)+2(1)+0(−2)=2(CD)13=1(1)+2(0)+0(1)=1\begin{aligned} (\mathbf{C}\mathbf{D})_{11}&=1(2)+2(1)+0(0)=4\\ (\mathbf{C}\mathbf{D})_{12}&=1(0)+2(1)+0(-2)=2\\ (\mathbf{C}\mathbf{D})_{13}&=1(1)+2(0)+0(1)=1 \end{aligned}

The same first-row method now uses the second row, then the third row.

(CD)21=0(2)−1(1)+3(0)=−1(CD)22=0(0)−1(1)+3(−2)=−7(CD)23=0(1)−1(0)+3(1)=3(CD)31=2(2)+1(1)+1(0)=5(CD)32=2(0)+1(1)+1(−2)=−1(CD)33=2(1)+1(0)+1(1)=3\begin{aligned} (\mathbf{C}\mathbf{D})_{21}&=0(2)-1(1)+3(0)=-1\\ (\mathbf{C}\mathbf{D})_{22}&=0(0)-1(1)+3(-2)=-7\\ (\mathbf{C}\mathbf{D})_{23}&=0(1)-1(0)+3(1)=3\\[2mm] (\mathbf{C}\mathbf{D})_{31}&=2(2)+1(1)+1(0)=5\\ (\mathbf{C}\mathbf{D})_{32}&=2(0)+1(1)+1(-2)=-1\\ (\mathbf{C}\mathbf{D})_{33}&=2(1)+1(0)+1(1)=3 \end{aligned}

Why this step? Completing one answer row at a time keeps the same left-hand row in view and reduces the chance of mixing positions.

Answer. CD=(421−1−735−13)\mathbf{C}\mathbf{D}=\begin{pmatrix}4&2&1\\-1&-7&3\\5&-1&3\end{pmatrix}.

Check. The last column is C(101)=(133)\mathbf{C}\begin{pmatrix}1\\0\\1\end{pmatrix}=\begin{pmatrix}1\\3\\3\end{pmatrix}. In matrix mode, enter both matrices as 3×33\times3 and evaluate CD\mathbf{C}\mathbf{D} in that order; all nine entries agree.

A calculator is useful for checking arithmetic. Under detailed reasoning, the row-by-column calculation must still appear in your answer.

Watch out

Wrong: (1234)2=(14916)\begin{pmatrix}1&2\\3&4\end{pmatrix}^2=\begin{pmatrix}1&4\\9&16\end{pmatrix}. A square means a matrix multiplied by itself. Right: row-by-column multiplication gives (7101522)\begin{pmatrix}7&10\\15&22\end{pmatrix}.

Keep the zeros visible in the following product until you are sure which row and column you are using.

Zero and identity matrices

Zero and one have matrix counterparts, but their sizes must fit the calculation.

The 2×32\times3 zero matrix is (000000)\begin{pmatrix}0&0&0\\0&0&0\end{pmatrix}. Adding it to any 2×32\times3 matrix changes nothing. Multiplying a conformable matrix by a zero matrix gives a zero matrix of the product's order, because every row-by-column term contains a zero.

Zero and identity matrices

The zero matrix 0\mathbf{0} has every entry zero. The identity matrix In\mathbf{I}_n is the square n×nn\times n matrix with 11 on its main diagonal and 00 elsewhere. For example,

I2=(1001),I3=(100010001)\mathbf{I}_2=\begin{pmatrix}1&0\\0&1\end{pmatrix},\qquad \mathbf{I}_3=\begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}

A matrix of all ones is not an identity matrix.

The diagonal ones select the entries that should survive. For instance, the first row of I2A\mathbf{I}_2\mathbf{A} is 11 times row 11 of A\mathbf{A} plus 00 times row 22. Each row is copied unchanged.

Identity and zero rules

For any p×qp\times q matrix A\mathbf{A}:

IpA=A=AIq,A+0=A\mathbf{I}_p\mathbf{A}=\mathbf{A}=\mathbf{A}\mathbf{I}_q,\qquad \mathbf{A}+\mathbf{0}=\mathbf{A}

The zero matrix in the sum must also be p×qp\times q. Every defined product with a zero factor is zero.

Not in the formula booklet: learn it.

The converse of the last sentence is false. Here is the promised surprise:

(1000)(0001)=(0000)\begin{pmatrix}1&0\\0&0\end{pmatrix} \begin{pmatrix}0&0\\0&1\end{pmatrix} =\begin{pmatrix}0&0\\0&0\end{pmatrix}

Both factors are non-zero. One retains only the first coordinate, while the other retains only the second; doing both leaves nothing. So AB=0\mathbf{A}\mathbf{B}=\mathbf{0} does not force either matrix to be zero, and ordinary scalar cancellation cannot simply be copied into matrix algebra.

Key idea

The identity leaves every conformable matrix unchanged. A zero product can have two non-zero matrix factors.

For a rectangular matrix the identity on the left can have a different order from the identity on the right. The dimensions tell you which one to use.

Order and brackets in a product

You may move brackets in a matrix product, but you may not freely exchange its factors.

For ordinary numbers, 2(3×4)=(2×3)42(3\times4)=(2\times3)4 and 2×3=3×22\times3=3\times2. These are two different properties. Associative concerns brackets; commutative concerns order.

Associativity without commutativity

For conformable matrices,

(AB)C=A(BC)(\mathbf{A}\mathbf{B})\mathbf{C}=\mathbf{A}(\mathbf{B}\mathbf{C})

Matrix multiplication is associative. In general,

AB≠BA\mathbf{A}\mathbf{B}\ne\mathbf{B}\mathbf{A}

so it is not commutative. Particular pairs can commute; sometimes only one order of product is defined.

Not in the formula booklet: learn it.

Associativity follows because either bracketing adds the same products aijbjkckℓa_{ij}b_{jk}c_{k\ell}. It lets you choose a cheaper calculation. If A\mathbf{A} and B\mathbf{B} are 3×33\times3 and v\mathbf{v} is 3×13\times1, calculating A(Bv)\mathbf{A}(\mathbf{B}\mathbf{v}) uses two matrix-vector products rather than first finding all nine entries of AB\mathbf{A}\mathbf{B}. Their order stays A,B,v\mathbf{A},\mathbf{B},\mathbf{v}.

Worked example 5: testing whether matrices commute

Question. Determine whether A=(1101)\mathbf{A}=\begin{pmatrix}1&1\\0&1\end{pmatrix} and B=(2001)\mathbf{B}=\begin{pmatrix}2&0\\0&1\end{pmatrix} commute under multiplication.

Plan. Calculate both products and compare corresponding entries.

AB=(1(2)+1(0)1(0)+1(1)0(2)+1(0)0(0)+1(1))first order=(2101)BA=(2(1)+0(0)2(1)+0(1)0(1)+1(0)0(1)+1(1))reverse order=(2201)\begin{aligned} \mathbf{A}\mathbf{B}&=\begin{pmatrix}1(2)+1(0)&1(0)+1(1)\\0(2)+1(0)&0(0)+1(1)\end{pmatrix}&&\text{first order}\\ &=\begin{pmatrix}2&1\\0&1\end{pmatrix}\\ \mathbf{B}\mathbf{A}&=\begin{pmatrix}2(1)+0(0)&2(1)+0(1)\\0(1)+1(0)&0(1)+1(1)\end{pmatrix}&&\text{reverse order}\\ &=\begin{pmatrix}2&2\\0&1\end{pmatrix} \end{aligned}

Why this step? “Not commutative in general” does not settle a question about a particular pair. The two products provide the evidence.

Answer. The upper-right entries differ, so AB≠BA\mathbf{A}\mathbf{B}\ne\mathbf{B}\mathbf{A}. These matrices do not commute.

Check. On v=(12)\mathbf{v}=\begin{pmatrix}1\\2\end{pmatrix}, A(Bv)=A(22)=(42)\mathbf{A}(\mathbf{B}\mathbf{v})=\mathbf{A}\begin{pmatrix}2\\2\end{pmatrix}=\begin{pmatrix}4\\2\end{pmatrix}, agreeing with (AB)v(\mathbf{A}\mathbf{B})\mathbf{v}. Reversing the factors gives (62)\begin{pmatrix}6\\2\end{pmatrix}.

The next example changes only the lower-right entry of B\mathbf{B}, making both diagonal entries 22. This particular pair now commutes.

Worked example 6: a commuting pair

Question. Determine whether A=(1101)\mathbf{A}=\begin{pmatrix}1&1\\0&1\end{pmatrix} and C=(2002)\mathbf{C}=\begin{pmatrix}2&0\\0&2\end{pmatrix} commute.

Plan. Evaluate both orders and identify why they agree.

AC=(1(2)+1(0)1(0)+1(2)0(2)+1(0)0(0)+1(2))rows by columns=(2202)CA=(2(1)+0(0)2(1)+0(1)0(1)+2(0)0(1)+2(1))reverse the factors=(2202)\begin{aligned} \mathbf{A}\mathbf{C}&=\begin{pmatrix}1(2)+1(0)&1(0)+1(2)\\0(2)+1(0)&0(0)+1(2)\end{pmatrix}&&\text{rows by columns}\\ &=\begin{pmatrix}2&2\\0&2\end{pmatrix}\\ \mathbf{C}\mathbf{A}&=\begin{pmatrix}2(1)+0(0)&2(1)+0(1)\\0(1)+2(0)&0(1)+2(1)\end{pmatrix}&&\text{reverse the factors}\\ &=\begin{pmatrix}2&2\\0&2\end{pmatrix} \end{aligned}

Why this step? Here C=2I\mathbf{C}=2\mathbf{I}, so multiplication on either side simply doubles every entry of A\mathbf{A}.

Answer. AC=CA\mathbf{A}\mathbf{C}=\mathbf{C}\mathbf{A}, so this pair commutes.

Check. Both products equal 2A2\mathbf{A}, as the identity rule predicts.

The distributive rules also work, with order preserved: A(B+C)=AB+AC\mathbf{A}(\mathbf{B}+\mathbf{C})=\mathbf{A}\mathbf{B}+\mathbf{A}\mathbf{C} and (B+C)A=BA+CA(\mathbf{B}+\mathbf{C})\mathbf{A}=\mathbf{B}\mathbf{A}+\mathbf{C}\mathbf{A}. These are not in the formula booklet. In particular, expanding (A+B)2(\mathbf{A}+\mathbf{B})^2 gives separate middle terms AB+BA\mathbf{A}\mathbf{B}+\mathbf{B}\mathbf{A}, which cannot generally be combined into 2AB2\mathbf{A}\mathbf{B}.

Exam tip

For “Determine whether the matrices commute”, show both products and write a conclusion comparing them. Calculating two matrices without saying whether they agree leaves the reasoning unfinished.

The following pair changes the off-diagonal entry. Use equality of the complete products to find the exceptional value.

Watch out

Wrong: associativity gives AB=BA\mathbf{A}\mathbf{B}=\mathbf{B}\mathbf{A}. Associativity changes brackets, not factor order. For the first pair, the correct products have upper-right entries 11 and 22, so AB≠BA\mathbf{A}\mathbf{B}\ne\mathbf{B}\mathbf{A}.

Keep the factor order while computing both products below.

Quick Recap

  • Equal matrices have the same order and equal corresponding entries; add, subtract and scale entry by entry.
  • In a product, inner dimensions must match; each answer entry is a row-by-column total.
  • Appropriate identity matrices leave a matrix unchanged; a zero factor makes a defined product zero.
  • Matrix multiplication is associative, so brackets may move. It is not generally commutative, so factor order matters.

Yes: two non-zero matrices can have zero product, as (1000)(0001)=0\begin{pmatrix}1&0\\0&0\end{pmatrix}\begin{pmatrix}0&0\\0&1\end{pmatrix}=\mathbf{0} demonstrates.