Shows how to add a general function as an input option.
Download file: DefiningFunctions.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'parserFunction.pl', 'PGcourse.pl');
Preamble
Load the parserFunction.pl macro which is used to add a new function to the context.
Context()->variables->are(x => 'Real', y => 'Real');
parserFunction('f(x,y)' => 'sin(x * y) - exp(y)');
$ans = Compute('f(x - 4, 3)');
Setup
Define a function f(x,y). The actual function doesn’t
matter but shouldn’t be easily guessed, since a student could enter it
and get the answer correct. This is a useful technique for any problem
adking is about a generic function rather than a specific one.
BEGIN_PGML
Given a surface defined by [`z = f(x, y)`], what is the equation for the
[`z`]-coordinate of the surface along the line [`y = 3`], shifted four units to
the right?
[`z =`] [_____]{$ans}
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.