Linear Algebra / Unit 3, Matrices / Topic 3.2
Unit 3. Matrices
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.
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.
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−110Each 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 + dsNow 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−111This 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.
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 = AThe 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⁻¹ = IFor 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.
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 AThe number ad − bc is called the determinant of the matrix. It is written det A.
det abcd = ad − bcThe 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.
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.
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⁻¹bFor 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 componentsThe solution is x = 2 and y = 1. Check:
2(2) + 1 = 5the first equation2 + 1 = 3the second equationFor 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.
| Term | Meaning |
|---|---|
| AB | The single map that does B first and A second |
| Identity I | The map that leaves each vector where it is |
| Inverse A⁻¹ | The map that undoes A |
| Determinant | ad − bc, the factor by which the map changes areas |
Work each problem on paper first. Then open the answer to check your work.
first column = 3(1, 0) + 1(2, 1) = (5, 1)second column = 0(1, 0) + 2(2, 1) = (4, 2)
The product is 5412.
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.
ad − bc = (4)(5) − (3)(2)the formula for the determinantad − bc = 20 − 6 = 14
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
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.
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 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.
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.
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.
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.
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.
The columns of AB are A times the columns of B. A(3, 1) = (5, 1) and A(0, 2) = (4, 2).
2. Find the determinant of 3214.
ad − bc = (3)(4) − (2)(1)the determinant of a 2 by 2 matrixad − bc = 12 − 2 = 10
3. Find the inverse of 2153.
ad − bc = (2)(3) − (1)(5) = 1the determinantSwap the two entries on the main diagonal, change the signs of the other two entries, and divide by the determinant.
4. Which of these matrices has no inverse?
A matrix has no inverse when its determinant is 0. For the last matrix, (1)(4) − (2)(2) = 0. The other three determinants are −2, 6, and −1.
5. The product AB is the matrix of one map. Which map is it?
In ABx, the matrix B acts on x first, and then A acts on the result. In general, the product BA is a different map.