Difference between revisions of "RecursivelyDefinedFunctions"
Line 108: | Line 108: | ||
[[Category:Problem Techniques]] |
[[Category:Problem Techniques]] |
||
+ | |||
+ | |||
+ | |||
+ | <ul> |
||
+ | <li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserFunction.pl.html parserFunction.pl.html]</li> |
||
+ | <li>PG macro: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/parserFunction.pl parserFunction.pl]</li> |
||
+ | </ul> |
Revision as of 14:15, 21 March 2010
Recursively Defined Functions
This PG code shows how to check student answers that are recursively defined functions.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "parserFunction.pl", ); TEXT(beginproblem()); |
Initialization:
We will be defining a new named function and adding it to the context, and the easiest way to do this is using |
Context("Numeric")->variables->are(n=>"Real"); parserFunction(f => "sin(pi^n)+e"); $fn = Formula("3 f(n-1) + 2"); |
Setup:
We define a new named function |
BEGIN_TEXT The current value \( f(n) \) is three times the previous value, plus two. Find a recursive definition for \( f(n) \). Enter \( f_{n-1} \) as \( f(n-1) \). $BR \( f(n) \) = \{ ans_rule(20) \} END_TEXT |
Main Text: The problem text section of the file is as we'd expect. We should tell students to use function notation rather than subscript notation so that they aren't confused about syntax. |
$showPartialCorrectAnswers=1; ANS( $fn->cmp() ); ENDDOCUMENT(); |
Answer Evaluation: As is the answer. |
- POD documentation: parserFunction.pl.html
- PG macro: parserFunction.pl