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
In the initialization section, we need to include the macros file 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
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.
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.