## PREP 2015 Question Authoring - Archived

### Errors resulting from variable assignments using base e.

by tim Payer -
Number of replies: 1
Hello all,

I ran into a curious error that involves using the constant of base e in variable assignments.  I experimented and ran through a number of combinations to try and reproduce variants of the error and variants of accepted forms. Both are posted below along with the original problem. A fellow teacher, Tim Lauck, who is taking the System Administrator course for Webwork next month prompted me to follow up in the forum for the source of the error. He suspects it is likely a syntax error for PERL??

Issues with exponential base e:

Forms that are accepted using base e:

$a1 = Compute("$k1*$d*e");$a1 = ($k1*$d*(e));

$a1 = Compute("$k1*$d*exp(1)");$a1 = ($k1*$d*(e)**1);

$a1 = ($k1*$d*(e**1));$a1 = ($k1*$d * e); # space on either side of operator

$a1 = ($k1*$d* e); # space before e Forms that create an error using base e:$a1 = ($k1*$d*e);    # See Payer Problem 2

$a1 = ($k1*$d*e**1); # See Payer Problem 2$a1 = ($k1*($d)*e);   # See Payer Problem 2

$a1 = ($k1*($d*e)); # See Payer Problem 2$a1 = ($k1*$d *e);  # See Payer Problem 2

With these error messages:

### Warning messages

• Operator or semicolon missing before *e at line 24 of (eval 23395)

• Ambiguous use of * resolved as operator * at line 24 of (eval 23395)

# 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();
"MathObjects.pl",
"PGML.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(); In reply to tim Payer ### Re: Errors resulting from variable assignments using base e. by Davide Cervone - In your list of expressions that are accepted, only the two assignments that involve Compute() actually produce what you are looking for. They others may not produce an error message, but they don't compute the correct value. That is because e is not a predefined value in Perl, and so it is treated as an unquoted string. In some situations, that string is converted to a number by turning it into a zero, but in other cases, it causes a syntax error. But even when it doesn't the answer you get won't be what you expect. Only inside a Compute() string is e defined as you would expect. We will talk more about these issues on Monday. In perl code, you could do e = exp(1);
$a = ($k1*$d*$e);

for example. There is also a constant \$E defined by PG that you could use (if you don't mind the capitalization difference).