How do I figure out how much of each food hits my protein, carbs, and fat?

Each nutrient gives one equation, and each food's servings is one unknown. Put each food's protein, carbs, and fat in a column of a 3×3 matrix and solve A·x = b by elimination. For 40 g protein, 60 g carbs, and 15 g fat, that's about 1.1 servings of chicken, 1.3 cups of rice, and 0.8 tablespoons of olive oil.

050100grams56 gprotein94 gcarbs33 gfat2 × salmon2 × rice0.52 × peanut butter
Servings of food 1
1.99
Servings of food 2
2.01
Servings of food 3
0.522

Challenge: Get 50 g of protein or more without any food going over 3 servings. Done!

Works best with one food high in protein, one in carbs, and one in fat.
Grams for this meal.
Grams for this meal.
Grams for this meal.

Play

Load lunch, then raise the fat target and watch the olive oil grow. Try swapping in peanut butter.

Challenge: Get 50 g of protein or more without any food going over 3 servings. The box under the picture turns green when you get it.

Stuck? Pick one of the examples from the “Try an example” menu, or press “New example.”

Understand

Ax=bA\mathbf{x} = \mathbf{b}

Each nutrient is one equation. For protein:

p1x1+p2x2+p3x3=Pp_1x_1 + p_2x_2 + p_3x_3 = P

where p1p_1 is the protein in one serving of food 1 and x1x_1 is how many servings you eat. Stack the three equations and you get a matrix equation, Ax=bA\mathbf{x} = \mathbf{b}. Elimination clears the matrix step by step until each unknown pops out.

The bars show where each gram comes from. The black line on each bar is your target.

Use

Every input has a unit menu, so you can type values in the units you already have. Results follow your units.

Show the work

  1. One column per food (salmon, rice, peanut butter), one row per nutrient\begin{bmatrix} 22 & 4.3 & 7 \\ 0 & 45 & 7 \\ 12 & 0.4 & 16 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 56 \\ 94 \\ 33 \end{bmatrix}
  2. Augmented matrix: coefficients | targets\left[\begin{array}{ccc|c} 22 & 4.3 & 7 & 56 \\ 0 & 45 & 7 & 94 \\ 12 & 0.4 & 16 & 33 \end{array}\right]
  3. Clear column 1 below the pivot (row operations)\left[\begin{array}{ccc|c} 22 & 4.3 & 7 & 56 \\ 0 & 45 & 7 & 94 \\ 0 & -1.95 & 12.2 & 2.45 \end{array}\right]
  4. Clear column 2 below the pivot (row operations)\left[\begin{array}{ccc|c} 22 & 4.3 & 7 & 56 \\ 0 & 45 & 7 & 94 \\ 0 & 0 & 12.5 & 6.52 \end{array}\right]
  5. Back-substitute from the bottom row upx_1 = 1.99,\ x_2 = 2.01,\ x_3 = 0.522

Export

Export PDF

Pick three foods and set your targets in grams.

  • Nutrition values are typical label numbers. Brands, cooking, and portion sizes vary.

For learning and estimation. Verify with applicable codes, standards, and a qualified professional before using in design, construction, or safety-critical work.

Cheat card

Ax=bA\mathbf{x} = \mathbf{b}
protein: p1x1+p2x2+p3x3=P\text{protein: } p_1x_1 + p_2x_2 + p_3x_3 = P
SymbolMeaningUnit
AAnutrients per serving, one column per foodg
x\mathbf{x}servings of each food
b\mathbf{b}your targetsg
  • Pick foods with different strengths, one high in protein, one in carbs, and one in fat.
  • A negative answer means these three foods can't reach the target mix.
  • Two foods with the same mix leave you one equation short.

Print this card

Where it’s used

  • Medicine & Health
    Dietitians build meal plans that hit nutrient targets from a few foods.
  • Biology
    Animal feed and fertilizer blends are solved the same way, for protein or nitrogen, phosphorus, and potassium.
  • Cooking
    Plan a meal-prep lunch that lands on your macros without guess-and-check.

Questions people ask

Why do I need three foods for three targets?

Each target is one equation. With two foods you have two unknowns for three equations, which usually can't all be met. Three foods give exactly enough freedom.

What if the answer says a negative serving?

The target mix is outside what those three foods can make. Swap one food for something that brings more of the missing nutrient.

How does elimination work?

Subtract multiples of one row from the others to clear numbers below the diagonal, then solve the last equation and work back up. The work steps show each stage.