5

I have 4 ingredients that I want to combine to prepare a drink:

                 | amount | pro | carbs | fats |
------------------------------------------------
[m]ilk           | 100ml  | 3.5 | 5.3   | 0.1  |
[o]ats           | 100g   | 11  | 62    | 7.7  |
oat[b]ran        | 100g   | 13  | 47    | 3.5  |
p[r]otein powder | 100g   | 82  | 4     | 7.5  |

and I want my drink to have 30.8g of protein, 58.97g of carbs and 12.46g of fats. Considering

  • $x$ = amount of milk, $y$ = amount of oats, $z$ = amount of oatbran, $v$ = amount of protein powder
  • $m$ = milk, $o$ = oats, $b$ = oatbran, $r$ = protein powder
  • $p$ = poteins needed in the drink, $c$ = carbs needed in the drink, $f$ = fats needed in the drink
  • $p_m$ = proteins in 100ml of milk, $c_o$ = carbs in 100 gr of oats, and so on.

this is how I'm trying to formalize the problem: $$ \left\{ \begin{array}{c} x \cdot p_m/100 + y \cdot p_o/100 + z \cdot p_b/100 + v \cdot p_r/100 = p \\ x \cdot c_m/100 + y \cdot c_o/100 + z \cdot c_b/100 + v \cdot c_r/100 = c \\ x \cdot f_m/100 + y \cdot f_o/100 + z \cdot f_b/100 + v \cdot f_r/100 = f \end{array} \right. $$

or

$$ \left\{ \begin{array}{c} x \cdot p_m + y \cdot p_o + z \cdot p_b + v \cdot p_r = p \cdot 100 \\ x \cdot c_m + y \cdot c_o + z \cdot c_b + v \cdot c_r = c \cdot 100 \\ x \cdot f_m + y \cdot f_o + z \cdot f_b + v \cdot f_r = f \cdot 100 \end{array} \right. $$

in our case

$$ \left\{ \begin{array}{c} 3.5x + 11y + 13z + 82v = 3080 \\ 5.3x + 62y + 47z + 4v = 5897 \\ 0.1x + 7.7y + 3.5z + 7.5v = 1246 \end{array} \right. $$

Furthermore, I want my drink to always have 300 ml of milk, I could remove x from the system to get

$$ \left\{ \begin{array}{c} 11y + 13z + 82v = 2030 \\ 62y + 47z + 4v = 4307 \\ 7.7y + 3.5z + 7.5v = 1216 \end{array} \right. $$

but resolving this I'm getting a negative value for z=-208.88, that is not actually an option.

Now, I've studied these kinds of problem too many years ago, I'm not being able to go any further, so I'm here to ask: is this approach totally wrong? If not, how should I proceed to get a good (or exact) approximation for the variables, excluding negative values?

Harry Peter
  • 7,819
  • the condition of $300$ml of milk is necessary, or has been added only for have a determined system? – Fernando May 18 '16 at 21:21
  • @Fernando well, it just... happened to be like that. I realized 300 ml is the right amount of liquid I like (yep, that's a real problem, my breakfast is a serious matter). What is a "determined" system? A system with the same number of variables and equations? – Luigi Cortese May 18 '16 at 21:27
  • Using linear algebra, your equality constraints can be reduced to this: $o=0.321-0.0152m,b=1.87+0.131m,r=-1.24-0.284m$. (This is rounding to three significant figures). So in fact just your equality constraints have no positive solutions. – Ian May 19 '16 at 01:03

2 Answers2

2

What you have found from your calculation is that your system of equations has no nonnegative solutions, and of course only nonnegative solutions are physically meaningful. This is not an error in your calculation. In fact, it is not even an error in the calculation with the exact constraint on the milk content removed. It is simply impossible to attain your nutrient targets with only those 4 ingredients.

Running the steps of row reduction showed me which nutrient is the problem: it is that the relative fat content of your ingredients is too low for your targets. (By the way, a fairly nice little Matlab script for this sort of thing: http://www.mathworks.com/matlabcentral/fileexchange/2168-linear-algebra-labs-with-matlab--2e/content/hill/LABBOX/rrefstep.m The only thing that annoys me about it is that there is no way to see descriptions of all the steps at the end of the procedure, though that would be an easy enough edit. Note that in my version of Matlab, I had to change all the variables named "switch" to "myswitch"; upon doing that it works great.)

To be specific, notice that the largest fat to protein ratio in your ingredients is about 0.8, the next one down is about 0.3, and then about 0.1 then about 0.03. Meanwhile your target fat to protein ratio is about 0.4. This means that just the fat to protein ratio that you want forces your drink to contain quite a bit of oats, since they are the only ingredient with a higher ratio than your target.

This would be OK except that your carb target is fairly low while the carb content of oats is quite high. In effect, your ingredients make it so that you cannot get significant fats without also getting significant carbs (from oats or oat bran) or significant protein (from protein powder). This means that you either need to change your targets or else introduce an ingredient with a higher fat content.

On the side of changing targets, you can get feasible solutions using your ingredients if you raise your carb target to be at least 90.1.

Ian
  • 101,645
0

I think more what you want is linear optimization.

You either maximize or minimize some function subject to constraints.

You have equality constraints for the protein, carb, and fat content, as well as a minimum constraint for the milk volume.

A decent tack to take would be to minimize the cost of such a meal. (You want to eat cheaply, don't you?) In this case, you'd need cost per 100 grams or ml $m_j$ for each of your ingredients.

Then the problem is formulated something like this ($x_j$ is the number of 100 ml or 100 g servings of ingredient $j$):

Minimize

$$\sum_{j=1}^4 x_j m_j$$

subject to the constraints

$$\sum_{j=1}^4 x_j p_j = 30.8$$

$$\sum_{j=1}^4 x_j c_j = 58.97$$

$$\sum_{j=1}^4 x_j f_j = 12.46$$

$$x_1 \geq 3$$

$$x_2, x_3, x_4 \geq 0$$ (ingredient 1 is milk)

John
  • 26,319