Difference between revisions of "InequalityEvaluators"

From WeBWorK_wiki
Jump to navigation Jump to search
m
m
Line 48: Line 48:
 
<pre>
 
<pre>
 
Context("Inequalities");
 
Context("Inequalities");
Context()->variables->add(y=>"Real");
+
Context()->variables->are(y=>"Real");
 
# Context()->constants->add(EmptySet => Set());
 
# Context()->constants->add(EmptySet => Set());
 
# Context()->flags->set(noneWord=>"EmptySet");
 
# Context()->flags->set(noneWord=>"EmptySet");
Line 65: Line 65:
 
</p>
 
</p>
 
<p>
 
<p>
As of January 2010, the inequality is not variable-specific, so the answer <code>-16 <= x <= 9</code> would also be marked correct. We could have required students to use the variable y by removing the default variable x from the context using <code>are</code> instead of <code>add</code> when setting variables. For example,
+
As of January 2010, the inequality is not variable-specific. If we had another variable defined in the context (for example, if we had used <code>Context()->variables->add(y=>"Real");</code> so that the default variable x was in the context), then the student answer <code>-16 <= x <= 9</code> would also be marked correct.
<code>Context()->variables->are(y=>"Real");</code>.
 
 
</p>
 
</p>
 
<p>
 
<p>

Revision as of 15:42, 22 January 2010

Inequalities as Answers


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

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"contextInequalities.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

Initialization: Include the macro file contextInequalities.pl.

Context("Inequalities");
Context()->variables->are(y=>"Real");
# Context()->constants->add(EmptySet => Set());
# Context()->flags->set(noneWord=>"EmptySet");

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

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

Setup: Using Context("Inequalities"), if the student enters either the inequality -16 <= y <= 9 or the interval [-16,9] their answer will be marked correct. To mark only the inequality correct but not the interval, use Context("Inequalities-Only"); instead. Uncommenting the lines containing EmptySet creates an empty set as a named constant and uses that name.

As of January 2010, the inequality is not variable-specific. If we had another variable defined in the context (for example, if we had used Context()->variables->add(y=>"Real"); so that the default variable x was in the context), then the student answer -16 <= x <= 9 would also be marked correct.

For a list of all available options for the interval context, see the POD documentation at http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/contextInequalities.pl

Context()->texStrings;
BEGIN_TEXT

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

END_TEXT
Context()->normalStrings;

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

ANS( $range->cmp() );

ENDDOCUMENT();

Answer Evaluation: As is the answer.

Problem Techniques Index