Hotmath
Math Homework. Do It Faster, Learn It Better.

Matrix Multiplication

You can only multiply two matrices if their dimensions are compatible , which means the number of columns in the first matrix is the same as the number of rows in the second matrix.

If A = [ a i j ] is an m × n matrix and B = [ b i j ] is an n × p matrix, the product A B is an m × p matrix.

A B = [ c i j ] , where c i j = a i 1 b 1 j + a i 2 b 2 j + ... + a i n b n j .

(The entry in the i th row and j th column is denoted by the double subscript notation a i j , b i j , and c i j . For instance, the entry a 23 is the entry in the second row and third column.)

The definition of matrix multiplication indicates a row-by-column multiplication, where the entries in the i th row of A are multiplied by the corresponding entries in the j th column of B and then adding the results.

Matrix multiplication is NOT commutative.   If neither A nor B is an identity matrix, A B B A .

Multiplying a Row by a Column

We'll start by showing you how to multiply a 1 × n matrix by an n × 1 matrix. The first is just a single row, and the second is a single column. By the rule above, the product is a 1 × 1 matrix; in other words, a single number.

First, let's name the entries in the row r 1 , r 2 , ... , r n , and the entries in the column c 1 , c 2 , ... , c n . Then the product of the row and the column is the 1 × 1 matrix

[ r 1 c 1 + r 2 c 2 + ... + r n c n ] .

Example:

Find the product.

[ 1 4 0 ] [ 2 1 5 ]

We have to multiply a 1 × 3 matrix by a 1 × 3 matrix. The number of columns in the first is the same as the number of rows in the second, so they are compatible.

The product is:

[ ( 1 ) ( 2 ) + ( 4 ) ( 1 ) + ( 0 ) ( 5 ) ] = [ 2 + ( 4 ) + 0 ] = [ 2 ]

Multiplying Larger Matrices

Now that you know how to multiply a row by a column, multiplying larger matrices is easy. For the entry in the i th row and the j th column of the product matrix, multiply each entry in the i th row of the first matrix by the corresponding entry in the j th column of the second matrix and adding the results.

Let's take the following problem, multiplying a 2 × 3 matrix with a 3 × 2 matrix, to get a 2 × 2 matrix as the product. The entries of the product matrix are called e i j when they're in the i th row and j th column.

[ 1 0 1 0 1 2 ] [ 3 5 1 0 2 1 ] = [ e 11 e 12 e 21 e 22 ]

To get e 11 , multiply Row 1 of the first matrix by Column 1 of the second.

e 11 = [ 1 0 1 ] [ 3 1 2 ] = 1 ( 3 ) + 0 ( 1 ) + 1 ( 2 ) = 5

To get e 12 , multiply Row 1 of the first matrix by Column 2 of the second.

e 12 = [ 1 0 1 ] [ 5 0 1 ] = 1 ( 5 ) + 0 ( 0 ) + 1 ( 1 ) = 4

To get e 21 , multiply Row 2 of the first matrix by Column 1 of the second.

e 21 = [ 0 1 2 ] [ 3 1 2 ] = 0 ( 3 ) + 1 ( 1 ) + 2 ( 2 ) = 3

To get e 22 , multiply Row 2 of the first matrix by Column 2 of the second.

e 22 = [ 0 1 2 ] [ 5 0 1 ] = 0 ( 5 ) + 1 ( 0 ) + 2 ( 1 ) = 2

Writing the product matrix, we get:

[ e 11 e 12 e 21 e 22 ] = [ 5 4 3 2 ]

Therefore, we have shown:

[ 1 0 1 0 1 2 ] [ 3 5 1 0 2 1 ] = [ 5 4 3 2 ]