Difference between revisions of "EquationEvaluators"
(New page: <h2>Equation Answer Evaluation: PG Code Snippet</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This code snippet shows the essential PG code to check st...) |
(added historical tag and gave updated problem link) |
||
(17 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | <h2>Equation Answer Evaluation: PG Code Snippet</h2> |
||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/EquationEvaluators.html a newer version of this problem]</p> |
||
+ | <h2>Equation Answer Evaluation</h2> |
||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <em>This code snippet shows the essential PG code to check student answers that are equations. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em> |
||
+ | <em> |
||
+ | This code shows how to check student answers that are equations. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working. |
||
+ | <br /> |
||
+ | For equations that are lines or planes, use [http://webwork.maa.org/wiki/ImplicitPlane ImplicitPlane] as it is more reliable. |
||
+ | </em> |
||
</p> |
</p> |
||
Line 17: | Line 24: | ||
<td style="background-color:#ddffdd;border:black 1px dashed;"> |
<td style="background-color:#ddffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | + | loadMacros("parserImplicitEquation.pl"); |
|
</pre> |
</pre> |
||
</td> |
</td> |
||
<td style="background-color:#ccffcc;padding:7px;"> |
<td style="background-color:#ccffcc;padding:7px;"> |
||
<p> |
<p> |
||
+ | <b>Initialization:</b> |
||
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 <code>parserImplicitEquation.pl</code>. |
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 <code>parserImplicitEquation.pl</code>. |
||
</p> |
</p> |
||
Line 29: | Line 37: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | + | Context("ImplicitEquation"); |
|
− | + | Context()->variables->set( |
|
− | + | x=>{limits=>[-2,2]}, |
|
− | + | y=>{limits=>[0,4]} |
|
− | + | ); |
|
− | + | $eqn = ImplicitEquation("y = (x-1)^2"); |
|
</pre> |
</pre> |
||
</td> |
</td> |
||
<td style="background-color:#ffffcc;padding:7px;"> |
<td style="background-color:#ffffcc;padding:7px;"> |
||
<p> |
<p> |
||
− | In the problem set-up section of the file, we specify that the Context should be <code>ImplicitEquation</code>, 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 [[FormulaTestPoints|limits used by the answer checker]]. |
||
+ | <b>Setup:</b> |
||
+ | We specify that the Context should be <code>ImplicitEquation</code>, 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 [[FormulaTestPoints|limits used by the answer checker]]. |
||
</p> |
</p> |
||
<p> |
<p> |
||
Line 49: | Line 58: | ||
</p> |
</p> |
||
<pre> |
<pre> |
||
− | + | $eqn = ImplicitEquation("y = (x-1)^2", |
|
− | + | solutions=>[[0,0],[1,1],[-1,1],[2,4],[-2,4]]); |
|
− | [2,4],[-2,4]]); |
||
</pre> |
</pre> |
||
<p> |
<p> |
||
Line 56: | Line 65: | ||
</p> |
</p> |
||
<pre> |
<pre> |
||
− | + | $eqn = ImplicitEquation("y = (x-1)^2", |
|
− | + | tolerance=>0.0001); |
|
</pre> |
</pre> |
||
+ | <p> |
||
+ | It is possible to remove the error message "Can't find any solutions to your equation" by remapping it to another error message. The message has to be non-empty, but it can be just a blank <code>" "</code>, as in |
||
+ | <pre> |
||
+ | Context()->{error}{msg}{"Can't find any solutions to your equation"} = " "; |
||
+ | </pre> |
||
+ | This will eliminate the error message (though the "messages" column will be displayed in the answer table at the top of the problem, but no message will be there). For another way to remove this error message, see the <code>withPostFilter</code> option below in the Answer Evaluation section. |
||
+ | </p> |
||
</td> |
</td> |
||
</tr> |
</tr> |
||
Line 64: | Line 80: | ||
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | + | 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 |
|
</pre> |
</pre> |
||
<td style="background-color:#ffcccc;padding:7px;"> |
<td style="background-color:#ffcccc;padding:7px;"> |
||
<p> |
<p> |
||
− | The problem text section of the file is as we'd expect. |
+ | <b>Main Text:</b> The problem text section of the file is as we'd expect. |
</p> |
</p> |
||
</td> |
</td> |
||
Line 81: | Line 97: | ||
<td style="background-color:#eeddff;border:black 1px dashed;"> |
<td style="background-color:#eeddff;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | + | ANS( $eqn->cmp() ); |
|
</pre> |
</pre> |
||
<td style="background-color:#eeccff;padding:7px;"> |
<td style="background-color:#eeccff;padding:7px;"> |
||
<p> |
<p> |
||
− | As is the answer. |
||
+ | <b>Answer Evaluation:</b> |
||
+ | Another way to remove the error message "Can't find any solutions to your equation" would be to use a post-filter to remove the message after the answer has been graded. The <code>answerHints.pl</code> file provides one way to do this, but it is probably just as easy to do it manually, as in: |
||
+ | <pre> |
||
+ | ANS($eqn->cmp->withPostFilter(sub { |
||
+ | my $ans = shift; |
||
+ | $ans->{ans_message} = " " if $ans->{ans_message} eq |
||
+ | "Can't find any solutions to your equation"; return $ans; |
||
+ | })); |
||
+ | </pre> |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 94: | Line 118: | ||
[[IndexOfProblemTechniques|Problem Techniques Index]] |
[[IndexOfProblemTechniques|Problem Techniques Index]] |
||
</p> |
</p> |
||
+ | |||
+ | [[Category:Problem Techniques]] |
||
+ | |||
+ | |||
+ | |||
+ | * POD documentation: [http://webwork.maa.org/pod/pg/macros/parserImplicitEquation.html parserImplicitEquation.pl] |
||
+ | * PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/parserImplicitEquation.pl?view=log parserImplictEquation.pl] |
Latest revision as of 08:30, 28 June 2023
This problem has been replaced with a newer version of this problem
Equation Answer Evaluation
This code shows how 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.
For equations that are lines or planes, use ImplicitPlane as it is more reliable.
PG problem file | Explanation |
---|---|
loadMacros("parserImplicitEquation.pl"); |
Initialization:
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 |
Context("ImplicitEquation"); Context()->variables->set( x=>{limits=>[-2,2]}, y=>{limits=>[0,4]} ); $eqn = ImplicitEquation("y = (x-1)^2"); |
Setup:
We specify that the Context should be
By default, the
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 $eqn = 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 $eqn = ImplicitEquation("y = (x-1)^2", tolerance=>0.0001);
It is possible to remove the error message "Can't find any solutions to your equation" by remapping it to another error message. The message has to be non-empty, but it can be just a blank Context()->{error}{msg}{"Can't find any solutions to your equation"} = " "; This will eliminate the error message (though the "messages" column will be displayed in the answer table at the top of the problem, but no message will be there). For another way to remove this error message, see the |
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 |
Main Text: The problem text section of the file is as we'd expect. |
ANS( $eqn->cmp() ); |
Answer Evaluation:
Another way to remove the error message "Can't find any solutions to your equation" would be to use a post-filter to remove the message after the answer has been graded. The ANS($eqn->cmp->withPostFilter(sub { my $ans = shift; $ans->{ans_message} = " " if $ans->{ans_message} eq "Can't find any solutions to your equation"; return $ans; })); |
- POD documentation: parserImplicitEquation.pl
- PG macro: parserImplictEquation.pl