# Hi First Post, with a weight loss math question, sliding scale

#### larswik

Hello, My name is Lars. I am 42 years young and starting a career change in my life. I started to take some programming classes last year and next year will start to take some math classes to help me grow. I have a program that I am working on and the math is a bit beyond me still. So I thought I would ask and see if anyone could help me reason this out.

The program is for weight loss and tells the user how many calories he should eat every day to loose weight and find how many seconds it takes to burn a calorie. Taking my age, weight and height I should consume 2762 calories a day to maintain my weight level. There are 86,400 seconds in a day and when I dived that by my total calorie useage I burn 1 calorie every 31.1913 second on average. If I want to loose 4 pounds a month (4weeks or 28 days) I would reduce that number by 500 calories to 2262 calories per day. The equation below gives me the calories a person should burn, which works fine for starting weight, age and height.

maleAgeMultiplier = 6.8;
maleHeightMultiplier = 12.7;
maleWeightMultiplier = 6.23;

maleBRMTotal = (66 + ((height * maleHeightMultiplier) + (weight * maleWeightMultiplier)) - (age * maleAgeMultiplier));
Now here is the problem... It estimates what the user should have lost giving the time, in seconds, since the program was started. Lets say 1 week exactly 604800 seconds, this is taking in to effect no food eating for this example and a starting weight of 260.0 pounds using 2762 calories per day.
5.54 lbs total loss = ((2762 calories per day * 7 days) / 3500 calories to a pound);
By the end of this week, and not eating any food the body weight would be 254.46 (254.5 lbs). But as the user looses weight the body uses less calories. Buy the time he lost 5.5 lbs his new body calorie needs are now 2721, 41 calories less then then 2762 he needed with the 260.0 starting body weight.

I need to find the mathematical equation for this sliding scale? He really did not loose 5.54 pounds because as he got close to that new weight his body needed less calories daily and should be slightly heavier.

I hope I explained my problem well enough. Any help would be appreciated in solving this.

Thanks!

#### MarkFL

If I read this correctly, you are going to need a first order linear differential equation to model weight as a function of time. We may express this as the initial value problem:

$$\displaystyle \frac{dw}{dt}=\frac{I-O(w(t))}{3500}$$ where $$\displaystyle w(0)=w_0$$

where:

$$\displaystyle w(t)$$ is weight as a function of time $$\displaystyle t$$.

$$\displaystyle I$$ is daily caloric intake (assumed constant).

$$\displaystyle O(w(t))$$ is the caloric expenditure as a function of weight (for simplicity, height and age are held constant).

We have:

$$\displaystyle O(w(t))=k_1+k_2w$$

where the constants $$\displaystyle k_i$$ are:

$$\displaystyle k_1=66+\text{height} \cdot \text{maleHeightMultiplier}- \text{age} \cdot \text{maleAgeMultiplier}$$

$$\displaystyle k_2=\text{maleWeightMultiplier}$$

Letting:

$$\displaystyle k_3=\frac{I+k_1}{3500}$$

$$\displaystyle k_4=-\frac{k_2}{3500}$$

we have:

$$\displaystyle \frac{dw}{dt}+k_4w=k_3$$

Multiplying through by $$\displaystyle e^{k_4t}$$ we have:

$$\displaystyle e^{k_4t}\frac{dw}{dt}+k_4e^{k_4t}w=k_3e^{k_4t}$$

$$\displaystyle \frac{d}{dt}\left(e^{k_4t}w \right)=k_3e^{k_4t}$$

$$\displaystyle e^{k_4t}w=\frac{k_3}{k_4}e^{k_4t}+c_1$$

$$\displaystyle w=\frac{k_3}{k_4}+c_1e^{-k_4t}$$

Using the initial conditions, we find:

$$\displaystyle c_1=w_0-\frac{k_3}{k_4}$$ and so:

$$\displaystyle w(t)=\frac{k_3}{k_4}+\left(w_0-\frac{k_3}{k_4} \right)e^{-k_4t}$$

1 person

#### larswik

Hi Mark. Thanks for the equation, boy did I ask for it I am able to follow that about 1/2 way and then I get lost. I will sit down tomorrow night and see if I can't break that down. Next year I will be starting out with Algebra at city college. Way back in high school I finished off with pre-algebra about 24 years ago. I developed a love for programming but the more I learn math skills are a must. It is getting frustrating wanting to do more but not having the skills yet to meet those goals. I was not expecting an equation that complex. Thank you though and I will see if I can't break that down in to what I need to add to my program.

Thank you.

#### MarkFL

I got into math as a programmer back when personal computers were relatively new, and quickly realized I would be a much more efficient programmer if I knew some math. Once I began to learn some, I was hooked!

If you need any assistance in implementing this into your code, I will be glad to help, although my programming skills are a bit rusty now.

#### larswik

Thanks Mark. I think this site will come in handy as I start my math classes. I started with a basic programming class (Pascal) and got hooked. Then to C, java and Objective C for the mac. But like you I am realizing that math skills are essential to progress in this environment with OpenGL and further. I want to try an figure this out my self but sometimes I need a push to get me thinking in the right direction. I do have 1 last question. The equations you posted above, at what math skill level is that. I am guessing I will be in pre algebra again and then progress from there. I am guessing that that is advanced algebra?

#### MarkFL

A problem like that is typically encountered in ordinary differential equations, which is taken after the freshman/sophomore calculus sequence, although some programs may expose you to such equations during the calculus sequence itself.