Scientia sine finibus

Linear Algebra / Unit 3, Matrices / Topic 3.2

Units and Topics

Unit 3. Matrices

3.2 Matrix Multiplication and Inverses

This topic shows how to combine two maps into one map, which is what matrix multiplication does. It also shows how to undo a map with an inverse matrix, and how one number, the determinant, tells whether a map can be undone.

You need Topics 2.1 and 3.1 for this topic.

1. Doing One Map After Another

Suppose a vector x is first sent through a map B, and the result is then sent through a map A. The final result is A(Bx). The two maps together act as one map, and that map has its own matrix. This matrix is called the product AB.

(AB)x = A(Bx)

Read a product of matrices from right to left. In AB, the map B acts first, because B is next to the vector. The map A acts second.

2. How to Multiply Two Matrices

From Topic 3.1, the columns of a matrix are where the map sends i and j. The map B sends i to the first column of B. The map A then acts on that column. So the first column of AB is A times the first column of B, and the second column of AB is A times the second column of B.

For example, let A be the shear and B be the rotation by 90°:

A = 1101 B = 0−110 first column of AB = 0(1, 0) + 1(1, 1) = (1, 1)A times (0, 1), the first column of Bsecond column of AB = −1(1, 0) + 0(1, 1) = (−1, 0)A times (−1, 0), the second column of B AB = 1−110

The entry rule

Each entry of AB is also the dot product of a row of A with a column of B. The entry in row 1 and column 2 uses row 1 of A and column 2 of B.

abcd pqrs = ap + braq + bscp + drcq + ds

3. The Order Matters

Now multiply the same two matrices in the other order. The columns of BA are B times the columns of A.

BA = 0−110 1101 = 0−111

This is not the same matrix as AB. Turning the plane and then shearing it gives a different result from shearing it and then turning it.

For numbers, 3 × 5 and 5 × 3 are equal. For matrices, AB and BA are usually different. The order of a matrix product cannot be changed.

Try it: the order of two maps

Choose two maps. The green shape shows the letter F after B and then A. The blue outline shows the letter F after A and then B. The gray shape is the starting position.

Some pairs of maps do give the same result in both orders. A map that shrinks the whole plane by one half gives the same result in either order with any other map. Try it in the drawing.

4. The Identity and the Inverse

The identity matrix leaves each vector where it is. It plays the role that the number 1 plays in ordinary multiplication.

I = 1001 Ix = x AI = IA = A

The inverse of a map A is the map that undoes A. It is written A⁻¹. Doing A and then A⁻¹ returns each vector to where it started:

A⁻¹A = I AA⁻¹ = I

For example, the inverse of a rotation by 90° counterclockwise is a rotation by 90° clockwise. The inverse of a stretch by a factor of 2 is a shrink by a factor of one half.

The formula for a 2 by 2 matrix

A = abcd A⁻¹ = 1/(ad − bc) d−b−ca

Swap the two entries on the main diagonal, change the signs of the other two entries, and divide by ad − bc.

For A = 2111:

ad − bc = (2)(1) − (1)(1) = 1the number in the formulaA⁻¹ = 1−1−12swap a and d, change the signs of b and c, and divide by 1first column of A⁻¹A = 2(1, −1) + 1(−1, 2) = (1, 0)the check, with the first column of Asecond column of A⁻¹A = 1(1, −1) + 1(−1, 2) = (0, 1)the check, with the second column of A

5. The Determinant

The number ad − bc is called the determinant of the matrix. It is written det A.

det abcd = ad − bc

The determinant has a meaning in the picture. A map sends the unit square, with sides i and j, to a parallelogram whose sides are the two columns. The area of that parallelogram is the size of the determinant. A determinant of 3 means that the map multiplies all areas by 3. A negative determinant means that the map also flips the plane over.

Try it: the determinant and the inverse

Drag the tips of the blue and red arrows, which are the two columns of the matrix. The shaded parallelogram is where the map sends the unit square.

When there is no inverse

If the determinant is 0, the formula would divide by 0, so the matrix has no inverse. In the picture, the two columns are on the same line, and the parallelogram has no area. The map flattens the whole plane onto a line. Many different vectors land on the same point, so the map cannot be undone.

This is the same situation that appeared in earlier topics.

  • Topic 1.1: two vectors on the same line span only a line.
  • Topic 2.1: two parallel lines give no solution or infinitely many solutions.
  • This topic: a determinant of 0 means that the matrix has no inverse.

6. Solving a System with the Inverse

From Topic 3.1, a system of linear equations is one matrix equation, Ax = b. If A has an inverse, multiply both sides by A⁻¹ on the left:

A⁻¹Ax = A⁻¹b so x = A⁻¹b

For the system 2x + y = 5 and x + y = 3, the matrix is the A from the example above, and

