I am having a small problem with a FormulaWithUnits() application.
The correct answer is "1/A hr" but Webwork replies that:
"Your answer doesn't look like a formula with units"
The Variable "A" has been declared as a Real variable, and the second answer in this assignment has "A/e hr" as a correct answer and this problem as no such problems as the "1/A hr" answer does.
The only temporary work around is to ask the student to enter parentheses around the formula: "(1/A) hr". And with this webwork will function correctly in returning a green field for a correct answer for the student.
The code is below and the formulas are declared on lines 20 and 21.
Any help you can shed on this is greatly appreciated,
Sincerely, Tim
# Webwork Workshop for Payer, Homework 1, Problem 1:
# Given a function for the probability of mortality at an age x,
# Find the the age that has the highest probability for death.
# So the student should know to take the derivative of the function,
# set the derivative to zero, and then solve for x.
DOCUMENT();
loadMacros("PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserNumberWithUnits.pl",
"parserFormulaWithUnits.pl");
Context("Numeric");
$a = Real(random(3,13,2));
$b = Real(random(2,9,1));
$c = Real(random(2,10,2));
$d = Real(random(2,10,1));
Context()->variables->add(A=>"Real");
$ans1 = Compute("1/A");
$ans11 = FormulaWithUnits("$ans1 hr");
$ans2 = Compute("A/e");
$ans22 = FormulaWithUnits("$ans2 hr");
TEXT(beginproblem());
BEGIN_PGML
A biologist measures the probability of mortality for a given species of mayfly by the function:
[``P(x) = A^2xe^{-Ax}``]
where [`x`] is the adult mayfly's age in hours such that [`0 < A < e`].
_(Include [@ helpLink('units') @]* in each of your answers.)_
Find the life-span age that corresponds with the maximum probability for a mayfly's death. Your answer should be in terms of A and you will have to *wrap the expression in parentheses*.
[_____]{$ans11}{20}
What age has the maximum probability for mayfly mortality?
Again your answer should be in terms of A.
[________]{$ans22}{20}
END_PGML
BEGIN_PGML_SOLUTION
*SOLUTION*
1.) We must take the derivative and set the derivative to zero to solve for x, the age for the most likely mayfly life span.
[``P(x) = A^2xe^{-Ax}``]
[``P(x) = A^2(xe^{-Ax})``] First pull out the constant of [``A^2``]
[::P'(x) = A^2(x'e^{-Ax}+xe^{-Ax}'{-Ax}')::] Apply the prime tics for the product rule and chain rule.
[``P'(x) = A^2(e^{-Ax} + xe^{-Ax}(-A))``] Take the derivative.
[``P'(x) = A^2e^{-Ax}(1-Ax)``] Pull the common factor and reduce.
[``A^2e^{-Ax}(1-Ax) = 0``] Set the derivative to zero and solve for x to find the critical point.
[``1-Ax = 0``] Recognize that [``A^2``] and [``e^{-Ax}``] can not be zero as both are positive.
[``Ax = 1``]
[``x = \frac{1}{A}``] Which is the age in hours for the life span with the greatest chance of death for the mayfly.
2.) Evaluate P(x) at the critical point of [``x = \frac{1}{A}``] for the mayfly's age that has the maximum probability for death.
[``P(x) = A^2xe^{-Ax}``]
[``P(\frac{1}{A}) = A^2\frac{1}{A}e^{-A\frac{1}{A}}``]
[``P(\frac{1}{A}) = Ae^{-1} = \frac{A}{e}``]
END_PGML_SOLUTION
ENDDOCUMENT();