I am writing a problem relating to the First Derivative Test. The first answer is to be a list of numbers representing the critical points. The second answer is to be a list of "+" or "-" corresponding to the sign of the first derivative on intervals created by these critical points.
If I add "+" and "-" as strings to the context, the first answer breaks for negative numbers: "Operands of "*" can't be words"
If I do not add them as strings, the list checker complains that "+" or "-" are missing operands.
Ideas?
Thanks,
D. Brian Walton
James Madison University
You do this by using two contexts. Since a MathObject remembers what context it was in when it was created, you can have object that are in two separate contexts (for exactly this type of situation).
Here is an example of how to do it:
loadMacros("contextString.pl"); Context("Numeric"); $critpts = Compute("-2.7, 1.5, 3.53"); Context("String")->strings->add("+"=>{}, "-"=>{}, "0"=>{}); # define the allowed strings Context()->operators->redefine(",", from=>"Numeric"); # allow lists $signs = Compute("+,-,+,-"); BEGIN_TEXT The critical points are: \{ans_rule(20)\}$BR The signs of the intervals between them are \{ans_rule(20)\} END_TEXT ANS($critpts->cmp(showHints=>1, showLengthHints=>1)); ANS($signs->cmp(ordered=>1, entry_type=>"a sign"));
Hope that does it.
Davide