Home
Matrix multiplication

Matrix multiplication

Matrix multiplication allows us to build multiplication tables in a concise way.

Here, we introduce at the technique of performing matrix multiplication, and we’ll look at some useful applications.

This introduction is for students who have had one year of algebra education, although some of the applications use the basic trigonometric functions {\sin} and {\cos.}

Index

Multiplication table

Here’s a multiplication table:

🞨 {10} {20 } {30 }
{2} {20} {40 } {60 }
{4} {40} {80 } {120}
{6} {60} {120} {180}
{8} {80} {160} {240}

Each entry in this table is the product of its row number and its column number.

This table contains {12} multiplication operations. In matrix mathematics, we can combine all of them together and write them as a single multiplication operation, like this:

{ \left[\hspace+2pt \begin{matrix} 2 \cr 4 \cr 6 \cr 8 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 10 &\hspace-5pt 20 &\hspace-5pt 30 \cr \end{matrix} \hspace+2pt\mathbf{]} \, = \left[\hspace+2pt \begin{matrix} 20 &\hspace-5pt 40 &\hspace-5pt 60 \cr 40 &\hspace-5pt 80 &\hspace-5pt 120 \cr 60 &\hspace-5pt 120 &\hspace-5pt 180 \cr 80 &\hspace-5pt 160 &\hspace-5pt 240 \cr \end{matrix} \hspace+2pt\right] }

This is called matrix multiplication. The left side of the equation consists of one matrix multiplied by another matrix, each of which is enclosed in square brackets. The right side of the equation is the matrix that results from the matrix multiplication.

The purpose of matrix multiplication is to specify the multiplication table in the most concise way possible, using only the row numbers and column numbers. It’s a notational shorthand that allows you to perform a large number of multiplications with just one matrix multiplication operation.

The result of the matrix multiplication is the internal body of the multiplication table, which is a rectangular grid of numbers showing the products of all the various row-column pairs.

As you look at the above equation, notice the following:

Matrix

A matrix is a rectangular grid of numbers. Here’s an example:

{ \left[\hspace+2pt \begin{matrix} 20 &\hspace-5pt 40 &\hspace-5pt 60 \cr 40 &\hspace-5pt 80 &\hspace-5pt 120 \cr 60 &\hspace-5pt 120 &\hspace-5pt 180 \cr 80 &\hspace-5pt 160 &\hspace-5pt 240 \cr \end{matrix} \hspace+2pt\right] }

Here are some facts about the matrix:

Let’s look again at the matrix multiplication from the previous section:

{ \left[\hspace+2pt \begin{matrix} 2 \cr 4 \cr 6 \cr 8 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 10 &\hspace-5pt 20 &\hspace-5pt 30 \cr \end{matrix} \hspace+2pt\mathbf{]} \, = \left[\hspace+2pt \begin{matrix} 20 &\hspace-5pt 40 &\hspace-5pt 60 \cr 40 &\hspace-5pt 80 &\hspace-5pt 120 \cr 60 &\hspace-5pt 120 &\hspace-5pt 180 \cr 80 &\hspace-5pt 160 &\hspace-5pt 240 \cr \end{matrix} \hspace+2pt\right] }

We could describe this equation as:

“a column matrix multiplied by a row matrix producing a {4 \mathord{\times} 3} matrix

Matrix multiplication: a simple case

Let’s perform the following matrix multiplication:

{ \left[\hspace+2pt \begin{matrix} 2 \cr 3 \cr 4 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 10 &\hspace-5pt 20 &\hspace-5pt 100 &\hspace-5pt 200 \cr \end{matrix} \hspace+2pt\mathbf{]} }

Here are the steps to do it:

  1. Move the second matrix physically upward, high enough to create space for the body of the multiplication table.

    So take this:

    { \left[\hspace+2pt \begin{matrix} 2 \cr 3 \cr 4 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 10 &\hspace-5pt 20 &\hspace-5pt 100 &\hspace-5pt 200 \cr \end{matrix} \hspace+2pt\mathbf{]} }

    and rewrite it like this:

    { \mathbf{[}\hspace+2pt \begin{matrix} 10 &\hspace-5pt 20 &\hspace-5pt 100 &\hspace-5pt 200 \cr \end{matrix} \hspace+2pt\mathbf{]} }
    { \left[\hspace+2pt \begin{matrix} 2 \cr 3 \cr 4 \cr \end{matrix} \hspace+2pt\right] } 🡅
  2. Create internal grid lines to hold the results:

    {10} {20} {100} {200}
    {2}
    {3}
    {4}
  3. Fill in the table with the products:

    🞨 {10} {20} {100} {200}
    {2} {20} {40} {200} {400}
    {3} {30} {60} {300} {600}
    {4} {40} {80} {400} {800}
  4. Write the internal body of the table as a matrix, producing the final result:

    { \left[\hspace+2pt \begin{matrix} 20 &\hspace-5pt 40 &\hspace-5pt 200 &\hspace-5pt 400 \cr 30 &\hspace-5pt 60 &\hspace-5pt 300 &\hspace-5pt 600 \cr 40 &\hspace-5pt 80 &\hspace-5pt 400 &\hspace-5pt 800 \cr \end{matrix} \hspace+2pt\right] }

  5. And now we can write the complete equation:

    { \left[\hspace+2pt \begin{matrix} 2 \cr 3 \cr 4 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 10 &\hspace-5pt 20 &\hspace-5pt 100 &\hspace-5pt 200 \cr \end{matrix} \hspace+2pt\mathbf{]} = \left[\hspace+2pt \begin{matrix} 20 &\hspace-5pt 40 &\hspace-5pt 200 &\hspace-5pt 400 \cr 30 &\hspace-5pt 60 &\hspace-5pt 300 &\hspace-5pt 600 \cr 40 &\hspace-5pt 80 &\hspace-5pt 400 &\hspace-5pt 800 \cr \end{matrix} \hspace+2pt\right] }

