# Webwork Workshop 2015 for Payer, Homework 1, Problem 2:
# Given the coordinates for the critical point of a general function the student
# should be able to determine the constants of the parameters for the
# function. Then evaluate the function for a specified input.
DOCUMENT();
loadMacros("PGstandard.pl",
"MathObjects.pl",
"PGML.pl");
loadMacros("contextFraction.pl");
Context("Numeric");
Context("Fraction");
$m = list_random(3,6,10,12,15,20,30);
$d = Real(random(2,10,1));
$t1 = Real(random(1,3,1));
$h = 60;
($mr,$hr) = reduce($m,$h);
$frac =Compute("$m/$h");
$k1 = Compute("$h/$m");
$a = Compute("$k1*$d");
$a1 = Compute("$k1*$d*e");
$at = Compute("$a*$t1");
$kt = Compute("$k1*$t1");
$kt1 = Compute("1-$kt");
$ktn = Compute("$kt-1");
$ans2 = Compute("$at/(e**($ktn))");
Context()->variables->add(A=>"Real");
Context()->variables->add(k=>"Real");
Context()->variables->add(t=>"Real");
TEXT(beginproblem());
BEGIN_PGML
The concentration of a particular drug within the bloodstream can be determined by the function: [``C(t) = Ate^{-kt}``], where t is the number of hours since the drug was ingested orally and [`C(t)`] is the concentration of the drug in micrograms per ml of blood. Given that [`A`] and [`k`] are both positive constants.
1. Given that the maximum concentration of [$d] occurs [$m] minutes after ingesting the drug, find the value of [`A`] and [`k`].
[`k`] = [_____]{("60/[$m]")}
[`A`] = [_____]{("60*[$d]*e/[$m]")}
2. What is concentration of the drug in the bloodstream [$t1] hours after its ingestion?
[`C([$t1])`] = [________]{Compute("(60*[$d]*[$t1]*e**{1-60*[$t1]/[$m]})/[$m]")}
END_PGML
BEGIN_PGML_SOLUTION
*SOLUTION*
1. The maximum concentration of the drug will occur at a critical point because the drug must increase from zero at ingestion and reach a peak value and then gradually dissipate as the body breaks it down. Then the given information yields
two equations both of which can be used to solve for [`k`] and [`A`]. The two equations
are: [`C(\text{c.p.}) = [$d]`], and [`C'(\text{c.p.}) = 0`], where c.p. = critical point. Recognize that the
time in minutes at the maximum concentration must be converted into hours: So t = [$m] minutes = [``\frac{[$m]}{60} = [$frac]``] hours. Then we will use
C[``\left([$frac]\right) = [$d]``] and [``C'\left([$frac]\right) = 0``] to solve for the
constants of [`k`] and [`A`].
* First apply the prime tics for the product rule and chain rule.
[``C'(t) = A(t'e^{-kt} + t(e^{-kt})'(-kt)')``]
* Take the derivative.
[``C'(t) = A(e^{-kt} -kte^{-kt})``]
* Pull the common factor of [``e^{-kt}``] and reduce.
[``C'(t) = Ae^{-kt}(1 -kt)``]
* Input [`t = [$frac]`] into the derivative and set to zero to solve for [`k`].
[``C'\left([$frac]\right) = Ae^{-[$frac]k}(1 -[$frac]k) = 0``]
* Recognize that [`A`] and [``e^{-[$frac]k}``] can not be zero as both are positive.
[``\begin{aligned}
1 -[$frac]k &= 0 \\
[$frac]k &= 1 \\
k &= \frac{1}{[$frac]}\\
k &=[$k1]
\end{aligned}``]
* We can now substitute [`k = [$k1]`] into the general equation of [``C(t) = Ate^{-kt}``] and use [``C\left([$frac]\right) = [$d]``] to solve for [`A`].
[``\begin{aligned}
C\left([$frac]\right) &= A([$frac])e^{-3\left([$frac]\right)} = [$d]\\
A([$frac])e^{-1} &= [$d]\\
\frac{A}{[$k1]e} &= [$d]\\
A &= [$a]e \\
A &= [$a1]
\end{aligned}``]
* Substituting both [`k = [$k1]`] and [`A = [$a]e`] values into the general equation yields the specific equation for the blood concentration:
[``\begin{aligned}
C(t) &= Ate^{-kt}\\
&= [$a]ete^{-[$k1]t}
\end{aligned}``]
* Combine the common base of e using the rule of exponents to reduce:
[``C(t) = [$a]te^{1-[$k1]t}``]
2. Evaluate [``C(t)``] at [``t = [$t1]``] hours to determine the concentration of the drug in the blood stream. We use the reduced form:
[``\begin{aligned} &\\
C([$t1]) &= [$a]([$t1])e^{1-[$k1]([$t1])}\\
& = [$at]e^{1-[$kt]}\\
& = [$at]e^{[$kt1]}\\
& = \frac{[$at]}{e^{[$ktn]}}\\
& = [$ans2]
\end{aligned}``]
END_PGML_SOLUTION
ENDDOCUMENT();