Scientia sine finibus

Linear Algebra / Unit 3, Matrices / Topic 3.1

Units and Topics

Unit 3. Matrices

3.1 Matrices as Maps

A matrix is a table of numbers. This topic shows that a matrix is also a rule that takes a vector and gives back a new vector. Seen this way, a matrix moves the whole plane: it can stretch the plane, turn it, flip it, or slant it.

You need Topics 1.1 and 2.1 for this topic.

1. A Matrix and Its Columns

A matrix is a rectangular table of numbers. This matrix has 2 rows and 2 columns:

A = 2101

Read the matrix by its columns. The first column is the vector (2, 0), and the second column is the vector (1, 1). In this topic the columns matter more than the rows.

2. A Matrix Times a Vector

To multiply a matrix by a vector, use the components of the vector as the coefficients of a linear combination of the columns.

2101 32 = 3 20 + 2 113 times the first column plus 2 times the second column2101 32 = 6 + 20 + 2add the matching components2101 32 = 82the result

The first component of the vector multiplies the first column. The second component multiplies the second column. Then the results are added.

There is also a quick rule for each entry of the answer. Take one row of the matrix and form its dot product with the vector:

abcd xy = ax + bycx + dy

For the example, the top entry is (2)(3) + (1)(2) = 8, and the bottom entry is (0)(3) + (1)(2) = 2. Both rules give the same answer.

This product is the column picture from Topic 2.1. The system 2x + y = 8 and y = 2 is the single equation Ax = b, with x = (x, y) and b = (8, 2). A system of linear equations is one matrix equation.

3. A Matrix as a Map

The product Ax takes a vector x and gives a new vector. A rule that takes an input and gives an output is a function. A matrix is a function whose inputs and outputs are vectors. Such a function is also called a map or a transformation.

To find what a map does, find where the map sends the two basic vectors from Topic 1.1, i = (1, 0) and j = (0, 1).

2101 10 = 20 2101 01 = 11

The first column of a matrix is where the map sends i. The second column is where the map sends j. A matrix is a record of where the two basic vectors go.

This is enough to know where all other vectors go. The vector (3, 2) is 3i + 2j, and the map sends it to 3 times the first column plus 2 times the second column. The map moves the grid of the plane along with i and j.

Try it: a matrix moves the plane

The blue arrow is where the map sends i, and the red arrow is where the map sends j. Drag their tips to change the matrix, or choose a map below. The purple arrow is an input vector x, and the green arrow is the output Ax. Press Play to watch the plane move from its starting position.

4. Some Useful Maps

MapMatrixWhat it does
Identity1001Leaves each vector where it is
Stretch2001Doubles the x component
Rotation by 90°0−110Turns each vector counterclockwise by 90°
Reflection100−1Flips the plane across the x axis
Shear1101Slides each point sideways by its height
Projection1000Drops each point straight onto the x axis

To write the matrix for a map, decide where i goes and where j goes, and write those two vectors as the columns. For a rotation by 90° counterclockwise, i = (1, 0) turns to (0, 1), and j = (0, 1) turns to (−1, 0). These are the two columns of the rotation matrix in the table.

Rotation by any angle

A rotation by an angle θ sends i to (cos θ, sin θ) and sends j to (−sin θ, cos θ). The matrix is

cos θ−sin θsin θcos θ

5. What “Linear” Means

The maps that come from matrices are called linear maps. A linear map follows two rules, for all vectors u and v and all scalars c:

A(u + v) = Au + Av A(cu) = c(Au)

The first rule says that adding first and then mapping gives the same result as mapping first and then adding. The second rule says the same for scaling. These are the two operations from Topic 1.1, so a linear map is a map that respects linear combinations.

In the drawing, the two rules have visible consequences.

  • The origin does not move.
  • Straight lines stay straight.
  • Grid lines that were parallel and evenly spaced stay parallel and evenly spaced.

A map that bends lines, or that moves the origin, is not linear and cannot be written as a matrix times a vector.

Common Mistakes

  • Reading the rows as the images of i and j. The images of the basic vectors are the columns of the matrix.
  • Multiplying entry by entry. The product of a matrix and a vector is a linear combination of the columns, not a list of separate products.
  • Writing the vector on the left. In Ax, the matrix is written first and the vector second.
  • Thinking that a shift of the whole plane is a linear map. A shift moves the origin, so it is not linear.

