From WeBWorK_wiki
Revision as of 22:19, 13 June 2015 by Paultpearson (talk | contribs) (PGML example link)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Sequences and Recursively Defined Functions

Click to enlarge

This PG code shows how to add a named function to the context and use it to ask students to come up with a recursive formula.

Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:




Initialization: We will be defining a new named function and adding it to the context, and the easiest way to do this is using There is a more basic way to add functions to the context, which is explained in example 2 at AddingFunctions

parserFunction(f => "sin(pi^n)+e");

$fn = Formula("3 f(n-1) + 2");

Setup: We define a new named function f as something the student is unlikely to guess. The named function f is, in some sense, just a placeholder since the student will enter expressions involving f(n-1), WeBWorK will interpret it internally as sin(pi^(n-1))+e, and the only thing the student sees is f(n-1). If the recursion has an closed-form solution (e.g., the Fibonacci numbers are given by f(n) = (a^n - (1-a)^n)/sqrt(5) where a = (1+sqrt(5))/2) and you want to allows students to enter the closed-form solution, it would be good to define f using that explicit solution in case the student tries to answer the question by writing out the explicit solution (a^n - (1-a)^n)/sqrt(5) instead of using the shorthand f(n).

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) \).
\( f(n) \) = \{ ans_rule(20) \} 

Main Text: We should tell students to use function notation rather than subscript notation so that they aren't confused about syntax.


ANS( $fn->cmp() );

Answer Evaluation:

Solution explanation goes here.

COMMENT('MathObject version.');



Templates by Subject Area