Eating a balanced diet using linear algebra

An interesting application of linear algebra is using it to find out what you need to eat to reach your nutrient goals and how much. We will assemble an augmented matrix to model this. Each row of the matrix corresponds to one equation, e.g. x+2y+3z=22. The variables x, y, and z are three types of food, the coefficients 1, 2, and 3 represent the quantity of a certain nutrient which each food contains, and 22 is the target goal. Therefore, each row will represent one nutrient, and each column will represent one food, which will contain many different nutrients.

In our example, we want to create a unique diet that will meet all of the nutrient goals, which means that excluding the target column, there will be the same number of foods as nutrients. Because almost every food has a different makeup, it will be highly unlikely for one food to have the exact same nutrients as a linear combination of the other foods. This means that due to the nature of this calculation, the columns of this matrix are nearly guaranteed to be linearly independent.

Sometimes, the reduced matrix will imply that we should eat a negative number of a certain food to meet our goals. In these cases, eating zero of that food is perfectly fine. I will use the nutrition information of several foods provided by WolframAlpha for the calculation. I will keep track of 10 nutrients in 10 foods.

The ten nutrients, from top to bottom, will be:

fat, cholesterol, sodium, carbohydrates, fiber, sugar, protein, vitamin C, vitamin A, calories

The ten foods, from right to left, will be:

1 average lemon, 1 average carrot, 85g lettuce, 1g salt, 1 steak, 30g cheddar cheese, 4g (1 pat) butter, 32g (2 tbsp) peanut butter, 50g white bread, 1 average egg

Assembling the matrix

I will use the amount in grams of each nutrient in each food, not the percent daily value, because the percentages are rounded.

WolframAlpha says that the amount of each nutrient in a lemon are:
0.25g fat, 0g cholesterol, 0.002g sodium, 8g carbohydrates, 3g fiber, 2g sugar, 1g protein, 0.081g vitamin C, 0.0000013g vitamin A, 20 calories.

Therefore the column which corresponds to a lemon will be.

[0.2500.00283210.0810.000001320]\left[\begin{array}{c} 0.25\\ 0\\ 0.002\\ 8\\ 3\\ 2\\ 1\\ 0.081\\ 0.0000013\\ 20 \end{array}\right]

Now, I will do this for each food, and write the daily values of the nutrients in the augmented column.

[0.250.0660.17502010416246500000.1470.0320.0100.00050.1210.30.0020.0260.0130.39340.1310.1860.0230.10.150.0652.3832000.3840.0037250.343300311000022025220.911000.1560.003320.2532510.279104670.037844500.0810.00270.0063000.000050000.00005800.090.00000130.0009720.00083700.000005130.0000540.0000180.0000540.000002970.0000360.0009201313037912132191135552400]\left[\begin{array}{cccccccccc|c} 0.25 & 0.066 & 0.175 & 0 & 20 & 10 & 4 & 16 & 2 & 4 & 65\\ 0 & 0 & 0 & 0 & 0.147 & 0.032 & 0.01 & 0 & 0.0005 & 0.121 & 0.3\\ 0.002 & 0.026 & 0.013 & 0.3934 & 0.131 & 0.186 & 0.023 & 0.1 & 0.15 & 0.065 & 2.3\\ 8 & 3 & 2 & 0 & 0 & 0.384 & 0.003 & 7 & 25 & 0.343 & 300\\ 3 & 1 & 1 & 0 & 0 & 0 & 0 & 2 & 2 & 0 & 25\\ 2 & 2 & 0.911 & 0 & 0 & 0.156 & 0.003 & 3 & 2 & 0.253 & 25\\ 1 & 0.279 & 1 & 0 & 46 & 7 & 0.037 & 8 & 4 & 4 & 50\\ 0.081 & 0.0027 & 0.0063 & 0 & 0 & 0.000050 & 0 & 0 & 0.000058 & 0 & 0.09\\ 0.0000013 & 0.000972 & 0.000837 & 0 & 0.00000513 & 0.000054 & 0.000018 & 0.000054 & 0.00000297 & 0.000036 & 0.0009\\ 20 & 13 & 13 & 0 & 379 & 121 & 32 & 191 & 135 & 55 & 2400 \end{array}\right]

It was difficult to find a website that would reduce a matrix with 11 columns, but eventually I found one. https://www.dcode.fr/matrix-row-echelon

This is the output it gave me. Like I expected, many rows have negative outputs. This is the “balanced diet” that the reduced matrix implies:

0.575 lemons

No carrots

948 grams of lettuce

No salt

No steak

2.04 kilograms of cheese (nearly 5 pounds of cheese!)

No butter

1.74 tablespoons of peanut butter

11 slices of white bread

7.4 eggs

It is clear that this diet is not balanced at all. The negative entries could be fixed by adding more foods, which would create free variables. Then, we could restrict the free variables to be positive only. In the future, I may post a part 2 to this post where I test that idea.


Comments

Leave a Reply