Notice the following:

The result has the same number of rows as the first matrix.
The result has the same number of columns as the second matrix.

Matrix multiplication: exercises

Here are some matrix multiplication exercises:

  1. { \left[\hspace+2pt \begin{matrix} 3 \cr 5 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 4 &\hspace-5pt 6 \cr \end{matrix} \hspace+2pt\mathbf{]} \ = }

  2. { \left[\hspace+2pt \begin{matrix} 8 \cr 1 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} a &\hspace-5pt b &\hspace-5pt c \cr \end{matrix} \hspace+2pt\mathbf{]} \ = }

  3. { \left[\hspace+2pt \begin{matrix} 1 \cr 2 \cr 3 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} 4 \cr \end{matrix} \hspace+2pt\mathbf{]} \ = }

Dot product

Matrix multiplication is also capable of performing an operation called the dot product.

The dot product is used to calculate the sum of proportionately-weighted values.

For example, if you have {4} ten-dollar bills, {3} five-dollar bills, and {6} one-dollar bills, you can calculate their total dollar value using the dot product like this:

{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 4 &\hfil\hspace-5pt 3 &\hfil\hspace-5pt 6 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 10 \cr \hfil 5 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] = \, \mathbf{[}\hspace+2pt \begin{matrix} \hfil 4 \mathord{\times} 10 + 3 \mathord{\times} 5 + 6 \mathord{\times} 1 \cr \end{matrix} \hspace+2pt\mathbf{]} = \, \mathbf{[}\hspace+2pt \begin{matrix} \hfil 40 + 15 + 6 \cr \end{matrix} \hspace+2pt\mathbf{]} = \, \mathbf{[}\hspace+2pt \begin{matrix} \hfil 61 \cr \end{matrix} \hspace+2pt\mathbf{]} }

to obtain a total value of {61} dollars.

More generally, we can write the dot product with variables:

{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil a &\hfil\hspace-5pt b &\hfil\hspace-5pt c \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \hfil z \cr \end{matrix} \hspace+2pt\right] = \, \mathbf{[}\hspace+2pt \begin{matrix} \hfil ax + by + cz \cr \end{matrix} \hspace+2pt\mathbf{]} }

and we can extend it to larger sizes, for any size {n \ge 1}:

{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil a_{\large{1}} &\hfil\hspace-5pt a_{\large{2}} &\hfil\hspace-5pt a_{\large{3}} &\hfil\hspace-5pt \cdots &\hfil\hspace-5pt a_{\large{n}} \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil b_{\large{1}} \cr \hfil b_{\large{2}} \cr \hfil b_{\large{3}} \cr \vdots \cr \hfil b_{\large{n}} \cr \end{matrix} \hspace+2pt\right] = \, \mathbf{[}\hspace+2pt \begin{matrix} \hfil a_{\large{1}} b_{\large{1}} + a_{\large{2}} b_{\large{2}} + a_{\large{3}} b_{\large{3}} + \cdots + a_{\large{n}} b_{\large{n}} \cr \end{matrix} \hspace+2pt\mathbf{]} }

Regardless of how large {n} is, the result is always a {1 \mathord{\times} 1} matrix that contains a single number.


In this section, we’re using matrix multiplication in a different way than we did in the previous sections. Here are the differences:

At first, it can be challenging to remember the rules about whether to orient a matrix horizontally or vertically. But in later sections, you will start to see clear and consistent patterns that will help you figure out the correct way to orient a matrix.

Dot product: exercises

Here are some dot product exercises:

  1. { \mathbf{[}\hspace+2pt \begin{matrix} 1 &\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} 3 \cr 4 \cr \end{matrix} \hspace+2pt\right] \ = }

  2. { \mathbf{[}\hspace+2pt \begin{matrix} 5 &\hspace-5pt 3 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} x \cr x \cr \end{matrix} \hspace+2pt\right] \ = }

  3. { \mathbf{[}\hspace+2pt \begin{matrix} 3 &\hspace-5pt 2 &\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 2 \cr \hfil 1 \cr \hfil -2 \cr \end{matrix} \hspace+2pt\right] \ = }

Row vectors and column vectors

A matrix is viewed as either a list of rows or a list of columns.

For example, given this matrix:

{ \left[\hspace+2pt \begin{matrix} \hfil a &\hfil\hspace-5pt b &\hfil\hspace-5pt c \cr \hfil d &\hfil\hspace-5pt e &\hfil\hspace-5pt f \cr \hfil g &\hfil\hspace-5pt h &\hfil\hspace-5pt i \cr \end{matrix} \hspace+2pt\right] }

we can slice it into a list of rows:

{ \mathbf{[}\hspace+2pt \hspace+1pt a \ \ \, b \ \ \, c \hspace+1pt \hspace+2pt\mathbf{]} }
{ \mathbf{[}\hspace+2pt \hspace+1pt d \ \ \, e \ \ \, \hspace-1.5pt f \hspace+1pt \hspace+2pt\mathbf{]} }
{ \mathbf{[}\hspace+2pt \hspace+1pt g \ \ \, h \ \ \, i \hspace+1pt \hspace+2pt\mathbf{]} }

or we can slice it into a list of columns:

{ \left[\hspace+2pt \begin{matrix} \hfil a \cr \hfil d \cr \hfil g \cr \end{matrix} \hspace+2pt\right] \hspace-4pt \left[\hspace+2pt \begin{matrix} \hfil b \cr \hfil e \cr \hfil h \cr \end{matrix} \hspace+2pt\right] \hspace-4pt \left[\hspace+2pt \begin{matrix} \hfil c \cr \hfil f \cr \hfil i \cr \end{matrix} \hspace+2pt\right] }

