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.
- 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!
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
Each nutrient is one equation. For protein:
where is the protein in one serving of food 1 and is how many servings you eat. Stack the three equations and you get a matrix equation, . 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
- 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} - 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] - 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] - 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] - Back-substitute from the bottom row up
x_1 = 1.99,\ x_2 = 2.01,\ x_3 = 0.522
Export
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
| Symbol | Meaning | Unit |
|---|---|---|
| nutrients per serving, one column per food | g | |
| servings of each food | ||
| your targets | g |
- 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.
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.
Related exhibits
- Start here
Mixing solutions: how much of each?
Two strengths, one target. Two equations tell you exactly how much of each to pour.
- Start here
Phone plans: finding the break-even point
Two plans, two lines. Where they cross, the price is the same.
- Go further
How search ranks pages: links as votes (PageRank)
A link is a vote, and votes from important pages count more. Repeat until it settles and you get PageRank.
- Also try
Scaling a recipe: more people, same taste
Double the guests? Every ingredient grows by the same factor.
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.