WeBWorK Problems

List of equations as an answer, using parserAssignment.pl

List of equations as an answer, using parserAssignment.pl

by Chris Wingard -
Number of replies: 0

Hi All,

I'm trying to have the students enter a list of asymptotes (vertical, horizontal, oblique) and I'm getting some weird behavior.

Suppose the answer is:  x=1/2, y=9x/2 + 9/4

If I enter the answer like that, it's fine.  But if I enter them switched: "y=9x/2 + 9/4, x=1/2", then I get this strange error message -- " No value given for variable 'x' " and the 'x' in y=9x/2 + 9/4 is highlighted.

Also, if I only enter x=1/2 then I get the error message "Your second value isn't equation (it looks like a real number)".  The bad grammar comes from my entry_type => "equation" in the code but I'd like that message to not be confusing (it sounds like it's treating x=1/2 as a list by itself) although I'd be happy to remove it entirely.

Here is the relevant code:

DOCUMENT();     

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "parserAssignment.pl",
);

Context("Numeric")->flags->set(
  formatStudentAnswer => parsed,
  reduceConstants => 0,
  reduceConstantFunctions => 0,
);
Context()->variables->are(x=>"Real",y=>"Real");
Parser::Number::NoDecimals;
parser::Assignment->Allow;

do {
  $a = random(7,12,1);
  $b = random(2,4,1);
  $c = random(1,9,1);
} while (gcd($b,$c) != 1);

$fx = "\frac{$a x^2}{$b x - $c}";

$top = $c*$a;
$bot = $b**2;

$ans1 = Formula("y = $a x/$b + $top/$bot");
$ans2 = Formula("x = $c/$b");
$ans = List($ans1, $ans2);

#########################################

Context()->normalStrings;
BEGIN_TEXT
$PAR
Let \( \displaystyle f(x) = $fx \).
$PAR
Find all horizontal, vertical, and oblique asymptotes of the graph of \(f(x)\).
$BR
Enter your answer as a list of equations of lines.
$PAR
ANSWER: \{ans_rule(40)\}
END_TEXT
Context()->texStrings;

ANS( $ans -> cmp( entry_type => "equation" ) );

ENDDOCUMENT();

Any thoughts on how to proceed?  Thanks!

-- C