Difference between revisions of "EquationDefiningFunction1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>Answer is a Linear Equation</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> This PG code shows how to check an answer that is a linear equation…')
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<h2>Answer is a Linear Equation</h2>
+
<h2>Answer is an Equation Defining a Function</h2>
   
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
  +
[[File:EquationDefiningFunction1.png|300px|thumb|right|Click to enlarge]]
This PG code shows how to check an answer that is a linear equation.
 
  +
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
<ul>
 
  +
This PG code shows how to check student answers that are equations that define functions. If an equation defines a function, it is much more reliable to use the this method of answer evaluation (via <code>parserAssignment.pl</code>) than the implicit equation method (via <code>parserImplicitEquation.pl</code>)
<li>Download file: [[File:LinearEquationAnswer1.txt]] (change the file extension from txt to pg)</li>
 
<li>File location in NPL: <code>NationalProblemLibrary/FortLewis/Authoring/Templates/Algebra/LinearEquationAnswer1.pg</code></li>
 
</ul>
 
 
</p>
 
</p>
  +
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/EquationDefiningFunction1.pg FortLewis/Authoring/Templates/Algebra/EquationDefiningFunction1.pg]
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/EquationDefiningFunction1_PGML.pg FortLewis/Authoring/Templates/Algebra/EquationDefiningFunction1_PGML.pg]
   
  +
<br clear="all" />
 
<p style="text-align:center;">
 
<p style="text-align:center;">
 
[[SubjectAreaTemplates|Templates by Subject Area]]
 
[[SubjectAreaTemplates|Templates by Subject Area]]
Line 41: Line 41:
 
<pre>
 
<pre>
 
DOCUMENT();
 
DOCUMENT();
  +
 
loadMacros(
 
loadMacros(
 
"PGstandard.pl",
 
"PGstandard.pl",
Line 46: Line 47:
 
"parserAssignment.pl",
 
"parserAssignment.pl",
 
);
 
);
  +
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
</pre>
 
</pre>
Line 67: Line 69:
   
 
$eqn = Formula("y=5x+2");
 
$eqn = Formula("y=5x+2");
$f = Formula("f(x)=5x+2");
+
$fun = Formula("f(x)=3x^2+2x");
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 73: Line 75:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
We must allow assignment, and declare any function names we wish to use. For more details and examples in other MathObjects contexts, see [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserAssignment.pl.html parserAssignment.pl.html]
+
We must allow assignment, and declare any function names we wish to use. For more details and examples in other MathObjects contexts, see [http://webwork.maa.org/pod/pg/macros/parserAssignment.html parserAssignment.pl]
 
</p>
 
</p>
 
</td>
 
</td>
Line 83: Line 85:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
  +
Context()->texStrings;
 
BEGIN_TEXT
 
BEGIN_TEXT
 
Enter \( y = 5x+2 \) \{ ans_rule(20) \}
 
Enter \( y = 5x+2 \) \{ ans_rule(20) \}
 
$BR
 
$BR
Enter \( f(x) = 5x+2 \) \{ ans_rule(20) \}
 
  +
$BR
  +
Enter \( f(x) = 3x^2+2x \) \{ ans_rule(20) \}
 
END_TEXT
 
END_TEXT
  +
Context()->normalStrings;
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
Line 102: Line 107:
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
<pre>
  +
$showPartialCorrectAnswers = 1;
  +
 
ANS( $eqn->cmp() );
 
ANS( $eqn->cmp() );
ANS( $f->cmp() );
+
ANS( $fun->cmp() );
 
ENDDOCUMENT();
 
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
Line 146: Line 153:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Revision as of 17:58, 7 April 2021

Answer is an Equation Defining a Function

Click to enlarge

This PG code shows how to check student answers that are equations that define functions. If an equation defines a function, it is much more reliable to use the this method of answer evaluation (via parserAssignment.pl) than the implicit equation method (via parserImplicitEquation.pl)


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserAssignment.pl",
);

TEXT(beginproblem());

Initialization: We need to include the macro file parserAssignment.pl.

Context("Numeric")->variables->are(x=>"Real",y=>"Real");
parser::Assignment->Allow;
parser::Assignment->Function("f");

$eqn = Formula("y=5x+2");
$fun = Formula("f(x)=3x^2+2x");

Setup: We must allow assignment, and declare any function names we wish to use. For more details and examples in other MathObjects contexts, see parserAssignment.pl

Context()->texStrings;
BEGIN_TEXT
Enter \( y = 5x+2 \) \{ ans_rule(20) \}
$BR
$BR
Enter \( f(x) = 3x^2+2x \) \{ ans_rule(20) \}
END_TEXT
Context()->normalStrings;

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

$showPartialCorrectAnswers = 1;

ANS( $eqn->cmp() );
ANS( $fun->cmp() );

Answer Evaluation: As is the answer.


Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:


Templates by Subject Area