If we slice a matrix into rows:

A single row such as { \mathbf{[}\hspace+2pt \hspace+0.5pt a \ \ \, b \ \ \, c \hspace+0.5pt \hspace+2pt\mathbf{]} } is called a row vector.

If we slice a matrix into columns:

A single column such as { \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil a \cr \hfil d \cr \hfil g \cr \end{matrix} \hspace+2pt\right] } is called a column vector.

We use the word vector to refer to one single column or one single row of a matrix. Within each vector, the numbers are written in a specific order:

The numbers in a row vector are written from left to right.
The numbers in a column vector are written from top to bottom.

The way we slice a matrix into vectors depends on whether it appears first or second in matrix multiplication:

In matrix multiplication:

We’re now ready to perform matrix multiplication on a matrix with multiple rows and multiple columns.

Matrix multiplication: technique

There are three key things to remember when performing matrix multiplication:

  1. Move the second matrix physically upward, high enough to create space for the body of the table.

  2. Slice each matrix into its individual vectors:
    • Slice the first matrix into row vectors.
    • Slice the second matrix into column vectors.

  3. Create internal grid lines in the body of the table — they will hold the result. Each entry in the grid is the dot product of its row vector and column vector.

For example, given this multiplication:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \hfil 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\right] }

1. Move the second matrix physically upward to create space for the table body:

{ \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\right] }
{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \hfil 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] } 🡅

2. Slice the first matrix into rows and the second matrix into columns:

{ { \left[\hspace+2pt \begin{matrix} \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 20 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] } } 🡄slice
{ { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\mathbf{]} } }
{ { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\mathbf{]} } }
🡅
slice

3. Create internal grid lines in the body of the table:

{ \left[\hspace+2pt \begin{matrix} \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 20 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] }
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\mathbf{]} }
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\mathbf{]} }

and then fill in the table entries using the dot product:

dot
product
{ \left[\hspace+2pt \begin{matrix} \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 20 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] }
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\mathbf{]} }
{12}
{24}
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\mathbf{]} }
{34}
{68}
For example, the entry {12} is calculated this way:

{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] \ = \ 1 \mathord{\times} 10 + 2 \mathord{\times} 1 \ = \ 10+2 \ = \ 12 }

and then use the internal body of the table as the result matrix:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 \cr \hfil 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \hfil 1 &\hfil\hspace-5pt 2 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 12 &\hfil\hspace-5pt 24 \cr \hfil 34 &\hfil\hspace-5pt 68 \cr \end{matrix} \hspace+2pt\right] }

Matrix multiplication: a larger example

Let’s perform the following matrix multiplication:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \hfil 4 &\hfil\hspace-5pt 5 &\hfil\hspace-5pt 6 \cr \hfil 7 &\hfil\hspace-5pt 8 &\hfil\hspace-5pt 9 \cr \hfil 10 &\hfil\hspace-5pt 11 &\hfil\hspace-5pt 12 \cr \hfil 13 &\hfil\hspace-5pt 14 &\hfil\hspace-5pt 15 \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil 100 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 300 &\hfil\hspace-5pt 400 \cr \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 \cr \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] }

