PREP 2015 Question Authoring - Archived

random variable list reads "1" as a default value?

random variable list reads "1" as a default value?

by tim Payer -
Number of replies: 2
I have used the list_random( ) command to declare specific values for a variable but upon execution this value is assigned a default value of 1 and the value of 1 isn't even in my list of values. This of course throws off all calculation of correct answers. I am assuming that this is a simple syntax error and that

The variable and command is:
$m = list_random(3,6,10,12,15,20,30);

Can you see my error? I have highlighted the line in purple below.
Thanks for any insight, Tim

# 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");

Context("Numeric");

$m = list_random(3,6,10,12,15,20,30);
$d = Real(random(2,10,1));
$t1 = Real(random(1,3,1));
$h = 60;
($m,$h) = 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 = [_____]{Compute("60/[$m]")}

   A = [_____]{Compute("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(c.p.) = [$d], and C'(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.

1a)  First apply the prime tics for the product rule and chain rule.

[``C'(t) = A(t'e^{-kt} + t(e^{-kt})'(-kt)')``] 

1b) Take the derivative.

[``C'(t) = A(e^{-kt} -kte^{-kt})``] 

1c)  Pull the common factor of [``e^{-kt}``] and reduce.

[``C'(t) = Ae^{-kt}(1 -kt)``]     

1d)  Input t = [$frac] into the derivative and set the derivative to zero to solve for k.

[``C'\left([$frac]\right) = Ae^{-[$frac]k}(1 -[$frac]k) = 0``]     

Recognize that A and [``e^{-kt}``] can not be zero as both are positive.

[``1 -[$frac]k = 0 ``]    

[``[$frac]k = 1``]

[``k = \frac{1}{[$frac]}=[$k1]``]

1e)  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.

C[``\left([$frac]\right) = A([$frac])e^{-3([$frac])}``] = [$d] to solve for A.

 [``A([$frac])e^{-1}``] = [$d]

[``\frac{A}{[$k1]e}``] = [$d]

A = [$a]e = [$a1]

1f)  Substituting both k and A values into the general equation 

yields the specific equation for the blood concentration:

[``C(t) = [$a]ete^{-[$k1]t}``]

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:

[``C([$t1]) = [$a]([$t1])e^{1-[$k1]([$t1])}``]

[``C([$t1]) = [$at]e^{1-[$kt]}``]

[``C([$t1]) = [$at]e^{[$kt1]}``]

[``C([$t1]) = \frac{[$at]}{e^{[$ktn]}}``]

[``C([$t1]) = [$ans2]``]


END_PGML_SOLUTION

ENDDOCUMENT();
In reply to tim Payer

Re: random variable list reads "1" as a default value?

by Paul Pearson -
Hi Tim,

You're defining $m 

$m = list_random(3,6,10,12,15,20,30);

and then overwriting $m a few lines later via

($m,$h) = reduce($m,$h);

You should use something like

($m_reduced,$h_reduced) = reduce($m,$h);

and then use the reduced values $m_reduced and $h_reduced later only when you want them.

Best regards,

Paul Pearson
In reply to tim Payer

Re: random variable list reads "1" as a default value?

by Davide Cervone -
Paul has beaten me to it again, and has correctly identified the problem. But I also wanted to give you some formatting advice, so am responding as well.

First, you have broken your opening paragraph into several shorter paragraphs (each line is a separate paragraph because of the blank lines in between). This might format OK on your screen, but for the (growing number of) people using handheld devices for doing their WeBWorK assignments, you are likely to get some very bad line breaks. It is best to let the browser do the line breaking rather than force paragraph breaks within the middle of a sentence.

Second, you have hand numbered your lists; the formatting could be improved if you used PGML lists rather than these "fake" lists. To do that, use 1. rather than 1.), and 2. rather than 2.), and so on.

In order to make the "k = [____]" and "A = [____]" be part of the list item in which they appear, you will need to indent them using four spaces (otherwise, they start a new paragraph, and that means the second list item will start a new list numbered starting at 1).

I recommend that you always use a math mode (TeX or algebra, it doesn't matter) whenever you refer to a variable of function name. So "find the values of A and k" should be "find the values of [`A`] and [`k`]". This will make sure the variable names are properly typeset, and appear the same in your sentences as they do in your formulas.

Finally, you don't need to use Compute() in the answers within PGML. It is allowed, but it is unnecessary, and makes things harder to read.

With these things in mind, I'd recommend your main text be formatted as follows:

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 values 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])`] = [________]{"(60*[$d]*[$t1]*e**{1-60*[$t1]/[$m]})/[$m]"}

END_PGML
You can do similar things within the solution section (I will leave that to you).

One improvement that I might suggest in the solution is to use the TeX aligned environment to handle some go your multi-line expressions. For example

[``C([$t1]) = [$a]([$t1])e^{1-[$k1]([$t1])}``]

[``C([$t1]) = [$at]e^{1-[$kt]}``]

[``C([$t1]) = [$at]e^{[$kt1]}``]

[``C([$t1]) = \frac{[$at]}{e^{[$ktn]}}``]

[``C([$t1]) = [$ans2]``]
can be replaced by
[``\begin{aligned}
  C([$t1]) &= [$a]([$t1])e^{1-[$k1]([$t1])} \\
           &= [$at]e^{1-[$kt]} \\
           &= [$at]e^{[$kt1]} \\
           &= \frac{[$at]}{e^{[$ktn]}} \\
           &= [$ans2]
\end{aligned}``]
This is a matter of knowing some more advanced TeX commands, which is really outside the scope of this course, but I thought I'd mention this one, since this is something that can simplify your solutions.