Differential Equations (Coffee) This is a long post so bear with me until I get to the part where I am stuck on! :)


Question: The author of a popular detective novel drinks black coffee to help him stay awake while writing. After he drinks each cup of coffee, $20mg$ of a substance called caffeine enters his bloodstream. There it is gardually broken down and absorbed according to the D.E $\frac{dC}{dt}=-0.3C$ where $C$ is the amount of caffeine (in $mg$) in the bloodstream at time $t$ and $t$ is the time in hours after each drink.
(a) If he drinks one cup of coffee, how much caffeine will remain in his blood after $2$ hours?


I solved this as such:
$$ \frac{dC}{dt}=-0.3C$$
$$ \Leftrightarrow \int \frac{1}{C} ~dc = \int -0.3 ~ dt $$
$$ \Leftrightarrow \ln|C| = -0.3t + C $$
$$ \Leftrightarrow C = Ae^{-0.3t} $$
At $t=0$ , $C=20$ , $\therefore A =20$
$$ \Longrightarrow C=20e^{-0.3t}$$
At $t=2$ 
$$ C = 20e^{-0.6}~mg$$
This is the part of the question where I am stuck on now:


(b) One evening he decides to stay awake all night and finish an entire chapter, which takes ten hours to write. To do this he uses the following strategy. 
Step $(1):$ Begin with one cup of coffee
Step $(2):$ Wait until he begins to feel drowsy (occurs when caffeine level drops to $12mg$), then drink another cup of coffee. Wait until he feels drowsy again, (that is , his caffeine  level falls to $12mg$), then drink another cup; and so on. 
$(i)$ How many cups of coffee will he drink during the night?
$(ii)$ What will his caffeine level be when he finishes the chapter?


The only progress I have gotten on this part of the question is that when $C=12mg$ then $t=\frac{-\ln(0.6)}{0.6} \approx 0.85 hrs$ but not sure how to continue this because at that time $0.85$ hrs that is when his caffeine level is at 12mg do I just divide 10 hrs by this and calculate the cups of coffee or is ther more to it.. I am stuck on how to answer part(i) and (ii)...
 A: It be something like find the time it takes for C to go from 20->12 in the first bout t1 and then 32 to 12 t2 using (0,32) as the initial condition. Then it would be t1+n*t2 = 10hr. Solve for n and round down to find how many cups and add one for t1. This is because it will always go in the pattern 20->12, then 32->12 until end. Thus your differential equations are representative of either a start of 20 mg or 32 mg.
That may be a start for part 1
For part 2 you can go from here using the remainder time solving for C from the eq representative of (0,32) since that is what is being represented during the extent of 10 hrs.
A: Notice that just because the writer begins another cup, it doesn't mean that there is no caffeine in him. In fact, when he begins cup #2, the writer will have $12 + 20 = 32$ milligrams of caffeine in his system. As you can see, it will take longer after he drinks the second cup before he becomes drowsy again.
To be honest, you can just do the calculations manually (without the aid of special functions) for each cup of coffee the writer drinks. As you have shown in your problem statement, it will take about $0.86$ hours before the writer becomes drowsy. Now solve the equation using $C|_{t = 0} = 32$ as the initial condition, and solve for time. Keep doing this until the total time is greater than $10$ hours.
A: The general solution to $$\frac {dC}{dt}=-0.3C$$
is $$C_t=C_0e^{-0.3t}$$ 
which is the same as
$$t=-\frac 1{0.3} \ln \left(\frac{C_t}{C_0}\right)=\frac 1{0.3}\ln\left(\frac{C_0}{C_t}\right)$$
Apply this for each cup of coffee consumed. 


*

*First cup:    $\;\;\quad C_0=20,\quad\quad \quad \;\;\;\ C_t=12 \Rightarrow t=1.7028$.

*Second cup: $\;\;\ C_0=20+12=32, C_t=12 \Rightarrow t=3.2694$.

*Third cup: $\;\;\; \;\; C_0=20+12=32, C_t=12 \Rightarrow t=3.2694$.

*Fourth cup: $t=10-1.7028-3.2694-3.2694=1.7584\Rightarrow C_t=32e^{-0.3(1.7584)}=18.882$


Hence answers are:  
(i) $4$ cups
(ii) $18.88$mg
