Matrix Multiplication

Consider the product of a 2×3 matrix and a 3×4 matrix. The multiplication is defined because the inner dimensions (3) are the same. The product will be a 2×4 matrix, the outer dimensions.

[[1,-2,3], [4,5,-2]] * [[1,-8,4,-3], [-3,6,7,2], [6,5,-1,4]]

Since there are three columns in the first matrix and three rows in the second matrix (the inner dimensions which must be the same), each element in the product will be the sum of three products.

Row 1, Column 1

To find the element in row 1, column 1 of the product, we will take row 1 from the first matrix and column 1 from the second matrix. We pair these values together, multiply the pairs of values, and then add to arrive at 25.

 R1: 1  -2   3
×C1: 1  -3   6
---------------
     1  +6 +18 = 25

Row 2, Column 3

To find the element in row 2, column 3 of the product, we will take row 2 from the first matrix and column 3 from the second matrix. We pair these values together, multiply the pairs of values, and then add to arrive at 53.

 R2:  4   5  -2
×C3:  4   7  -1
---------------
     16 +35  +2 = 53

Understanding where each number in the product comes from is helpful when you only need a specific value. You don't need to multiply completely if you only want specific elements. Just take the row from the first matrix and the column from the second matrix.

The process can be completed for the rest of the elements in the matrix.

    Column 1 Column 2 Column 3 Column 4
  values [1, -3, 6] [-8, 6, 5] [4, 7, -1] [-3, 2, 4]
Row 1 [1, -2, 3] 1(1) - 2(-3) + 3(6)
= 1 + 6 + 18
= 25
1(-8) -2(6) + 3(5)
= -8 - 12 + 15
= -5
1(4) -2(7) +3(-1)
= 4 - 14 - 3
= -13
1(-3) -2(2) + 3(4)
= -3 -4 + 12
= 5
Row 2 [4, 5, -2] 4(1) + 5(-3) -2(6)
= 4 - 15 - 12
= -23
4(-8) + 5(6) - 2(5)
= -32 + 30 - 10
= -12
4(4) + 5(7) -2(-1)
= 16 + 35 + 2
= 53
4(-3) + 5(2) -2(4)
= -12 + 10 - 8
= -10

So, the final product is

  25 -5 -13 5  
  -23 -12 53 -10  

Matrix Multiplication is not Commutative

Note that the multiplication is not defined the other way. You can not multiply a 3x4 and a 2x3 matrix together because the inner dimensions aren't the same.

This product is undefined.

 [[1,-8,4,-3], [-3,6,7,2], [6,5,-1,4]] * [[1,-2,3], [4,5,-2]]