Here are the steps to do it:

  1. Move the second matrix physically upward, high enough to create space for the body of the table.

    So take this:

    { \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \hfil 4 &\hfil\hspace-5pt 5 &\hfil\hspace-5pt 6 \cr \hfil 7 &\hfil\hspace-5pt 8 &\hfil\hspace-5pt 9 \cr \hfil 10 &\hfil\hspace-5pt 11 &\hfil\hspace-5pt 12 \cr \hfil 13 &\hfil\hspace-5pt 14 &\hfil\hspace-5pt 15 \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil 100 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 300 &\hfil\hspace-5pt 400 \cr \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 \cr \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] }

    and rewrite it like this:

    { \left[\hspace+2pt \begin{matrix} \hfil 100 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 300 &\hfil\hspace-5pt 400 \cr \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 \cr \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] }
    { \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \hfil 4 &\hfil\hspace-5pt 5 &\hfil\hspace-5pt 6 \cr \hfil 7 &\hfil\hspace-5pt 8 &\hfil\hspace-5pt 9 \cr \hfil 10 &\hfil\hspace-5pt 11 &\hfil\hspace-5pt 12 \cr \hfil 13 &\hfil\hspace-5pt 14 &\hfil\hspace-5pt 15 \cr \end{matrix} \hspace+2pt\right] } 🡅
  2. Slice the first matrix into its individual row vectors, and slice the second matrix into its individual column vectors. Also, create internal grid lines to hold the results:

    { \left[\hspace+2pt \begin{matrix} \hfil 100 \cr \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 200 \cr \hfil 20 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 300 \cr \hfil 30 \cr \hfil 3 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 400 \cr \hfil 40 \cr \hfil 4 \cr \end{matrix} \hspace+2pt\right] } 🡄slice
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil \phantom{0}1 &\hfil\hspace-5pt \phantom{0}2 &\hfil\hspace-5pt \phantom{0}3 \cr \end{matrix} \hspace+2pt\mathbf{]} }
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil \phantom{0}4 &\hfil\hspace-5pt \phantom{0}5 &\hfil\hspace-5pt \phantom{0}6 \cr \end{matrix} \hspace+2pt\mathbf{]} }
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil \phantom{0}7 &\hfil\hspace-5pt \phantom{0}8 &\hfil\hspace-5pt \phantom{0}9 \cr \end{matrix} \hspace+2pt\mathbf{]} }
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 11 &\hfil\hspace-5pt 12 \cr \end{matrix} \hspace+2pt\mathbf{]} }
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 13 &\hfil\hspace-5pt 14 &\hfil\hspace-5pt 15 \cr \end{matrix} \hspace+2pt\mathbf{]} }
    🡅
    slice
  3. Fill in the table entries using the dot product:

    dot
    product
    { \left[\hspace+2pt \begin{matrix} \hfil 100 \cr \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 200 \cr \hfil 20 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 300 \cr \hfil 30 \cr \hfil 3 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 400 \cr \hfil 40 \cr \hfil 4 \cr \end{matrix} \hspace+2pt\right] }
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil \phantom{0}1 &\hfil\hspace-5pt \phantom{0}2 &\hfil\hspace-5pt \phantom{0}3 \cr \end{matrix} \hspace+2pt\mathbf{]} } {123} {246} {369} {492}
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil \phantom{0}4 &\hfil\hspace-5pt \phantom{0}5 &\hfil\hspace-5pt \phantom{0}6 \cr \end{matrix} \hspace+2pt\mathbf{]} } {456} {912} {1368} {1824}
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil \phantom{0}7 &\hfil\hspace-5pt \phantom{0}8 &\hfil\hspace-5pt \phantom{0}9 \cr \end{matrix} \hspace+2pt\mathbf{]} } {789} {1578} {2367} {3156}
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 11 &\hfil\hspace-5pt 12 \cr \end{matrix} \hspace+2pt\mathbf{]} } {1122} {2244} {3366} {4488}
    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 13 &\hfil\hspace-5pt 14 &\hfil\hspace-5pt 15 \cr \end{matrix} \hspace+2pt\mathbf{]} } {1455} {2910} {4365} {5820}

    For example, the top-left entry is calculated using the dot product this way:

    { \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 100 \cr \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] \, = \, \ 1 \mathord{\times} 100 + 2 \mathord{\times} 10 + 3 \mathord{\times} 1 \, \ = \, \ 123 }

  4. Write the internal body of the table as a matrix, producing the final result:

    { \left[\hspace+2pt \begin{matrix} \hfil 123 &\hfil\hspace-5pt 246 &\hfil\hspace-5pt 369 &\hfil\hspace-5pt 492 \cr \hfil 456 &\hfil\hspace-5pt 912 &\hfil\hspace-5pt 1368 &\hfil\hspace-5pt 1824 \cr \hfil 789 &\hfil\hspace-5pt 1578 &\hfil\hspace-5pt 2367 &\hfil\hspace-5pt 3156 \cr \hfil 1122 &\hfil\hspace-5pt 2244 &\hfil\hspace-5pt 3366 &\hfil\hspace-5pt 4488 \cr \hfil 1455 &\hfil\hspace-5pt 2910 &\hfil\hspace-5pt 4365 &\hfil\hspace-5pt 5820 \cr \end{matrix} \hspace+2pt\right] }

  5. And now we can write the complete equation:

    { \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \hfil 4 &\hfil\hspace-5pt 5 &\hfil\hspace-5pt 6 \cr \hfil 7 &\hfil\hspace-5pt 8 &\hfil\hspace-5pt 9 \cr \hfil 10 &\hfil\hspace-5pt 11 &\hfil\hspace-5pt 12 \cr \hfil 13 &\hfil\hspace-5pt 14 &\hfil\hspace-5pt 15 \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil 100 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 300 &\hfil\hspace-5pt 400 \cr \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 \cr \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 123 &\hfil\hspace-5pt 246 &\hfil\hspace-5pt 369 &\hfil\hspace-5pt 492 \cr \hfil 456 &\hfil\hspace-5pt 912 &\hfil\hspace-5pt 1368 &\hfil\hspace-5pt 1824 \cr \hfil 789 &\hfil\hspace-5pt 1578 &\hfil\hspace-5pt 2367 &\hfil\hspace-5pt 3156 \cr \hfil 1122 &\hfil\hspace-5pt 2244 &\hfil\hspace-5pt 3366 &\hfil\hspace-5pt 4488 \cr \hfil 1455 &\hfil\hspace-5pt 2910 &\hfil\hspace-5pt 4365 &\hfil\hspace-5pt 5820 \cr \end{matrix} \hspace+2pt\right] }


When performing matrix multiplication, it’s important to remember this rule:

In matrix multiplication, the number of columns in the first matrix must be the same as the number of rows in the second matrix.

Observe that the above example satisfies this requirement.

Matrix multiplication: examples

Here are some examples of matrix multiplication.

