How do you calculate how long until a drug reaches its steady state? I encountered a mathematically intriguing conundrum, in that it's related to medicine but is centered around mathematics.
Suppose drug A has a half-life in the body of 30 hours. The patient takes 40mg once per day. How long is it then until the patient then reaches steady-state dosage in the body (within some tolerance interval)?
The answer should be about one week, but I'm trying to understand the math behind "why".
 A: Imagine you have always been taking this drug. That means at the beginning of each day after you take the drug, the total concentration of the drug will be the concentration from today's drug (let's call it $C_0$), plus what is left from yesterday, $C_0 \times 2^{-(24\, hr)/(30\, hr)}$, plus what is left of day before, $C_0 \times 2^{-(48\, hr)/(30\, hr)}$ and so on:
$$
C = \sum_{k=0}^\infty C_0\times2^{-k\,(24\, hr)/(30\, hr)} = \frac{C_0}{1-2^{-24/30}},
$$
where I used the geometric series to evaluate the sum, $\sum_0^\infty x^k = \frac{1}{1-x}$.
Now if you have been only taking it for $n$ days, the total concentration at the beginning of the day would be
$$
C_n = \sum_{k=0}^n C_0\times2^{-k\,(24\, hr)/(30\, hr)} = \frac{1-2^{-n\times24/30}}{1-2^{-24/30}}\times C_0.
$$
Here, I used the geometric sum $\sum_0^n x^k = \frac{1-x^n}{1-x}$.
Now, you want to wait until $C_n$ is very close to $C$. Let's say $99$% close. That is $C_n/C = 99$%. That is
$$
99\%=\frac{C_n}{C} = 1-2^{-n\times24/30}
$$
or $2^{-n\times24/30}=0.01$. Taking the log from both sides and solving for $n$, we have
$$
n = \log(0.01)/\log\left(2^{-24/30}\right)\approx 8.
$$
That is, you need to wait $8$ days to get to $99\%$ of the steady-state concentration (technically you should round up and wait for $9$ days to make sure you are within $99\%$).
More generally, if you want to be within $\epsilon$ of the steady-state value (that is $1-C_n/C=\epsilon$), you have to wait for $n=\log(\epsilon)/\log\left(2^{-24/30}\right)\approx -4.15 \times \log(\epsilon)$ days.

Update - Second solution using differential equations, as suggested by the OP:
Let us approximate the intake of the drug to be uniform throughout the day (averaged over the day), then we can write the following ODE for the change in the concentration of the drug as a function of time given by the rate of intake minus decay rate
$$
\frac{dC}{dt}= \frac{C_0}{24\, hr} - \frac{\ln(2)}{30\,hr} C.
$$
(Note that the factor $\ln(2)$ is needed here because half-life time is defined as the time it takes for concentration to drop by a factor of $2$, while the decay rate is the inverse time it takes for the concentration to drop by a factor $e$. In other words $e^{-(\text{decay rate})\,t} = 2^{-t/(30\, hr)}$ or decay rate $= \ln(2)/(30\, hr)$.)
This ODE has the following solution
$$
C(t) = \frac{C_0\times (30\,hr)}{(24\, hr)\times \ln(2)} \left(1-2^{-\frac{t}{30\, hr}}\right).
$$
The concentration at the steady state is given by
$$
C_\infty \equiv \lim_{t\to\infty} C(t) =  \frac{5\,C_0}{4\ln(2)}.
$$
To find the time when the concentration gets withing $\epsilon$ of $C_\infty$ we set $(C_\infty- C(t))/C_\infty$ equal to $\epsilon$ and solve for $t$:
$$
\epsilon = \frac{C_\infty - C(t)}{C_\infty} = 2^{-\frac{t}{30\, hr}} \implies t = -(30\, hr)\log(\epsilon)/\log(2) \\= -(30/24)\log(\epsilon)/\log(2)\, \text{days} \approx -4.15\times\log(\epsilon)\,\text{days},
$$
which is exactly what we had before.
