Tuesday, March 3, 2015

Engineering Your Body: Macrobatics and Linear Algebra

One thing I've always been skilled at is looking at problems, finding out ways to represent them numerically, and then solving them. As a mechanical engineering student, I've become a lot more proficient at it. So I'm bringing you the Engineering Your Body series, about how to streamline your fitness with a bit of math.

The following scenario is not uncommon: I come home from school, and during the ride home I've been thinking about dinner. I have 18g fat, 44g carbs and 60g protein left in my macro allowance. I feel like eating something vaguely Mexican tonight, so I've decided on some chicken breast, brown rice and guacamole. The question of the day is, how do I decide how much of each to eat?

That's where linear algebra comes in. Linear algebra is a field of math that's primarily focused on solving systems with multiple equations with multiple variables. What I'm going to focus on now is pretty basic, it's actually stuff I've been doing since 8th grade, but using some tools to make the whole process easier.

So, first we collect our foods and read the labels.
Chicken breast (4oz/112g): 2g fat, 0g carbs, 24g protein
Brown Rice (0.25c/42g): 1g fat, 32g carbs, 3g protein
Guacamole (2T/30g): 4.5g fat, 2.5g carbs, 1g protein

First, you set up your system of equations. Using C to represent a serving of chicken, R for a serving of rice, and G for a serving of guacamole, you get

Fat: 2C + 1R + 4.5G = 18
Carbs: 0C + 32R + 2.5G = 44
Protein: 24C + 3R + 1G = 60

Which, converted to matrix form, looks like this:

Now, I'm guessing that unless you've taken a fair amount of college level math, that baffles you a bit. That's ok. You'll notice in the first matrix, each column represents a different food, each row represents a different macro. All we have to do is convert that to an augmented matrix and perform Gauss elimination. I'll teach you how to do that, even if you have no idea what that means.

Step 1: Go to http://www.WolframAlpha.com
Step 2: Enter the following formula: rowreduce[{{F1, F2, F3, FT}, {C1, C2, C3, CT}, {P1, P2, P3, PT}}]

Where F1 is the grams of fat in ingredient 1, CT is your target carbs... I'm sure you can figure the rest out. For my example, my input was rowreduce[{{2,1,4.5,18},{0, 32, 2.5,44}, {24, 3, 1,60}}]

Step 3: Read the results.
The ones and zeroes on the left are what's called an identity matrix. You can ignore that for the time being, it's the column on the right we care about. What it tells us is, from top to bottom, how many servings of chicken, rice, and guacamole I should be consuming. So, looks like what I need is about 9oz chicken, 50g rice, and 5.5 T guacamole.

Now, to address a couple weaknesses in the system. For one, it only can calculate exactly 3 ingredients: 1 per macro. If you wanted to add extra parameters in there like fiber or sugar, you could add extra ingredients. My personal recommendation is just to pick ingredients off the list, add whatever quantity you deem appropriate, and then subtract it from your target macros. Maybe I want to add some cheese to this.

 Shredded Cheddar (0.25c/28g): 8g fat, 1g carbs, 6g protein.

I've decided that I want 1 serving of cheese. So, my new target macros are 10g fat, 43g carbs, and 54g protein.

If you're good with linear algebra, you can do this by hand and come up with a family of solutions: Basically meaning that there's no single answer, but that how much of one ingredient you use is dependent on how much of other ingredients you use. It's basically the same thing I suggested before, but a little more systematic.

Second thing is, you have to pick ingredients that you reasonably think you actually can fill your macros with. I picked some easy ingredients: chicken is high in protein, rice is high in carbs, guacamole is high in fat. But, hypothetically, let's take rice out and replace it with cheese. Our new results look like this.
The fact that one of the answers is negative means you can't make these ingredients work. Basically, guacamole has become our primary carb source. To get enough carbs from the guacamole puts us way over our fat target, so you have to compensate by eating negative cheese. I don't know about you, but I can't just vomit cheese at will.

No comments:

Post a Comment