Shows how to add a general function as an input option.
Download file: AddingFunctions.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'parserFunction.pl', 'PGcourse.pl');
Preamble
We need to load the parserFunction.pl macro, and then use one of its routines to define a new function that students may type in their answers.
Context()->variables->are(x => 'Real', y => 'Real');
parserFunction('f(x,y)' => 'sin(x*y)-exp(y)');
$ans = Compute('f(x-4,3)');
Setup
First, we define a function f(x,y). The actual function doesn’t matter but shouldn’t be easily guessed, since a student could put in sin(x*y)-exp(y) and get the answer correct.
This is a useful technique for any problem that the question is about a generic function rather than a specific one.
BEGIN_PGML
Given a surface [`z = f(x,y)`], what is the equation for the [`z`] -coordinate
of the surface along a line having [`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.