Background of the problem: A patient takes a drug every $X$ hours with a half-life of $Y$ hours. How much of the drug will be (exactly) in his system after $h$ hours? For $X=24$, and $Y=24$ I made the following function showing the concentration of the drug for the first 96 hours.
Clear[m]
m[h_] := Exp[-(h/48)] /; h < 24
m[h_] := Exp[-(h/48)] + Exp[-((h - 24)/48)] /; ( h >= 24 && h < 48)
m[h_] := Exp[-(h/48)] + Exp[-((h - 24)/48)] +
Exp[-((h - 48)/48)] /; ( h >= 48 && h < 72)
m[h_] := Exp[-(h/48)] + Exp[-((h - 24)/48)] + Exp[-((h - 48)/48)] +
Exp[-((h - 72)/48)] /; ( h >= 72 && h < 96)
m[h_] := Exp[-(h/48)] + Exp[-((h - 24)/48)] + Exp[-((h - 48)/48)] +
Exp[-((h - 72)/48)] + Exp[-((h - 96)/48)] /; ( h >= 96 && h < 120)
Plot[m[h], {h, 0, 120}, AxesOrigin -> {0, 0}]
This is exactly what I want. But now I want to optimize the code, so that I can also Plot[]
for periods up to several weeks.
Question: How can I rewrite m[h]
such that there will only be one line involved, i.e. add the Exp[-((h - 72)/48]
type of terms automatically?
Piecewise[]
? $\endgroup$ – J. M.'s ennui♦ Oct 31 '12 at 10:20Exp[-Log[2] h/24]
$\endgroup$ – Simon Woods Oct 31 '12 at 13:282^(-h/24)
? :) $\endgroup$ – J. M.'s ennui♦ Oct 31 '12 at 14:17