Summary

TermMeaning
MatrixA rectangular table of numbers
AxThe linear combination of the columns of A, with the components of x as the coefficients
Columns of AWhere the map sends i and j
Linear mapA map that respects addition and scalar multiplication

Practice

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

1. Calculate 1234 21.

2(1, 3) + 1(2, 4) = (2 + 2, 6 + 4)2 times the first column plus 1 times the second column2(1, 3) + 1(2, 4) = (4, 10)the result

2. A map sends i to (3, 0) and sends j to (0, 2). Write its matrix and describe the map.

The columns are (3, 0) and (0, 2), so the matrix is 3002.

The map stretches the plane by a factor of 3 in the x direction and by a factor of 2 in the y direction.

3. Where does the shear 1101 send the vector (2, 3)?

2(1, 0) + 3(1, 1) = (2 + 3, 0 + 3)2 times the first column plus 3 times the second column2(1, 0) + 3(1, 1) = (5, 3)the result

The height stays 3, and the point slides 3 units to the right.

4. Write the matrix that reflects the plane across the y axis.

The vector i = (1, 0) goes to (−1, 0), and the vector j = (0, 1) stays at (0, 1). The matrix is −1001.

5. Write the system 2x − y = 3 and x + 4y = 6 as one matrix equation.

2−114 xy = 36.

6. Is the map that sends (x, y) to (x + 1, y) a linear map?

No. It sends the origin (0, 0) to (1, 0). A linear map leaves the origin where it is.

Python Practice

Step 1. Store a matrix

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. Each row goes inside its own square brackets, and all of the rows go inside one more pair of square brackets. The code below stores the matrix A from Part 1 of this topic. Its first row is 2, 1 and its second row is 0, 1.

Python

Python prints the two rows on two lines. Notice that the matrix is typed by its rows, although this topic reads a matrix by its columns. The first column of this matrix is (2, 0): the first number of the first row, and the first number of the second row.

Step 2. Multiply a matrix by a vector

The @ sign multiplies a matrix by a vector. The code below calculates the product from Part 2 of this topic.

Python

The result is [8 2], which agrees with Part 2.

Do not use the * sign for this product. With a matrix and a vector, the * sign multiplies matching entries, which is a different operation.

Now change the vector so that the code prints the first column of A. Part 3 of this topic shows which vector to use.

Python

Step 3. Build a matrix from what it does

From Part 3, the columns of a matrix are the vectors where (1, 0) and (0, 1) land. A rotation by 90 degrees counterclockwise moves (1, 0) to (0, 1), and it moves (0, 1) to (−1, 0).

In the next box, replace the zeros so that R is the matrix of this rotation. The first column of the matrix should be (0, 1), and the second column should be (−1, 0). Remember that a matrix is typed by its rows. The last line applies the rotation to the vector (2, 1).

Python

The rotation moves (2, 1) to (−1, 2). You can check that these two vectors are perpendicular, because their dot product is (2)(−1) + (1)(2) = 0.

Step 4. Rotate by any angle

Part 4 gives the matrix for a rotation by any angle θ. Python calculates a cosine with np.cos and a sine with np.sin. Both of them need the angle in radians, so the code first changes the angle from degrees to radians with np.radians.

Python

The result is about [1.73 1.], which is the vector (2, 0) turned by 30 degrees.

Now change the angle so that the vector (2, 0) is turned by 180 degrees.

Python

The second component is printed as a number such as 2.4492936e-16. The ending e-16 means that the number is multiplied by 10⁻¹⁶. This is a very small rounding error, and the value is 0.

Step 5. Test the two rules of a linear map

Part 5 states that a matrix map satisfies A(u + v) = Au + Av. The code below calculates the two sides of this equation for one pair of vectors.

Python

Both lines print [9 1]. Change u and v to any other vectors and run the code again. The two lines agree each time.

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 = 2103. Calculate A times the vector (1, 2).

2. A linear map sends (1, 0) to (2, 5) and sends (0, 1) to (−1, 3). Write the four entries of its matrix.

3. Which matrix rotates each vector counterclockwise by 90°?

4. What does the matrix 100−1 do to the plane?

5. A matrix A sends (1, 0) to (3, 1) and sends (0, 1) to (1, 2). Find A times the vector (2, −1).

Next: Topic 3.2, Matrix Multiplication and Inverses