1. These examples don’t require any addition:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \end{matrix} \hspace+2pt\mathbf{]} = \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \hfil 20 &\hfil\hspace-5pt 40 \cr \end{matrix} \hspace+2pt\right] }
{ \left[\hspace+2pt \begin{matrix} \hfil 1 \cr \hfil 2 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 &\hfil\hspace-5pt 50 \cr \end{matrix} \hspace+2pt\mathbf{]} = \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 &\hfil\hspace-5pt 50 \cr \hfil 20 &\hfil\hspace-5pt 40 &\hfil\hspace-5pt 60 &\hfil\hspace-5pt 80 &\hfil\hspace-5pt 100 \cr \end{matrix} \hspace+2pt\right] }
{ \left[\hspace+2pt \begin{matrix} \hfil 1 \cr \hfil 2 \cr \hfil 3 \cr \hfil 4 \cr \hfil 5 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \end{matrix} \hspace+2pt\mathbf{]} = \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 \cr \hfil 20 &\hfil\hspace-5pt 40 \cr \hfil 30 &\hfil\hspace-5pt 60 \cr \hfil 40 &\hfil\hspace-5pt 80 \cr \hfil 50 &\hfil\hspace-5pt 100 \cr \end{matrix} \hspace+2pt\right] }
{ \left[\hspace+2pt \begin{matrix} \hfil 1 \cr \hfil 2 \cr \hfil 3 \cr \hfil 4 \cr \hfil 5 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 &\hfil\hspace-5pt 50 \cr \end{matrix} \hspace+2pt\mathbf{]} = \left[\hspace+2pt \begin{matrix} \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 &\hfil\hspace-5pt 40 &\hfil\hspace-5pt 50 \cr \hfil 20 &\hfil\hspace-5pt 40 &\hfil\hspace-5pt 60 &\hfil\hspace-5pt 80 &\hfil\hspace-5pt 100 \cr \hfil 30 &\hfil\hspace-5pt 60 &\hfil\hspace-5pt 90 &\hfil\hspace-5pt 120 &\hfil\hspace-5pt 150 \cr \hfil 40 &\hfil\hspace-5pt 80 &\hfil\hspace-5pt 120 &\hfil\hspace-5pt 160 &\hfil\hspace-5pt 200 \cr \hfil 50 &\hfil\hspace-5pt 100 &\hfil\hspace-5pt 150 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 250 \cr \end{matrix} \hspace+2pt\right] }

2. These examples require adding products together:

{ \hspace+1.5pt \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 100 \cr \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] = \mathbf{[}\hspace+2pt \begin{matrix} \hfil 123 \end{matrix} \hspace+2pt\mathbf{]} }
{ \hspace+1.5pt \mathbf{[}\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 100 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 300 \cr \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 \cr \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \end{matrix} \hspace+2pt\right] = \mathbf{[}\hspace+2pt \begin{matrix} \hfil 123 &\hfil\hspace-5pt 246 &\hfil\hspace-5pt 369 \cr \end{matrix} \hspace+2pt\mathbf{]} }
{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \hfil 4 &\hfil\hspace-5pt 5 &\hfil\hspace-5pt 6 \cr \hfil 7 &\hfil\hspace-5pt 8 &\hfil\hspace-5pt 9 \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil 100 \cr \hfil 10 \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 123 \cr \hfil 456 \cr \hfil 789 \cr \end{matrix} \hspace+2pt\right] }
{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \hfil 4 &\hfil\hspace-5pt 5 &\hfil\hspace-5pt 6 \cr \hfil 7 &\hfil\hspace-5pt 8 &\hfil\hspace-5pt 9 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 100 &\hfil\hspace-5pt 200 &\hfil\hspace-5pt 300 \cr \hfil 10 &\hfil\hspace-5pt 20 &\hfil\hspace-5pt 30 \cr \hfil 1 &\hfil\hspace-5pt 2 &\hfil\hspace-5pt 3 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 123 &\hfil\hspace-5pt 246 &\hfil\hspace-5pt 369 \cr \hfil 456 &\hfil\hspace-5pt 912 &\hfil\hspace-5pt 1368 \cr \hfil 789 &\hfil\hspace-5pt 1578 &\hfil\hspace-5pt 2367 \cr \end{matrix} \hspace+2pt\right] }

For each of these examples, notice that:

The result has the same number of rows as the first matrix.
The result has the same number of columns as the second matrix.

and that:

The number of columns in the first matrix must be the same as
the number of rows in the second matrix.

Matrix multiplication: more exercises

Here are some more matrix multiplication exercises:

  1. { \left[\hspace+2pt \begin{matrix} \hfil 2 \cr \hfil 4 \cr \end{matrix} \hspace+2pt\right] \mathbf{[}\hspace+2pt \begin{matrix} \hfil 6 &\hfil\hspace-5pt 8 \cr \end{matrix} \hspace+2pt\mathbf{]} \ = }

  2. { \hspace+1.5pt \mathbf{[}\hspace+2pt \begin{matrix} \hfil 2 &\hfil\hspace-5pt 4 \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 6 \cr \hfil 8 \cr \end{matrix} \hspace+2pt\right] \ = }

  3. { \hspace+1.5pt \mathbf{[}\hspace+2pt \begin{matrix} \hfil a &\hfil\hspace-5pt b &\hfil\hspace-5pt c \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} x^{\large 2} \cr x \cr 1 \cr \end{matrix} \hspace+2pt\right] \ = }

  4. { \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil\hspace-5pt 1 \cr \hfil 1 &\hfil\hspace-5pt 0 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil a &\hfil\hspace-5pt b \cr \hfil c &\hfil\hspace-5pt d \cr \end{matrix} \hspace+2pt\right] \ = }

Application: the sum of proportionately-weighted values

Alice and Bob both invest in precious metal coins.

This table shows how many coins they each have:

Gold coins Silver coins Platinum coins
Alice: { 5} {75} {30}
Bob: { 8} {50} {16}

This table shows information about each type of coin:

 Weight  Market value
One gold coin: { 50 \text{ g}} {$3500}
One silver coin: {200 \text{ g}} { $150}
One platinum coin: { 20 \text{ g}} { $700}

We can determine the total amount of their investments (in both weight and market value) by performing this matrix multiplication:

{ \left[\hspace+2pt \begin{matrix} \hfil 5 &\hfil\hspace-5pt 75 &\hfil\hspace-5pt 30 \cr \hfil 8 &\hfil\hspace-5pt 50 &\hfil\hspace-5pt 16 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 50 &\hfil\hspace-5pt 3500 \cr \hfil 200 &\hfil\hspace-5pt 150 \cr \hfil 20 &\hfil\hspace-5pt 700 \cr \end{matrix} \hspace+2pt\right] }

As usual, we can construct the table by moving the second matrix physically upward, slicing each matrix into individual rows or columns as necessary, and performing the dot products:

