From WeBWorK_wiki
Revision as of 15:18, 6 February 2010 by Pearson (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Interval Answer Checkers

This code shows how to check answers that are intervals.

For answers that are inequalities (or intervals), see InequalityEvaluators

Problem Techniques Index

PG problem file Explanation



Initialization: Load the usual suspects. The interval context and interval answer checker are part of

# to allow open or closed intervals, uncomment
#    the following line.
# Context()->flags->set(ignoreEndpointTypes=>1);

$int = Compute("(1,3)");

Setup: No changes are necessary in the tagging and description and initialization sections of the question file. In the problem set-up section of the file, we set the Context to be the Interval Context. Note that we can relax checking of endpoints in the Context or in the actual answer checking, as noted below.

Once we're in the Interval context, we can define intervals as we'd expect: as shown here, or with limits at infinity:

$int2 = Compute("(-inf,1]");

Would give the interval from negative infinity to 1, including the point at one. Note the Context flag to make endpoint checking "fuzzy."

On what interval is the parabola
\( y = (1-x)(x-3) \)
above the \(x\)-axis?
For \(x\) in \{ ans_rule(15) \}

Main Text: In the text section of the file, we ask the question as usual.

ANS( $int->cmp() );


Answer Evaluation: We check the answer using our interval MathObject. To allow either open or closed intervals, we can specify a flag for the cmp() call: $int->cmp( requireParenMatch => 0 ). (Alternately, we can specify this for all intervals in the Context, as noted above.)

Problem Techniques Index