Hi Andrew,
Two things were needed to get the problem to run:
1. Load "contextFraction.pl" after "MathObjects.pl" in loadMacros(). Apparently contextFraction.pl does not automatically load MathObjects.pl, so the order in which they are loaded does matter since contextFraction.pl is "built on top of" MathObjects.pl.
2. You need to pass a MathObject to ->cmp. When you write
$x2 = random(-12,12,1);
$ansX = $x2;
...
ANS( $ansX->cmp );
the answer checker is trying to apply the method ->cmp to the Perl real $x2, but Perl reals do not have the ->cmp method defined for them. To fix this, you need to promote $ansX to a MathObject, e.g.,
$ansX = Fraction("$x2");
Similar remarks apply for $ansY.
#################
More comments:
1. You may want to consider using non_zero_random(-12,12,1); in several places.
2. Technically, the point is on the graph of the function, not the function itself, which is why I edited the problem text.
3. In general, when thinking about the presentation of problem text, I ask myself what the text would look like in a good textbook that has been professionally edited. A textbook editor would probably typeset x-coordinate using math mode as \(x\)-coordinate. Also, capitalizing New is unnecessary.
4. You may want to consider having the students enter a point instead of each coordinate separately. If you only ask your students for the x- and y-coordinates separately on the homework, but the quiz or test asks for a point, you're going to have many students who give the wrong type of answer on the quiz or test (a list of two numbers instead of a point). In general, asking students for the correct type of answer is a good thing in my experience.
5. I cleaned up the list_random() stuff by replacing $a = list_random(Fraction("1/2")); by $a = list_random("1/2"); $a = Fraction("$a");
Good work! My code is below.
Paul Pearson
##################################################
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"contextFraction.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
Context("Fraction-NoDecimals");
$a = list_random(-6, -5, -4, -3, -2, -1, "-1/2", "-1/3", "-1/4", "1/4", "1/3", "1/2", 1, 2, 3, 4, 5, 6);
$a = Fraction("$a");
$b = list_random(-6, -5, -4, -3, -2, -1, "-1/2", "-1/3", "-1/4", "1/4", "1/3", "1/2", 1, 2, 3, 4, 5, 6);
$b = Fraction("$b");
$c = random(-10,10,1);
$d = random(-10,10,1);
$x2 = random(-12,12,1);
$y1 = random(-12,12,1);
$x1 = Fraction("$b*$x2+$c");
$y2 = Fraction("$a*$y1+$d");
$ansX = Fraction("$x2");
$ansY = Fraction("$y2");
##############################################################
#
# Text
#
Context()->texStrings;
BEGIN_TEXT
Suppose the point \( ($x1, $y1) \) is on the graph of
the function \( f(x) \). Find the coordinates of the
resulting point after the transformation
\[ $a f( $b x + $c ) + $d. \]
The new \(x\)-coordinate is
\{ ans_rule(20) \}
\{ AnswerFormatHelp("fractions") \}
$BR
The new \(y\)-coordinate is
\{ ans_rule(20) \}
\{ AnswerFormatHelp("fractions") \}
END_TEXT
Context()->normalStrings;
##############################################################
#
# Answers
#
ANS( $ansX->cmp);
ANS( $ansY->cmp);
COMMENT('MathObject version');
ENDDOCUMENT();