From WeBWorK
Jump to: navigation, search

Inequalities as Answers

This is the essential code for having inequalities as student answers.

Problem Techniques Index

PG problem file Explanation



Initialization: Include the macro file, which automatically loads

# Context()->constants->add(EmptySet => Set());
# Context()->flags->set(noneWord=>"EmptySet");
# Context()->flags->set(ignoreEndpointTypes=>1);

# f(x) = x^2 - 16 on -1 <= x <= 5
$f = Formula("x^2 - 16");

$range = Compute("-16 <= y <= 9");


Setup: Using Context("Inequalities-Only"), if the student enters the inequality -16 <= y <= 9 their answer will be marked correct, but the equivalent interval [-16,9] would be incorrect. If we had used Context("Inequalities") instead, both the inequality and the interval would be marked correct.

Uncommenting the lines containing EmptySet creates an empty set as a named constant and uses that name.

Uncommenting Context()->flags->set(ignoreEndpointTypes=>1); would also mark the student answers -16 < y < 9 or -16 <= y < 9 or -16 < y <= 9 correct.

As of January 2010, the inequality is not variable-specific. If we had not removed the default variable x from the context using Context()->variables->remove("x");, then the student answer -16 <= x <= 9 would also be marked correct. Note that we removed the variable x from the context after we defined the formula $f that uses this variable (otherwise there would be errors and PG file would not work).

What is the range of  
\( y = f(x) = $f \) on the domain \( -1 \leq x \leq 5 \)?
Range: \{ ans_rule(20) \} Enter your answer using 
inequalities (not intervals).

Main Text: The problem text section of the file is as we'd expect.

ANS( $range->cmp() );


Answer Evaluation: As is the answer.

Problem Techniques Index

follow us