Modelling Caffeine Concentration in Blood

Translate to FA

1. The Story Behind This Little Project

I used to drink coffee regularly about 2 to 3 cups a day. I had a horrible sleep schedule and was sleepy throughout the day. At some point I decided to fix this and tried really hard for it. Unfortunately it didn't work and I started to look for the reason. I figured it was the coffee and tried to quit it but because of my dependence on it I regularly got sleepy and tired so I went back to coffee.

I vaguely remember hearing quitting addiction takes time and one should lower the doses they take little by little. Since caffeine is a drug I assumed that's how it works with it. I knew from experience that the effects of caffeine hit in about 20-30 minutes and pretty much go away in 4-5 hours. I decided to look it up and try to dose my caffeine in a way to keep its effects unchanged throughout the day and lower the overall dose little by little so I don't experience the heavy tiredness that comes in 4-5 hours after drinking it.

After some research I ended up at this Wikipedia article It helped as a starting (and ending to be honest) point to model the caffeine concentration in my blood. I'll tell you how I did this computation.

2. The Physics (?) Behind it

I'm not sure in which category (chemistry, biology?) the science behind this phenomenon is but I don't think it matters because nature is nature and we need to use whatever we can to understand it.

As you might've realized when you read that Wikipedia article, it's quite simple to model the concentration of most matters in our blood. In the case of caffeine there are 3 places that it goes:

  1. The Digestive System: Where it goes in.
  2. The Circulatory System: Where it does its magic.
  3. THe Urinary System: Where it goes out.

If we know at what rate the caffeine we ingest goes into the blood and at what rate it exits the blood we can calculate its concentration! The rate at which it enters and leaves depends on its concentration on both sides (where it is and where it wants to go. eg from the digestive system to the circulatory system or from the circulatory system to the urinary system); However for a simple estimate we don't really need that and we can assume it only depends on the concentration of where it is

.

3. The Solution

From some googling (I don't remember where I found this data) I found out that we absorb 99% of the caffeine we drink in 30-45 minutes and lose half of it in 4-6 hours (Mind that these are average values and could vary from person to person). So using this data we can write the dynamics of our system:

\begin{gather} \frac{dN_{\text{gut}}}{dt} = -\tau_{in} N_{\text{gut}},\\ \frac{dN_{\text{bladder}}}{dt} = \tau_{out} N_{\text{blood}}\\ \therefore \frac{dN_{\text{blood}}}{dt} = -\frac{dN_{\text{gut}}}{dt} - \frac{dN_{\text{bladder}}}{dt}. \end{gather}

From here on we can simply use the Euler method to find its concentration in blood! I've already written the code. It's here. Please let me know if something could've been done better.

Date: 2025-09-11 Thu 00:00

Created: 2026-04-20 Mon 21:13