Difference between revisions of "FormulasToConstants"

From WeBWorK_wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<h2>Formulas Up To Constants: 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/FormulasToConstants.html a newer version of this problem]</p>
  +
<h2>Formulas Up To Additive Constants: PG Code Snippet</h2>
   
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
Line 51: Line 54:
 
<pre>
 
<pre>
 
BEGIN_TEXT
 
BEGIN_TEXT
An antiderivative of \(cos(x)\) is
+
An antiderivative of \(\cos(x)\) is
 
\{ ans_rule(15) \}
 
\{ ans_rule(15) \}
 
$BR
 
$BR
Line 72: Line 75:
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
And then in the answer and solution section of the file we rely on the MathObjects <code>cmp()</code> method. By specifying the <code>upToConstant=&gt;1</code> flag for <code>cmp()</code>, we allow the student's answer to differ from the correct answer by any specific constant. For the <code>FormulaUpToConstant</code> we don't need this, because those MathObjects already know that they are "up to a constant". Which makes pretty good sense, really.
+
And then in the answer and solution section of the file we rely on the MathObjects <code>cmp()</code> method. By specifying the <code>upToConstant=&gt;1</code> flag for <code>cmp()</code>, we allow the student's answer to differ from the correct answer by any specific constant. <code>sin(x)</code> and <code>sin(x)+5</code> are both marked as correct but <code> sin(x) +C </code> is not correct since it is a family of answers and not a single anti-derivative.
</p>
+
<p>
+
Note that for the formula up to an arbitrary constant the comparison will correctly mark students' answers that have different arbitrary constants: thus, a student answer of <code>sin(x)+k</code> to the second question here will be marked correct as will <code>sin(x) +c </code>.
Note that for the formula up to an arbitrary constant the comparison will correctly mark students' answers that have different arbitrary constants: thus, a student answer of <code>sin(x)+k</code> to the second question here will be marked correct.
 
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
  +
  +
  +
  +
<ul>
  +
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/parserFormulaUpToConstant.html parserFormulaUpToConstant.pl]</li>
  +
<li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/parserFormulaUpToConstant.pl?view=log parserFormulaUpToConstant.pl]</li>
  +
</ul>
  +
  +
  +
   
 
<p>
 
<p>

Latest revision as of 16:55, 20 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Formulas Up To Additive Constants: PG Code Snippet

This code snippet shows the essential PG code to evaluate antderivative and general antiderivative formulas. 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.

There are two types of comparison that we're interested in here: one is "an antiderivative of f(x)", and the other is "the most general antiderivative of f(x)". The former requires that the student answers F(x), F(x)+1, F(x)-sqrt(8), etc., all be marked correct, and the latter, that F(x)+C, F(x)+5-k, etc., all be marked correct. These are both illustrated below.

It is possible to do some of this type of comparison with old-style answer checkers. This is shown in a table below.

Problem Techniques Index

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

To check the most general antiderivative of a function, that is, a formula up to an arbitrary additive constant, we need to load the parserFormulaUpToConstant.pl macros file. To evaluate an antiderivative of a function, that is, a formula that only unique up to a (specified) additive constant, we do not need to load this file.

  $func = Formula("sin(x)");
  $gfunc = FormulaUpToConstant("sin(x)+C");

In the problem set-up section of the problem file, we define an antiderivative function, $func and the most general antiderivative function, $gfunc. For the latter we are not required to include the +C; it would be equivalent to specify $gfunc = FormulaUpToConstant("sin(x)").

  BEGIN_TEXT
  An antiderivative of \(\cos(x)\) is
  \{ ans_rule(15) \}
  $BR
  The most general antiderivative is
  \{ ans_rule(15) \}
  END_TEXT

In the text section of the file we ask for the answers as usual.

  ANS( $func->cmp(upToConstant=>1) );
  ANS( $gfunc->cmp() );

And then in the answer and solution section of the file we rely on the MathObjects cmp() method. By specifying the upToConstant=>1 flag for cmp(), we allow the student's answer to differ from the correct answer by any specific constant. sin(x) and sin(x)+5 are both marked as correct but sin(x) +C is not correct since it is a family of answers and not a single anti-derivative. Note that for the formula up to an arbitrary constant the comparison will correctly mark students' answers that have different arbitrary constants: thus, a student answer of sin(x)+k to the second question here will be marked correct as will sin(x) +c .




With old-style answer checkers we can check antiderivatives, but checking the most general antiderivative is much less elegant, as we have to require that the student use a specific constant of integration.

PG problem file Explanation
  $func = "sin(x)";
  $gfunc = "sin(x)+C";

In this case we need no additional macros, and so do not change the description and tagging or initialization sections of the file. In the problem set-up section we specify the function(s) to evaluate.

  BEGIN_TEXT
  An antiderivative of \(cos(x)\) is
  \{ ans_rule(15) \}
  $BR
  The most general antiderivative is
  \{ ans_rule(15) \}
  $BR
  ${BITALIC}(Use "C" for any arbitrary 
  constant of integration in your 
  answer.)$EITALIC
  END_TEXT

In the text section of the problem we ask for the functions. Because we require that the most general antiderivative use the constant C, however, we should probably remind the student of that fact.

  ANS( fun_cmp( $func, mode=>"antider" ) );
  ANS( fun_cmp( $gfunc, mode=>"antider", 
  var=>["x","C"] ) );

When checking the answer in the answer and solutions section of the file, we specify mode=>"antider" in the call to the old-style answer checker fun_cmp. For the most general antiderivative we also indicate that the variables include the "variable" C.

Problem Techniques Index