Lecture 12 · Week 3· 20:15
The matrix-vector product
Ax as a combination of columns, Ax = b revisited.
Saved in this browser only. No account needed.
TranscriptThe full text of the lecture. Click any sentence to play the video from there.
Today: the product A x
Welcome back. In the very first lecture, we solved the system two x minus y equals one, and x plus y equals five, in three ways: by rows, by columns, and in a compact form, A x equals b. We promised to explain that last form properly. Today we keep that promise. Here is the compact form again. The matrix A holds the coefficients. The vector x holds the unknowns. And the vector b holds the right hand side. But what does it mean to multiply a matrix by a vector? Today we define this product, the matrix vector product, and we learn two ways to compute it.
Then we prove two rules that make it behave like ordinary multiplication, and we use them to look at systems of equations again, with new eyes. By the end, A x equals b will be more than shorthand. It will be a statement we can reason with.
A x is a combination of the columns
Recall the column picture. The system says that x times the first column, plus y times the second column, equals the right hand side. The unknowns are the weights of a linear combination of the columns. This is exactly what we take as the definition. Let A be a matrix with m rows and n columns, with entries in a field F. Call its columns a one, a two, up to a n. Each column has m entries, so it lies in F m. Let x be a vector in F n, with entries x one up to x n. Then the product A x is the linear combination of the columns of A, with the entries of x as weights: x one times a one, plus x two times a two, and so on, up to x n times a n.
In words: the first entry of x tells us how much of the first column to take, the second entry how much of the second column, and so on. Then we add. Let's compute one. Take A with rows (two, minus one) and (one, one), so its columns are (two, one) and (minus one, one). And take x equal to (two, three). By the definition, A x is two times the first column, plus three times the second column.
Scaling first. Two times the vector (two, one) is the vector (four, two). Three times the vector (minus one, one) is the vector (minus three, three). Now we add, one coordinate at a time. In the first coordinate, four plus minus three is one. In the second coordinate, two plus three is five. So A x is (one, five). That is exactly the right hand side, so x equal to (two, three) solves the system, just as we found in lecture one.
In the plane, we walk two copies of the first column, then three copies of the second, and we land on the point (one, five).
Sizes, and a wider matrix
The definition needs one weight for each column. So A x makes sense only when x has as many entries as A has columns. And the result is a combination of columns, each with m entries. So A x has one entry for each row of A. A matrix with m rows and n columns takes a vector in F n, and returns a vector in F m. A quick way to remember it: m by n, times n by one, gives m by one. In this product, the n by one matrix, a matrix with a single column, is just our vector x. Later in the course, we multiply matrices of other sizes too, and the same rule holds: the inner sizes must match, and the outer sizes give the size of the result.
Here is a wider example. This A has two rows and three columns. Its first row is (one, two, minus one), and its second row is (zero, one, three). So its first column is (one, zero), its second column is (two, one), and its third column is (minus one, three). We take x equal to (three, one, two). It has three entries, one for each column, so the product is defined, and the result will have two entries. By the definition, A x is three times the first column, plus one times the second, plus two times the third. That is (three, zero), plus (two, one), plus (minus two, six).
In the first coordinate, three plus two plus minus two is three. In the second coordinate, zero plus one plus six is seven. So A x is (three, seven). So this matrix takes a vector in R three, and returns a vector in R two. But a vector with only two entries cannot be multiplied by this A: there are three columns, and only two weights. One special choice of x is worth noticing. If x has a one in position two, and zeros elsewhere, then A x takes none of the first column, all of the second, and none of the third. So A x is exactly the second column of A.
In the same way, multiplying by the vector with a single one in position j picks out column j. Keep this in mind. It will be the key to lecture thirteen.
The row rule
The definition works with columns. But when we compute by hand, there is a faster route, which works with rows. Look at the first entry of A x. Every column contributes its first entry, times its weight. So the first entry is a one one times x one, plus a one two times x two, and so on, up to a one n times x n. Those numbers, a one one up to a one n, are exactly the first row of A. So the first entry of A x is the first row of A, multiplied entry by entry with x, and added up.
The same holds for every row. Entry i of A x is row i of A, times x, entry by entry and added up. This is called the row rule. With the dot product from lecture four, it says that entry i is row i, dotted with x. The proof is the argument we just made. Vectors are added and scaled entry by entry, so entry i of the combination is x one times entry i of a one, plus and so on. Entry i of the column a j is a i j. And multiplication in a field is commutative, so we may write each product with the matrix entry first. Let's redo our wider example by rows. A has rows (one, two, minus one) and (zero, one, three), and x is (three, one, two).
First row. One times three, plus two times one, plus minus one times two. That is three plus two minus two, which is three. Second row. Zero times three, plus one times one, plus three times two. That is zero plus one plus six, which is seven. We get (three, seven) again, as we must. The same six products appear both times, only grouped differently: by columns before, and by rows now.
So the two ways of computing match the two pictures of a system. The column rule is the column picture: a combination of columns. The row rule is the row picture: one equation for each row. In practice, use the row rule to compute, since it gives one entry at a time. And use the column rule to understand, since it tells you what A x means.
The identity matrix
One matrix deserves a name of its own. The identity matrix, I n, is the n by n matrix with ones on the diagonal, from top left to bottom right, and zeros everywhere else. Its columns are the vectors with a single one: in position one, then position two, and so on. Multiply it by any x. By the column rule, we get x one times the first column, plus x two times the second, plus x three times the third. Each column puts its weight in its own position. So the first entry is x one, the second is x two, and the third is x three.
So I x equals x, for every x. The identity matrix does to vectors what the number one does to numbers: nothing at all.
Linearity
Now the two rules that make the product so useful. For every m by n matrix A, all vectors u and v in F n, and every scalar c: A, times u plus v, equals A u plus A v. And A, times c u, equals c times A u. The first rule says that A respects addition. The second says that A respects scaling. Together, they are called linearity. Before the proof, a quick check with numbers. Take our two by two matrix A, with u equal to (one, zero) and v equal to (one, three). Then u plus v is the vector (two, three), and from our first example at the start of the lesson, we already know that A times the vector (two, three) is the vector (one, five).
On the other side, A u is one times the first column, which is (two, one). And A v is the first column plus three times the second, which is (minus one, four). Adding, two plus minus one is one, and one plus four is five. Both sides give (one, five). Now the proof. It uses only the rules of vector algebra from lecture two. It is short but dense, so take it slowly, and feel free to pause or rewatch it. Start with A, times u plus v. The entries of u plus v are u one plus v one, up to u n plus v n. So by the definition, A, times u plus v, is u one plus v one, times a one, plus and so on, up to u n plus v n, times a n.
By the distributive law over scalar addition, each term splits in two: u one a one, plus v one a one, and so on. Now we regroup. Addition of vectors is commutative and associative, so we may collect all the u terms first, and all the v terms after them. The u terms add up to A u, and the v terms add up to A v. So A, times u plus v, equals A u plus A v.
The second rule is proved the same way. A, times c u, is c u one times a one, plus and so on. By the rule for scaling twice, c u one, times a one, equals c, times u one a one. And by the distributive law over vector addition, we can take c out of the whole sum. What is left is c times A u. Combining the two rules, A respects every linear combination: A, times c u plus d v, equals c A u plus d A v. These two rules may look like simple bookkeeping. But they are the heart of the course. A function with these two properties is called a linear transformation, and in lecture thirteen we will see that every matrix defines one.
A x = b revisited
Now let's revisit systems of equations. Take a system of m linear equations in n unknowns. Its coefficient matrix A has a column for each unknown, and the vector b collects the right hand sides. We now have three ways to write the same system. As m separate equations. As one vector equation: x one a one, plus and so on, up to x n a n, equals b. And as one matrix equation: A x equals b. These three have exactly the same solutions. The vector equation and the matrix equation are the same by definition, since A x is that combination of columns. And by the row rule, entry i of A x equals b i is exactly equation i of the system.
So from now on, we write a system simply as A x equals b, and we solve it, as before, by row reducing the augmented matrix. Let's test this on the system from lecture eight. Its coefficient matrix has first row (one, two, one), second row (two, five, three), and third row (minus one, zero, two), and b is the vector (three, eight, four). Elimination gave the solution x equal to (two, minus one, three). We check A x by the row rule. First row: two, minus two, plus three, is three. Second row: four, minus five, plus nine, is eight. Third row: minus two, plus zero, plus six, is four. So A x is (three, eight, four), which is b.
And the column rule gives the meaning: two times the first column, minus the second, plus three times the third, lands exactly on b. The matrix form also gives a short way to say when a system can be solved. A x equals b has a solution exactly when b is a combination of the columns of A, that is, when b lies in the span of the columns.
Solvable for every b
Often we want more than one right hand side. When does A x equals b have a solution for every b in F m? Here is the theorem. For an m by n matrix A, these statements are equivalent. First, A x equals b has a solution for every b in F m. Second, every b in F m is a linear combination of the columns of A. Third, the columns of A span F m. And fourth, an echelon form of A has a pivot in every row. The first three say the same thing in different words, by what we just saw and by the definition of span. The real content is the link with pivots. This part of the proof is demanding, so take it slowly, and pause or rewatch it if you need to.
Suppose first that an echelon form U of A has a pivot in every row. Take any b, and row reduce the augmented matrix. The same row operations that turn A into U turn b into some new right hand side d. Every row of U has a pivot, so no row can read zero equals a nonzero number. By the existence theorem of lecture ten, the system is consistent. So there is a solution, for every b. Now for the other direction, suppose instead that some row of U has no pivot. Then the last row of U is all zeros. Choose d to be the vector with a one in its last entry, and zeros elsewhere. The system with augmented matrix U and d has a last row that says zero equals one, so it has no solution.
Every row operation can be undone. So we run the operations backwards, starting from U and d. This turns U back into A, and turns d into some vector b. Row operations keep the solutions, so A x equals this b has no solution either. So not every b can be reached, and the proof is complete. Let's see the theorem at work. Our two by two matrix has rows (two, minus one) and (one, one). We swap the rows, then replace row two by row two minus two times row one. Two minus two is zero, and minus one minus two is minus three. The echelon form has a pivot in both rows. So every b in the plane is a combination of the two columns. In the column picture, the two columns point in different directions, so their combinations cover the whole plane.
Now a matrix that fails. Let A have rows (one, two) and (two, four). We replace row two by row two minus two times row one. Two minus two is zero, and four minus four is zero. The second row has no pivot. So not every b can be reached. The column picture shows why: the second column, (two, four), is twice the first, (one, two). Every combination of them lies on one line through the origin, and a vector off that line, such as (one, three), is never reached. One more consequence. Each pivot sits in its own column, so there are never more pivots than columns. If A has more rows than columns, some row has no pivot. For example, two vectors can never span R three.
The shape of all solutions
Finally, linearity gives a new view of something from lecture ten: the shape of the set of all solutions. Start with the simplest right hand side, b equal to zero. Recall that a system A x equals zero is called homogeneous. It always has the trivial solution, x equal to zero, since A times the zero vector is zero times every column, added up, which is the zero vector. In lecture ten we proved the structure theorem. In matrix language, it says: if p is one solution of A x equals b, then the solutions of A x equals b are exactly the vectors p plus h, where A h equals zero.
With linearity, the proof takes two short checks. First, if A h is zero, then A, times p plus h, equals A p plus A h, which is b plus zero, which is b. So p plus h is a solution. Second, let x be any solution, and set h equal to x minus p. Then A h equals A x minus A p, which is b minus b, which is zero. So h solves the homogeneous system, and x equals p plus h. Let's see it for the matrix that failed a moment ago, with rows (one, two) and (two, four). Its columns reach only the line through (one, two), and this line contains b equal to (three, six). One solution is p equal to (three, zero): in the first row, three plus zero is three, and in the second, six plus zero is six.
The homogeneous system says x plus two y equals zero, and two x plus four y equals zero, which is the same equation twice. So the solution set of the homogeneous system is a line through the origin: all the multiples of (minus two, one). For our own system, every solution is (three, zero) plus t times (minus two, one). So its solution set is the line of homogeneous solutions, shifted so that it passes through p. For example, t equal to one gives (one, one), and indeed one plus two is three, and two plus four is six. In fact every point on this line is a solution: wherever we take x on it, A x is (three, six). So once there is one solution, all the others come from the homogeneous system. In particular, a solution of A x equals b is the only one exactly when the homogeneous system has only the trivial solution.
By the elimination test of the last lecture, that happens exactly when the columns of A are linearly independent, that is, when an echelon form of A has a pivot in every column. Compare this with a pivot in every row, which we needed to reach every b.
Summary
Let's summarise. The product A x is the combination of the columns of A, with the entries of x as weights. It is defined when x has one entry for each column, and it has one entry for each row. To compute it, use the row rule: entry i of A x is row i of A, times x, entry by entry and added up. The product is linear: A, times u plus v, is A u plus A v, and A, times c u, is c times A u. And the identity matrix leaves every vector unchanged.
A system of equations is a single equation, A x equals b. It is solvable exactly when b is in the span of the columns, and it is solvable for every b exactly when an echelon form of A has a pivot in every row. And if p is one solution, every solution is p plus a solution of the homogeneous system. Before the next lecture, read section three point one of the course book, try the problems on the matrix vector product on sheet three, and do the lecture check on this lecture's page at Open Semester dot com. Next time, we stop thinking of A as a table of numbers, and start thinking of it as a machine that moves vectors: a linear transformation. See you there.
In this lecture
Materials
Check yourself
3 questions, from warm-up to stretch
Work each one out on paper, type your answer and press Check. Stuck? Open a hint; the worked solution is there when you need it.
- Question 1 of 3 Warm-up
Let and . Compute as a combination of the columns of .
Hint 1 of 2
: the entries of are the weights, and the columns of are the vectors.
Hint 2 of 2
. Scale each column, then add entry by entry.
Worked solution
- The columns of are and , and the weights are , .
- .
- Adding entry by entry: .
- Question 2 of 3 Core
Let and . How many entries does have? Compute them with the row rule.
Hint 1 of 2
is and is in : . Then .
Hint 2 of 2
Row of is , so . Do the same with row , .
Worked solution
- is , so is in : it has entries, one for each row of .
- .
- .
- So . The column rule gives the same: .
- Question 3 of 3 Stretch
Let . Does have a solution for every ? For which number does have a solution?
Hint 1 of 2
By Theorem 3.1.9, has a solution for every exactly when has a pivot in every row. Row reduce .
Hint 2 of 2
turns into . Do the same to and read the last row.
Worked solution
- gives . Row has no pivot, so by Theorem 3.1.9 there is some with no solution: the answer is no.
- The same step on gives .
- The last row reads , so there is a solution exactly when .
- Check: gives . The columns are multiples of , so only reaches vectors on that line.
How did it go?