dot
product
{ \left[\hspace+2pt \begin{matrix} \hfil 50 \cr \hfil 200 \cr \hfil 20 \cr \end{matrix} \hspace+2pt\right] } { \left[\hspace+2pt \begin{matrix} \hfil 3500 \cr \hfil 150 \cr \hfil 700 \cr \end{matrix} \hspace+2pt\right] }
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 5 &\hfil\hspace-5pt 75 &\hfil\hspace-5pt 30 \cr \end{matrix} \hspace+2pt\mathbf{]} }
{15\text{,}850}
{49\text{,}750}
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil 8 &\hfil\hspace-5pt 50 &\hfil\hspace-5pt 16 \cr \end{matrix} \hspace+2pt\mathbf{]} }
{10\text{,}720}
{46\text{,}700}

Then, we can write the internal body of the table as a matrix:

{ \left[\hspace+2pt \begin{matrix} \hfil 15\text{,}850 &\hfil\hspace-5pt 49\text{,}750 \cr \hfil 10\text{,}720 &\hfil\hspace-5pt 46\text{,}700 \cr \end{matrix} \hspace+2pt\right] }

which we can interpret like this:

Total coin weight Total market value
Alice: {15\text{,}850 \text{ g}} {$49\text{,}750}
Bob: {10\text{,}720 \text{ g}} {$46\text{,}700}

Application: rotation

On the XY plane, let’s draw a line segment from the origin to any point {(x, y)} on the plane.

We can now rotate that line segment around the origin. The rotation is performed like the hand of an analog clock, with one end remaining stationary at the origin, and the other end moving in a circular arc. During rotation, the length of the line segment never changes.

After rotating by angle {\theta,} we would like to know the new position of the end that moved. Let’s define ({x^\prime, y^\prime)} to be that new position.

We can calculate ({x^\prime, y^\prime)} using matrix multiplication, as follows:

{ \left[\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta \cr \hfil \sin \theta &\hfil \cos \theta \cr \end{matrix} \hspace+2pt\right] \hspace-3pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil x^\prime \cr \hfil y^\prime \cr \end{matrix} \hspace+2pt\right] }

Notice that {(x, y)} is written here as a column vector: { \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right]. }

The reason why it’s a column vector is because it’s the second matrix in the multiplication, and the second matrix is always organized by columns.

As usual, we can construct the table by moving the second matrix physically upward, slicing each matrix into individual rows or columns as necessary, and performing the dot products:

dot
product
{ \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] }
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta \cr \end{matrix} \hspace+2pt\mathbf{]} }
{x^\prime}
{ \mathbf{[}\hspace+2pt \begin{matrix} \hfil \sin \theta &\hfil \phantom{-} \cos \theta \cr \end{matrix} \hspace+2pt\mathbf{]} }
{y^\prime}

We can now see that the result { \left[\hspace+2pt \begin{matrix} \hfil x^\prime \cr \hfil y^\prime \cr \end{matrix} \hspace+2pt\right] } is calculated using these two dot products:

{ x^\prime \ = \ \mathbf{[}\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] \ = \ x \cos \theta - y \sin \theta }
{ y^\prime \hspace0.8pt \ = \ \mathbf{[}\hspace+2pt \begin{matrix} \hfil \sin \theta &\hfil \phantom{-}\cos \theta \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] \ = \ x \sin \theta + y \cos \theta }

For example, if we start at {(x,y) = (3,4)} and rotate by angle {\theta = 30°,} then we get:

{ x^\prime \ = \ \mathbf{[}\hspace+2pt \begin{matrix} \hfil \cos 30° &\hfil -\sin 30° \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 3 \cr \hfil 4 \cr \end{matrix} \hspace+2pt\right] \ = \ 0.866 \mathord{\times} 3 - 0.5 \mathord{\times} 4 \ = \ 0.598 }
{ y^\prime \hspace0.8pt \ = \ \mathbf{[}\hspace+2pt \begin{matrix} \hfil \sin 30° &\hfil \phantom{-}\cos 30° \cr \end{matrix} \hspace+2pt\mathbf{]} \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 3 \cr \hfil 4 \cr \end{matrix} \hspace+2pt\right] \ = \ 0.5 \mathord{\times} 3 + 0.866 \mathord{\times} 4 \ = \ 4.964 }

producing the result {(x^\prime, y^\prime) = (0.598, 4.964).}

If {\theta > 0,} the rotation is counterclockwise, and if {\theta < 0,} the rotation is clockwise.

Transformation

In this section, we take the point {(x, y)} and multiply it by a transformation matrix to obtain a new point. We can view this as “movement” from {(x, y)} to the new point. This kind of “movement” is called a transformation.

