The code below works and does what I want, but I have the feeling that there is a better way to do it. I do not want decimals in the solution, but the only way I could do that was to define two different objects, $ans to check the answer and $sol to display the solution without decimals. If I use ContextFraction for $ans (that is used by the answer checker), the system does not recognize the correct answer and returns "incorrect". Is there a way to use contextFraction for the object that goes in the answer checker?
Thanks for any help.
DOCUMENT();
loadMacros("PGstandard.pl",
"MathObjects.pl",
"contextFraction.pl",
"PGcourse.pl",
"PGML.pl");
Context("Point");
$a=random(2,9,1);
$b=non_zero_random(-8,8,2);
$c=random(3,9,2);
$d=non_zero_random(-9,9,1);
Context()->variables->add(r=>'Real',s=>'Real');
$ans=Compute("($d/$a-$b r/$a-$c s/$a, r, s)");
Context("Fraction-NoDecimals");
Context()->variables->add(r=>'Real',s=>'Real');
$sol=Compute("($d/$a-$b r/$a-$c s/$a, r, s)");
TEXT(beginproblem());
BEGIN_PGML
Find the solution set of the linear equation, using [`x_1`] and [`x_2`] as free variables.
[``[$a] x_1+[$b]x_2+[$c]x_3 = [$d]``]
[``S=``][_________________]{$ans}
END_PGML
BEGIN_PGML_SOLUTION
[``S= [$sol]``]
END_PGML_SOLUTION
ENDDOCUMENT()