Last active
November 18, 2023 13:38
-
-
Save bruno-brant/e6c89ba66b735ef473052b7ad826e45f to your computer and use it in GitHub Desktop.
Small experiment I wrote for myself to understand the concentration of molecules in the body considering their half-life and daily intake.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def concentration_after(initial_dosage, age, half_life): | |
""" | |
Age is the number of days, dosage is the amount (in mg) that was applyed at | |
the day 0 | |
:param initial_dosage: Initial dosage | |
:param age: how many hours since the dosage | |
:param half_life: how many hours for a half-life of the molecule | |
""" | |
return initial_dosage * 0.5 ** (age / half_life) | |
def accumulated_concentration(daily_dosage, days, half_life): | |
""" | |
Gets the total dosage in the body after a certain number of daily intake. | |
:param daily_dosage: how much is taken each day | |
:param days: how many days have the medicine been taken | |
:param half_life: how many hours for a half-life of the molecule | |
""" | |
total = 0 | |
for age in range(days-1, -1, -1): | |
d = concentration_after(daily_dosage, age * 24, half_life) | |
total += d | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment