3. Drug Absorption¶
When a drug is administered to a pacient it follows a process of progressive absorption in the patient’s body. Its concentration increases each day according to a model that depends on the concentration of the drug in the body that day n (\(y_n\)), the absorption rate (\(k\)) and the initial drug concentration (\(y_0\)).
\[\begin{aligned} y_{i+1} &= y_i + k \cdot y_i \cdot (1 - y_i), \quad i>=1 \end{aligned}\]
For example, \(y_0 = 0.4\) and \(k = 0.5\) the first terms of the succession are:
\[\begin{split}\begin{align*} y_0 &= 0.4 \\ y_1 &= 0.52 \\ y_2 &= 0.6448 \\ y_3 &= 0.7593164800000001 \\ \end{align*}\end{split}\]
The concentration is considered stable when the drug concentration is equal to the previous day under the given tolerance.
You are asked to deliver the folowing function in the drug_abs module (drug_abs.py file):
- drug_abs_days(y0, k, eps)¶
For example:
>>> drug_abs_days(0.4, 0.5, 0.1)
4
>>> drug_abs_days(0.4, 0.5, 0.01)
9
>>> drug_abs_days(0.4, 0.5, 0.001)
12
Doctests are available in the file drug_abs_days.test.