SL | Matrix Multiplication

Matrix Multiplication

Let C denote the product of two matrices A and B.

C=AB

Where matrix A has N columns, and matrix B has N rows, a restriction which must be imposed in order multiply them. (The reason behind the restriction will be made clear by the end of this discussion.)

Here is the most common definition of matrix multiplication.

An element cij of C (the element at the intersection of row i and column j) is computed as follows.

cij=k=0N1aikbkj

This is a useful definition, but it does not provide us with any insight into what matrix multiplication really does.

Fortunately, there is a better way to view matrix multiplication.

We can view the matrix multiplication A B as each row vector of matrix A transforming the row vectors of matrix B to produce the corresponding row vector of matrix C, or equivalently as each column vector of B transforming the column vectors of A to produce the corresponding column vector of C. In this contex, transforming row vectors or column vectors simply means taking their linear combination.

To take the linear combination of N vectors Vk we simply multiply each vector by a scalar (a number) αk and sum the products:

U=k=0N1αkVk

The resulting vector U will have exactly the same number of elements as each original vector Vk.

Now, to produce a row of C, the corresponding row of A transforms the rows of B by taking their linear combination: This is done by multiplying each row of B by the corresponding element of the row of A and by summing the products (each product is a row and their sum is therefore a row.) This implies that C will have the same number of rows as A has; this also implies that C will have the same number of columns as B has. We call this Row Major Multiplication.

Similarly, to produce a column of C, the corresponding column of B transforms the columns of A by taking their linear combination: This is done by multiplying each column of A by the corresponding element of the column of B and by summing the products (each product is a column and their sum is therefore a column.) This implies that C will have the same number of columns as B has; this also implies that C will have the same number of rows as A has. We call this Column Major Multiplication.

Viewing the matrix multiplication in this manner enables us to gain a deeper insight into what matrix multiplication really does, which in turn enables us to answer some interesting questions. For example, we can answer the following questions quite easily.

What matrix A transforms the matrix B so that the result C consists of only the first and last rows of B?

A 2357 2300 0023 7532 = 2357 7532

Because C has two rows, A too must have two rows. How do we choose the rows of A?

We recall that to produce the first row of C, the first row of A takes the linear combination of all rows of B; and that to produce the second row of C, the second row of A takes the linear combination of all rows of B. Thus, we choose the rows of A in such way that the linear combination the of rows of B simply picks only the first row of B to produce first row of C, and picks only the last row of B to produce the second row of C. Thus we choose the matrix A as follows.

A= 1000 0001

This simply says that take only one (1) of the first of row of B and take none (0) of the other rows; take only one (1) of the last row of B and take none (0) of the other rows.

What matrix B transforms the matrix A so that the result C consists of only the last two columns of A?

2207 3305 5023 7032 B= 07 05 23 32

Because C has two columns, B too must have two columns. How do we choose the columns of B?

Again, we recall that to produce the first column of C, the first column of B takes the linear combination of all columns of A; and that to produce the second column of C, the second column of B takes the linear combination of all columns of A. Thus, we choose the columns of B in such way that the linear combination of the columns of A simply picks only the third coumn of A to produce the first column of C, and picks only the fourth column of A to produce the second column of C. Thus we choose the matrix B as follows.

B= 00 00 10 01

Similarly, this simply says that take only one (1) of the third of column of A and take none (0) of the other columns; take only one (1) of the fourth column of A and take none (0) of the other columns.

What matrix B transforms the matrix A so that the result C equals the mirror image of A?

2002 3200 0320 0033 B= 2002 0023 0230 3300

Choose the columns of matrix B in such a way that its first column takes the linear combination of the columns of A to pick only the last column of A in order to produce the first column of C; and so on.