Get startedGet started for free

Matrix-Vector Operations

1. Matrix-Vector Operations

Data often needs to be transformed into new data for a number of reasons. In this lesson, we'll discuss how matrices can be used to turn vectors into other vectors via multiplication.

2. How Matrix-Vector Multiplication Works

A matrix with n columns and m rows can only be multiplied by a vector with n elements. The resulting vector then has m elements. Here A, a 3 by 2 matrix, is being multiplied by a 2-dimensional vector to make a 3-dimensional vector.

3. How Matrix-Vector Multiplication Works

The ith element of a matrix vector multiplication is the element formed by component-wise multiplication of the ith row of the given matrix by the given vector, and summing the results as shown here. Here the row 1, -1 is multiplied by the vector 1, 2 to make the element -1 of the resulting vector here.

4. How Matrix-Vector Multiplication Works

Matrix-vector multiplication uses the * symbol sandwiched between two % symbols. The * symbol alone produces what is called component-wise multiplication (and was discussed in a previous exercise), which is useful in practice but is not the multiplication we want in this case. Here we have the matrix A multiplied by the vector b makes the vector -1, 4, 0 on the left.

5. How Matrix-Vector Multiplication Works

Here's an example of a 2 by 3 matrix multiplied by a vector with three elements, making a vector with two elements.

6. How Matrix-Vector Multiplication Works

For demonstrations sake, it's good to see what matrix multiplication of A by b is actually doing for these small examples. Notice than each element of A multiplied by b is simply the product of a particular row of A (which is a vector) and b. Vector-vector multiplication in this way is called the dot product. For example, the first element of A times b is the dot product of the first row of A, coded with A[1,] and b, making 7. Same for the second element of A times b.

7. Matrix-Vector Multiplication Motivation

An example of where matrix-vector multiplication is used is the ranking of entities like sports players or teams. Here's an example of a table of outcomes in college football. This is a relatively-small example, with just five teams, yielding a matrix with 25 elements. In the exercises you'll deal with 12-team league, which yields a matrix with 144 (or 12 times 12) elements.

8. Matrix-Vector Multiplication Motivation

Such a table can be put into a matrix that has the pairwise interactions between all of the teams. For example, in this situation team JH (for John's Hopkins) has played four games, one each against the other four teams, hence the 4 in the 1,1 element of the matrix and a -1 in each of the remaining elements of the row and column in which it resides. rJH is the rating of John's Hopkins, which has outscored its opponents by 103 so far, the first element of the vector on the right-hand side. We know that who a team plays matters every bit as much as how a team plays, so we want the vector with the r_JH, r_F&M, etc. on the left to be an alteration of the vector of score differentials on the right that reflects the strength of each team given how they played against the teams they played against. The alteration is executed by matrix multiplication by the matrix (called the Massey Matrix) on the left.

9. Let's practice!

Now it's your turn.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.