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).
Download file: EquationsDefiningFunctions.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'parserAssignment.pl', 'PGcourse.pl');
Preamble
Include the macro parserAssignment.pl.
Context('Numeric')->variables->are(x => 'Real', y => 'Real');
parser::Assignment->Allow;
parser::Assignment->Function('f');
$eqn = Formula('y = 5x + 2');
$f = Formula('f(x) = 5x + 2');
Setup
Set the variables in the context to be x and
y, enable assignments in the context, and declare that the
function f may be used on the left side of an
assignment.
For more details see parserAssignment.pl.
BEGIN_PGML
Enter [`y = 5x + 2`]: [___]{$eqn}
Enter [`f(x) = 5x + 2`]: [___]{$f}
END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.