Context("Numeric");
parser::FunctionPrime->Enable();
Context()->variables->add(t=> 'Real');
parserFunction("r(t)" => "15");
$r = Formula("r(t)");
$dr = Formula("r'(t)");
$dA = Compute("2 pi $r * $dr");
BEGIN_TEXT
...
\(A'(t) = \)\{ans_rule(30) \}
END_TEXT
ANS($dA->cmp);
Here are a few comments:
First, I'd use
Context()->variables->are(t=> 'Real');with
are
rather than add
so that you remove the original variable x
that was in the context. Not a big issue, but cleaner.
Next, there is no real need for the variables $r
or $dr
. You can just do
$dA = Compute("2 pi r(t) r'(t)");so that it looks like what you would expect the student to type.
Third, I would not use r(t) = 15
as that means that r'(t) = 0
so an answer of 0 will be a correct answer. (In your case, 2pi r(t) r'(t)
does equal 0.) I'd recommend using some function that has a non-zero derivative and unlikely to be reproduced by a student, say r(t) = e^t + cos(3t)/10
(which is positive and not too big on the usual domain) or some such thing.
So a revised version of the problem is
loadMacros("parserFunctionPrime.pl");
Context("Numeric");
parser::FunctionPrime->Enable();
Context()->variables->are(t=>"Real");
parserFunction("r(t)" => "e^t+cos(3t)/10");
$dA = Compute("2pi r(t) r'(t)");
Context()->texStrings;
BEGIN_TEXT
\(A'(t)\) = \{$dA->ans_rule(20)\}
END_TEXT
Context()->normalStrings;
ANS($dA->cmp);
Hope that helps.