Difference between revisions of "EquationEvaluators"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 17: Line 17:
 
<td style="background-color:#ddffdd;border:black 1px dashed;">
 
<td style="background-color:#ddffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
loadMacros("parserImplicitEquation.pl");
+
loadMacros("parserImplicitEquation.pl");
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 29: Line 29:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("ImplicitEquation");
+
Context("ImplicitEquation");
Context()-&gt;variables-&gt;set(
+
Context()-&gt;variables-&gt;set(
x=&gt;{limits=&gt;[-2,2]},
+
x=&gt;{limits=&gt;[-2,2]},
y=&gt;{limits=&gt;[0,4]}
+
y=&gt;{limits=&gt;[0,4]}
);
+
);
   
$expr = ImplicitEquation("y = (x-1)^2");
+
$expr = ImplicitEquation("y = (x-1)^2");
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 49: Line 49:
 
</p>
 
</p>
 
<pre>
 
<pre>
$expr = ImplicitEquation("y = (x-1)^2",
+
$expr = ImplicitEquation("y = (x-1)^2",
solutions=&gt;[[0,0],[1,1],[-1,1],
+
solutions=&gt;[[0,0],[1,1],[-1,1],
[2,4],[-2,4]]);
+
[2,4],[-2,4]]);
 
</pre>
 
</pre>
 
<p>
 
<p>
Line 57: Line 57:
 
</p>
 
</p>
 
<pre>
 
<pre>
$expr = ImplicitEquation("y = (x-1)^2",
+
$expr = ImplicitEquation("y = (x-1)^2",
tolerance=&gt;0.0001);
+
tolerance=&gt;0.0001);
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 65: Line 65:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
BEGIN_TEXT
+
BEGIN_TEXT
Give the equation of a shift of the
+
Give the equation of a shift of the
parabola \(y = x^2\) which is upward
+
parabola \(y = x^2\) which is upward
opening and has its vertex at (1,0).
+
opening and has its vertex at (1,0).
$PAR
+
$PAR
equation = \{ ans_rule(35) \}
+
equation: \{ ans_rule(35) \}
END_TEXT
+
END_TEXT
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
Line 82: Line 82:
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
<pre>
ANS( $expr->cmp() );
+
ANS( $expr->cmp() );
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">

Revision as of 15:06, 7 January 2010

Equation Answer Evaluation: PG Code Snippet

This code snippet shows the essential PG code to check student answers that are equations. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

Problem Techniques Index

PG problem file Explanation
loadMacros("parserImplicitEquation.pl");

To check equations given as answers, we don't have to change the tagging and documentation section of the problem file. In the initialization section, we need to include the macros file parserImplicitEquation.pl.

Context("ImplicitEquation");
Context()->variables->set(
x=>{limits=>[-2,2]},
y=>{limits=>[0,4]}
);

$expr = ImplicitEquation("y = (x-1)^2");

In the problem set-up section of the file, we specify that the Context should be ImplicitEquation, and define the answer to be an equation. It's worth noting that there are a number of Context settings that may be specifying for equation answers. In particular, it's often important to pay attention to the limits used by the answer checker.

By default, the ImplicitEquation context defines the variables x and y. To include other variables, it may be necessary to modify the context.

Two other notes: if it's possible that a student's solution may evaluate to true for the test points that are used in the answer checker, it may be a good idea to specify what (x,y) solution values are used to check the answer. This can be done in the ImplicitEquation initialization call, e.g.,

$expr = ImplicitEquation("y = (x-1)^2",
solutions=>[[0,0],[1,1],[-1,1],
[2,4],[-2,4]]);

And, for this type of answer checking it is more likely than for regular formulas that the student will represent the function in a form that exceeds the default problem checking tolerances, and so be marked as incorrect. To correct this, it may be necessary to specify a tolerance; an absolute tolerance can be set in the ImplicitEquation call, e.g.,

$expr = ImplicitEquation("y = (x-1)^2",
tolerance=>0.0001);
BEGIN_TEXT
Give the equation of a shift of the
parabola \(y = x^2\) which is upward
opening and has its vertex at (1,0).
$PAR
equation: \{ ans_rule(35) \}
END_TEXT

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

ANS( $expr->cmp() );

As is the answer.

Problem Techniques Index