The "Correct" answer is displaying as a constant, but should be a formula
by tim Payer - Number of replies: 3Re: The "Correct" answer is displaying as a constant, but should be a formula
by tim Payer -Re: The "Correct" answer is displaying as a constant, but should be a formula
by Davide Cervone -[__________]{"([$a]-sqrt([$b]))*(sqrt(x)+[$c])/(x-[$c**2])"}not
[__________]{([$a]-sqrt([$b]))*(sqrt(x)+[$c])/(x-[$c**2])}The contents of the braces is actually treated as a perl command whose result is used as the answer (this allows things like
$f->cmp->withPostFilter(AnswerHints(...))
and so on to be used in the braces). So in your case, without the quotes, this is treated as a Perl expression and reduced to a constant before being used as the answer. Here, "x", will be treated as an unquoted string, which has value 0 in perl expressions. So you en up with a numerical result. (This is correct behavior, not a bug in PGML; the bug is in not putting the quotation marks around the expression.)
If the result of evaluating the contents of the braces is a string (as it should be in your case) or a number, then PGML will call Compute()
on the string and use the resulting MathObject as the answer. That is how you get formula answers.
Note that A second problem is that you are using [$a]
outside of PGML. Note that this does variable substitution only in PGML. Outside of PGML, it creates an array reference containing the value of $a
. So in
Context()->variables->set(x => {limits => [[$a]/[$b],100]});both
[$a]
and [$b]
are array references (i.e., pointers to arrays), not the values of the variables themselves. I think in this case, the result will be the fraction formed by the actual memory locations, not th values of the variables, so this is not the computation you want. You really want just
Context()->variables->set(x => {limits => [$a/$b,100]});as that is all that is required in perl expressions.
Similarly, you have use [$a]
in your answer where you only need $a
, since the answer is treated as a perl string, not a PGML one. So you can use
[__________]{"($a-sqrt($b))*(sqrt(x)+$c)/(x-$csq)"}for the answer. The other form is not an error, since brackets work as parentheses in the Numeric context, so the result is essentially the same, but it suggests a misunderstanding of the format and may lead to problems in other contexts.
A small detail is that you don't need to load PGbasicmacros.pl
, since those are loaded automatically by PGstandard.pl
. Also, you don't use problemRandomize.pl