These examples will help you gain familiarity with the use of a transformation matrix for performing various transformations on the XY plane.

  1. Start at {(x, y)} and mirror-reflect around the Y axis:

    { \left[\hspace+2pt \begin{matrix} \hfil -1 &\hfil 0 \cr \hfil 0 &\hfil 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil -x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] }

  2. Start at {(x, y)} and reflect upside-down around the X axis:

    { \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil 0 \cr \hfil 0 &\hfil -1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil -y \cr \end{matrix} \hspace+2pt\right] }

  3. Start at {(x, y)} and rotate {180°} around the origin:

    { \left[\hspace+2pt \begin{matrix} \hfil -1 &\hfil 0 \cr \hfil 0 &\hfil -1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil -x \cr \hfil -y \cr \end{matrix} \hspace+2pt\right] }

  4. Start at {(x, y)} and reflect diagonally around the line {y = x}:

    { \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil 1 \cr \hfil 1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil y \cr \hfil x \cr \end{matrix} \hspace+2pt\right] }

  5. Start at {(x, y)} and don’t move:

    { \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil 0 \cr \hfil 0 &\hfil 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] }

  6. Start at {(x, y)} and rotate {90°} counterclockwise around the origin:

    { \left[\hspace+2pt \begin{matrix} \hfil \cos 90° &\hfil -\sin 90° \cr \hfil \sin 90° &\hfil \cos 90° \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil -1 \cr \hfil 1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil -y \cr \hfil x \cr \end{matrix} \hspace+2pt\right] }

  7. Start at {(x, y)} and rotate {90°} clockwise around the origin:

    { \left[\hspace+2pt \begin{matrix} \hfil \cos (-90°) &\hfil -\sin (-90°) \cr \hfil \sin (-90°) &\hfil \cos (-90°) \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil 1 \cr \hfil -1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil y \cr \hfil -x \cr \end{matrix} \hspace+2pt\right] }

  8. Start at {(x, y)} and move {s} times farther away from the origin:

    { \left[\hspace+2pt \begin{matrix} \hfil s &\hfil 0 \cr \hfil 0 &\hfil s \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil sx \cr \hfil sy \cr \end{matrix} \hspace+2pt\right] }

  9. Start at {(x, y)} and move {s_1} times farther away from the origin in the horizontal direction, and move {s_2} times farther away from the origin in the vertical direction:

    { \left[\hspace+2pt \begin{matrix} s_1 & 0 \cr 0 & s_2 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil s_1 \, x \cr \hfil s_2 \, y \cr \end{matrix} \hspace+2pt\right] }

Transformation: composition exercises

If you perform a transformation using matrix {A,} and then take the result and perform another transformation using matrix {B,} you can combine them together into a single matrix that performs both transformations {A} and {B} at the same time.

The result is called the composition of {A} and {B}, and its matrix is determined by multiplying {B} with {A,} in that order.

Example #1:

Multiplication by matrix {A} reflects around the line {y = x}:

{ A = \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil 1 \cr \hfil 1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] }

Multiplication by matrix {B} mirror-reflects around the Y axis:

{ B = \left[\hspace+2pt \begin{matrix} \hfil -1 &\hfil 0 \cr \hfil 0 &\hfil 1 \cr \end{matrix} \hspace+2pt\right] }

Find the matrix of the composition of {A} and {B}, which is {BA}:

{ BA = \left[\hspace+2pt \begin{matrix} \hfil -1 &\hfil 0 \cr \hfil 0 &\hfil 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil 1 \cr \hfil 1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil -1 \cr \hfil 1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] }

Now, we can use multiplication by matrix {BA} to perform {A} and then {B} in one step:

{ \left[\hspace+2pt \begin{matrix} \hfil 0 &\hfil -1 \cr \hfil 1 &\hfil 0 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil -y \cr \hfil x \cr \end{matrix} \hspace+2pt\right] }

Example #2:

Multiplication by matrix {A} moves {s} times farther away from the origin:

{ A = \left[\hspace+2pt \begin{matrix} \hfil s &\hfil 0 \cr \hfil 0 &\hfil s \cr \end{matrix} \hspace+2pt\right] }

Multiplication by matrix {B} rotates around the origin by angle {\theta}:

{ B = \left[\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta \cr \hfil \sin \theta &\hfil \cos \theta \cr \end{matrix} \hspace+2pt\right] }

Find the matrix of the composition of {A} and {B}, which is {BA}:

{ BA = \left[\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta \cr \hfil \sin \theta &\hfil \cos \theta \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil s &\hfil 0 \cr \hfil 0 &\hfil s \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil s\cos \theta &\hfil -s\sin \theta \cr \hfil s\sin \theta &\hfil s\cos \theta \cr \end{matrix} \hspace+2pt\right] }

Now, we can use multiplication by matrix {BA} to perform {A} and then {B} in one step:

{ \left[\hspace+2pt \begin{matrix} \hfil s\cos \theta &\hfil -s\sin \theta \cr \hfil s\sin \theta &\hfil s\cos \theta \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil sx \cos \theta - sy \sin \theta \cr \hfil sx \sin \theta + sy \cos \theta \cr \end{matrix} \hspace+2pt\right] }

Exercise:

Use matrix multiplication to show that a rotation of {90°} followed by another rotation of {90°} produces a net rotation of {180°.}

Transformation: composition in general

In the previous section, we found that we can start at the point { \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] } and perform two consecutive transformations.

In general, we can write the two transformations like this:

{ \left[\hspace+2pt \begin{matrix} \hfil e &\hfil f \cr \hfil g &\hfil h \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil a &\hfil b \cr \hfil c &\hfil d \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] }

The transformations are performed in a “chain”, from right to left, producing the combined effect of one transformation followed by the other. This “chaining” effect is called composition.

To understand how composition works, first, start with any column vector:

{ \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] }

and then transform it by multiplying it with

{ \left[\hspace+2pt \begin{matrix} \hfil a &\hfil b \cr \hfil c &\hfil d \cr \end{matrix} \hspace+2pt\right], }   which gives us the point { \left[\hspace+2pt \begin{matrix} \hfil x^{\prime} \cr \hfil y^{\prime} \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil a &\hfil b \cr \hfil c &\hfil d \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] }

and then take that result and transform it by multiplying it with

{ \left[\hspace+2pt \begin{matrix} \hfil e &\hfil f \cr \hfil g &\hfil h \cr \end{matrix} \hspace+2pt\right], }   which gives us the point { \left[\hspace+2pt \begin{matrix} \hfil x^{\prime\prime} \cr \hfil y^{\prime\prime} \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil e &\hfil f \cr \hfil g &\hfil h \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x^\prime \cr \hfil y^\prime \cr \end{matrix} \hspace+2pt\right] }