x = A⁻¹bthe solutionx = 1−1−12 53the inverse from the example abovex = 5 1−1 + 3 −125 times the first column plus 3 times the second columnx = 21add the matching components

The solution is x = 2 and y = 1. Check:

2(2) + 1 = 5the first equation2 + 1 = 3the second equation

For a single system, elimination is usually faster than finding an inverse. The inverse is useful when the same matrix must be used with many different right sides.

Common Mistakes

  • Changing the order of a product. AB and BA are usually different matrices.
  • Reading AB from left to right. In AB, the map B acts first.
  • Multiplying entry by entry. The product of two matrices is not found by multiplying matching entries.
  • Forgetting to divide by the determinant in the inverse formula.
  • Calculating the determinant as ad + bc. The correct expression is ad − bc.
  • Looking for the inverse of a matrix whose determinant is 0. That matrix has no inverse.

Summary

TermMeaning
ABThe single map that does B first and A second
Identity IThe map that leaves each vector where it is
Inverse A⁻¹The map that undoes A
Determinantad − bc, the factor by which the map changes areas

Practice

Work each problem on paper first. Then open the answer to check your work.

1. Calculate 1201 3012.

first column = 3(1, 0) + 1(2, 1) = (5, 1)second column = 0(1, 0) + 2(2, 1) = (4, 2)

The product is 5412.

2. Calculate the same two matrices in the other order: 3012 1201.

first column = 1(3, 1) + 0(0, 2) = (3, 1)second column = 2(3, 1) + 1(0, 2) = (6, 4)

The product is 3614, which is different from the answer to Problem 1.

3. Calculate the determinant of 4325.

ad − bc = (4)(5) − (3)(2)the formula for the determinantad − bc = 20 − 6 = 14

4. Find the inverse of 3152.

ad − bc = (3)(2) − (1)(5) = 1the determinantA⁻¹ = 2−1−53swap the diagonal entries, change the signs of the other two entries, and divide by 1

5. Does 2412 have an inverse?

No.

ad − bc = (2)(2) − (4)(1) = 0the determinant

The second column is 2 times the first column, so the map flattens the plane onto a line.

6. Use the inverse from Problem 4 to solve 3x + y = 4 and 5x + 2y = 7.

x = A⁻¹bthe solutionx = 4(2, −5) + 7(−1, 3)4 times the first column of A⁻¹ plus 7 times the second columnx = (8 − 7, −20 + 21) = (1, 1)add the matching components3(1) + 1 = 4the check in the first equation5(1) + 2(1) = 7the check in the second equation

Python Practice

Step 1. Multiply two matrices

Python reads the code one line at a time, from the top to the bottom. The equals sign stores the value on its right under the name on its left, and print shows a result. The name np stands for NumPy, the part of Python that works with vectors and matrices. A matrix is typed one row at a time, with each row inside its own square brackets.

The @ sign multiplies two matrices. The code below calculates the product AB from Part 2 of this topic.

Python

The result has the rows 1, −1 and 1, 0, which agrees with Part 2.

Now change the last line so that it prints BA, the product in the other order.

Python

The two products are different matrices, as Part 3 explains.

Step 2. Calculate a determinant

The instruction np.linalg.det calculates the determinant of a matrix.

Python

The result is very close to 14, because (4)(5) − (3)(2) = 14. Python may print a number such as 14.000000000000004. The difference is a very small rounding error.

Now change the matrix to the one with the rows 2, 4 and 1, 2, and find its determinant.

Python

The determinant is 0, so this matrix has no inverse.

Step 3. Find an inverse

The instruction np.linalg.inv calculates the inverse of a matrix. The code below finds the inverse of the matrix with the rows 2, 1 and 1, 1, and stores it under the name Ainv. The last line multiplies the matrix by its inverse.

Python

The inverse has the rows 1, −1 and −1, 2. The product of the matrix and its inverse is the identity matrix, with the rows 1, 0 and 0, 1.

Now find the inverse of the matrix with the rows 3, 1 and 5, 2. Compare the result with the answer to Practice Problem 4.

Python

Python may print 2 as 2. or as 1.99999999. The difference is a very small rounding error.

Step 4. Solve a system with the inverse

Part 6 of this topic solves the system 2x + y = 5 and x + y = 3 with the equation x = A⁻¹b. In the next box, the last two lines are ready. Replace the zeros in the first two lines with the matrix of coefficients and the vector of right sides.

Python

The solution is x = 2 and y = 1, as in Part 6.

Quiz

This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.

Choose how your answers are checked

1. Let A = 1201 and B = 3012. Calculate the product AB.

2. Find the determinant of 3214.

3. Find the inverse of 2153.

4. Which of these matrices has no inverse?

5. The product AB is the matrix of one map. Which map is it?

Next: Topic 3.3, The Transpose and Special Matrices