I cannot get the absolute value function to graph. I get a warning message:
Warning messages
syntax error in answer:(|x|)
Illegal character at position 2 at line 454 of [PG]/macros/PGgraphmacros.plsyntax error in answer:(|x|)
Illegal character at position 2 at line 458 of [PG]/macros/PGgraphmacros.pl
Here is the code:-------------------------------------------------------------------
DOCUMENT(); # This should be the first executable line in the problem.
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextInequalities.pl",
"parserUtils.pl"
);
TEXT(beginproblem);
######################################
# Setup
#----Define the functions
$f = Formula("abs(x)");
$a = random(-4,-2,1);
$g = Formula("$a");
#---Define the graph
($xm,$xM) = (-6,6); #min and max for x
($ym,$yM) = (-6,6); #min and max for y
$size = [300,300];
$tex_size = 600;
@slice = NchooseK(3,3);
@colors = ("blue", "red", "green");
@sc = @colors[@slice]; #scrambled colors
@Goptions = (
$xm,$ym,$xM,$yM,
axes => [0,0],
grid => [$xM-$xm,$yM-$ym],
size => $size
);
@imageoptions = (size=>$size,tex_size=>$tex_size);
$xdomain = "x in <$xm,$xM>";
$f_options = "using color:$sc[0] and weight:3";
$g_options = "using color:$sc[1] and weight:3";
$graph = init_graph_no_labels(@Goptions);
plot_functions($graph,
"$f for $xdomain $f_options",
"$g for $xdomain $g_options");
$labelf = new Label(-3,5, "f(x) = $f->string", 'black','center');
$labelg = new Label(3,$a, "y = $a",'black','center');
$graph->lb($labelf,$labelg);
$Image = Image($graph,@imageoptions);
######################################
# Main text
BEGIN_TEXT
$Image
$BR $BR
The graph of \( f(x) = \{$f->TeX\} \) is given above with the line \( y = $a \).
For what values of \(x\) is the following true?
$PAR
\( |x| = $a \)
$BR
Answer: \{ans_rule(20) \}
END_TEXT
######################################
# Answer
Context("Inequalities");
$ans = Compute("NONE");
ANS($ans->cmp);
$showPartialCorrectAnswers = 1;
######################################
ENDDOCUMENT();
-----------------------END CODE----------------------------------------------
Thanks for your help -- rac