If we multiply the two transformation matrices together, we get a single matrix that performs the combined effects of the two individual transformations:

{ \left[\hspace+2pt \begin{matrix} \hfil e &\hfil f \cr \hfil g &\hfil h \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil a &\hfil b \cr \hfil c &\hfil d \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil ea+fc &\hfil eb+fd \cr \hfil ga+hc &\hfil gb+hd \cr \end{matrix} \hspace+2pt\right] }

Now, using this final matrix, we can find {(x^{\prime\prime}, y^{\prime\prime})} directly from {(x, y)} with only one multiplication:

{ \left[\hspace+2pt \begin{matrix} \hfil x^{\prime\prime} \cr \hfil y^{\prime\prime} \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil ea+fc &\hfil eb+fd \cr \hfil ga+hc &\hfil gb+hd \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil (ea+fc)x + (eb+fd)y \cr \hfil (ga+hc)x + (gb+hd)y \cr \end{matrix} \hspace+2pt\right] }

Transformation: displacement

On the XY plane, you can start at {(x, y)} and move to another position by the amount {(\Delta x, \Delta y).} This movement can be expressed in algebra like this:

{(x, y) + (\Delta x, \Delta y) \ = \ (x + \Delta x, \, y+ \Delta y)}

The movement from the start position to the end position is called displacement, and {(\Delta x, \Delta y)} represents the amount of that displacement.

Since displacement represents movement, you can view it as another type of transformation.

Can we perform displacement with a transformation matrix? We can, but first, we need to make the following observation:

If you multiply a {2 \mathord{\times} 2} matrix by {(0,0),} the result is always {(0,0)}:
{ \left[\hspace+2pt \begin{matrix} \hfil a &\hfil b \cr \hfil c &\hfil d \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil 0 \cr \hfil 0 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil 0 \cr \hfil 0 \cr \end{matrix} \hspace+2pt\right] }

This means that {2 \mathord{\times} 2} matrix multiplication, by itself, is unable to displace {(0,0)} to any other position.

If you want to use a transformation matrix for displacement, you need to add another dimension.

Here’s how you can take {(x,y)} and displace it by {(\Delta x, \Delta y)} using a 3D transformation matrix:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil 0 &\hfil \Delta x \cr \hfil 0 &\hfil 1 &\hfil \Delta y \cr \hfil 0 &\hfil 0 & 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} x + \Delta x \cr y + \Delta y \cr 1 \cr \end{matrix} \hspace+2pt\right] }

Notice the extra {1} that appears in the third dimension. That extra {1} is necessary to obtain the correct result, and it must always be {1,} but you can otherwise ignore it.

As an exercise, work through the above equation to verify that it’s correct.

Transformation: scaling, rotation, and displacement

Recall that in 2D, we can perform scaling by a factor {s} like this:

{ \left[\hspace+2pt \begin{matrix} s & 0 \cr 0 & s \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil s x \cr \hfil s y \cr \end{matrix} \hspace+2pt\right] }

and we can perform rotation around the origin by angle {\theta} like this:

{ \left[\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta \cr \hfil \sin \theta &\hfil \cos \theta \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} \hfil x \cos \theta - y \sin \theta \cr \hfil x \sin \theta + y \cos \theta \cr \end{matrix} \hspace+2pt\right] }

and that displacement by {(\Delta x, \Delta y)} can be done, but it requires a {3 \mathord{\times} 3} matrix:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil 0 &\hfil \Delta x \cr \hfil 0 &\hfil 1 &\hfil \Delta y \cr \hfil 0 &\hfil 0 & 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} x + \Delta x \cr y + \Delta y \cr 1 \cr \end{matrix} \hspace+2pt\right] }

Let’s combine scaling, rotation, and displacement, together, in that order, to create a single transformation. We do this by multiplying these three matrices together:

{ \left[\hspace+2pt \begin{matrix} \hfil 1 &\hfil 0 &\hfil \Delta x \cr \hfil 0 &\hfil 1 &\hfil \Delta y \cr \hfil 0 &\hfil 0 & 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil \cos \theta &\hfil -\sin \theta & 0 \cr \hfil \sin \theta &\hfil \cos \theta & 0 \cr 0 & 0 & 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil s &\hfil 0 &\hfil 0 \cr \hfil 0 &\hfil s &\hfil 0 \cr \hfil 0 &\hfil 0 & 1 \cr \end{matrix} \hspace+2pt\right] }

As a result, we get the matrix for the composition of the three transformations:

{ \left[\hspace+2pt \begin{matrix} \hfil s \cos \theta &\hfil -s \sin \theta &\hfil \Delta x \cr \hfil s \sin \theta &\hfil s \cos \theta &\hfil \Delta y \cr 0 & 0 & 1 \cr \end{matrix} \hspace+2pt\right] }

which we can use to perform scaling, rotation and displacement in a single step:

{ \left[\hspace+2pt \begin{matrix} \hfil s \cos \theta &\hfil -s \sin \theta &\hfil \Delta x \cr \hfil s \sin \theta &\hfil s \cos \theta &\hfil \Delta y \cr 0 & 0 & 1 \cr \end{matrix} \hspace+2pt\right] \hspace-2pt \left[\hspace+2pt \begin{matrix} \hfil x \cr \hfil y \cr \hfil 1 \cr \end{matrix} \hspace+2pt\right] = \left[\hspace+2pt \begin{matrix} s(x \cos \theta - y \sin \theta) + \Delta x \cr s(x \sin \theta + y \cos \theta) + \Delta y \cr 1 \cr \end{matrix} \hspace+2pt\right] }

As an exercise, verify that the composition matrix is correct, by performing the matrix multiplication of the three {3 \mathord{\times} 3} matrices yourself.