The forward problem was: eat amounts v of foods A, B, C and compute the nutrient totals Nv. This page solves the inverse problem: first choose the nutrient totals t you want for carbohydrate, fat, and protein, then ask how much of each food should be eaten. That is, solve Nv = t for the unknown v. When N is invertible, the answer is unique:
Nv = t ⇒ v = N−1t, N−1N = NN−1 = I.
Edit any entry (grams per 100 g of food). Column = food, row = nutrient.
| g per 100 g | Food A | Food B | Food C |
|---|---|---|---|
| Carbohydrate | |||
| Fat | |||
| Protein |
Slide to choose the desired total grams of each nutrient for the meal.
A 3×3 matrix is invertible exactly when det N ≠ 0, where
det N = N1,1(N2,2N3,3 − N2,3N3,2)
− N1,2(N2,1N3,3 − N2,3N3,1)
+ N1,3(N2,1N3,2 − N2,2N3,1).
Since det N ≠ 0, the inverse exists:
Here adj(N) is the adjugate matrix of N.
Feed the computed amounts back into the forward problem. Multiplying by N undoes multiplying by N−1: N(N−1t) = (NN−1)t = It = t. The target vector is recovered exactly.