Matrix Multiplication: A Nutrition Calculator

A nutrition label is a column of numbers, and eating is a matrix multiplication. Put the labels of three foods side by side to get a 3×3 matrix N: each column is one food, each row is one nutrient (grams per 100 g of that food). If a person eats amounts vA, vB, vC (in units of 100 g), the total nutrients eaten are exactly the product

Nv  =  total grams of (carb, fat, protein),    (Nv)i = NiAvA + NiBvB + NiCvC

1. The nutrient matrix N — three food labels, side by side

Edit any entry (grams per 100 g of food). Column = food, row = nutrient.

Nutrient values in grams per 100 grams for Foods A, B, and C
g per 100 g Food A Food B Food C
Carbohydrate
Fat
Protein

2. The amount vector v — what the person eats

Slide to choose how much of each food is eaten. The vector entry is the amount in units of 100 g.

3. The product Nv — total nutrients eaten

Hover, tap, or focus a result entry to see which numbers produced it: one row of N meets the whole vector v.

N  (3×3)
·
v  (3×1)
=
Nv  (3×1)

4. Who contributed what? — the column picture

Each bar is one nutrient total, split by food. Hover or focus a segment for its term Nij · vj.

Food A Food B Food C

5. Estimated food energy from carbohydrate, fat, and protein — an inner product

Assign an energy factor (kcal/g) to each of the three nutrients. Collect these factors in a row vector c = (ccarb, cfat, cprot). The estimated energy represented by this model is the inner product of c with the nutrient-total vector Nv:  c · (Nv) = ccarb(Nv)1 + cfat(Nv)2 + cprot(Nv)3.

Energy factors in kilocalories per gram for the three nutrients
kcal per g Carbohydrate Fat Protein
c
c  (1×3)
·
Nv  (3×1)
=
kcal  (1×1)

The default entries 4, 9, and 4 are the Atwater factors.

Back to Collection