Matrix-matrix multiplication example

I wanted to create notes for matrix-matrix multplication so I will always have it in my backpocket - but obviously writing an example from scratch will take some time so it makes sense to use LLMs to generate it - but I wanted the example to be based on an existing example that is human-generated. This example is from Andy Math’s YouTube channel.

But also - why matrix-matrix multiplication? In part because I have no trouble computing Vector-vector multiplications or matrix-vector multiplications after a long time of not looking at them, but this is not the case for matrix-matrix multiplications. Example

Example of matrix multiplication using apples, oranges, and pears with rows representing Monday to Wednesday, and columns representing cost and weight.

Table A

Day
Apples
Oranges
Pears
Monday
10
5
8
Tuesday
7
12
6
Wednesday
15
9
11

Table B

Fruit
Cost ($/fruit)
Weight (kg/fruit)
Apples
2.00
0.20
Oranges
3.00
0.30
Pears
2.50
0.25

Matrices

Let's define two matrices:

  • Matrix A (3x3): Fruit type as columns (Apple, Orange, Pear) and Day of Week as rows (Mon, Tues, Wed)
A=[1058712615911]A = \begin{bmatrix} 10 & 5 & 8 \\ 7 & 12 & 6 \\ 15 & 9 & 11 \end{bmatrix}
  • Matrix B (3x2): Features as columns (cost and weight) and Fruit type as rows (Apple, Orange, Pear)
B=[20.230.32.50.25]B = \begin{bmatrix} 2 & 0.2 \\ 3 & 0.3 \\ 2.5 & 0.25 \end{bmatrix}

Matrix Multiplication

The resulting matrix AB = A × B will be a 3x2 matrix, where each row represents a day, and the columns represent the total cost and total weight for that day.

AB=A×B=[1058712615911]×[20.230.32.50.25]AB = A \times B = \begin{bmatrix} 10 & 5 & 8 \\ 7 & 12 & 6 \\ 15 & 9 & 11 \end{bmatrix} \times \begin{bmatrix} 2 & 0.2 \\ 3 & 0.3 \\ 2.5 & 0.25 \end{bmatrix}

Linear Equations

The linear equations for each element of the resulting matrix C are:

  1. For Monday (first row of C):
    • Total Cost: 10(2) + 5(3) + 8(2.5) = 20 + 15 + 20 = 55
    • Total Weight: 10(0.2) + 5(0.3) + 8(0.25) = 2 + 1.5 + 2 = 5.5
  2. For Tuesday (second row of C):
    • Total Cost: 7(2) + 12(3) + 6(2.5) = 14 + 36 + 15 = 65
    • Total Weight: 7(0.2) + 12(0.3) + 6(0.25) = 1.4 + 3.6 + 1.5 = 6.5
  3. For Wednesday (third row of C):
    • Total Cost: 15(2) + 9(3) + 11(2.5) = 30 + 27 + 27.5 = 84.5
    • Total Weight: 15(0.2) + 9(0.3) + 11(0.25) = 3 + 2.7 + 2.75 = 8.45

The resulting matrix AB will be:

C=[555.5656.584.58.45]C = \begin{bmatrix} 55 & 5.5 \\ 65 & 6.5 \\ 84.5 & 8.45 \end{bmatrix}

This matrix shows the total cost (in dollars) and total weight (in kilograms) of fruits for each day from Monday to Wednesday.

Footnotes:

  1. Original example is from Andy Math: Andy Math Matrix Multiplication Real World ExampleAndy Math Matrix Multiplication Real World Example
  2. The notes above are AI-generated using Perplexity