Difference between revisions of "RecursiveSequence1"

From WeBWorK_wiki
Jump to navigation Jump to search
(add historical tag and give links to newer problems.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/Sequences/RecursiveSequence.html a newer version of this problem]</p>
  +
 
<h2>Sequences and Recursively Defined Functions</h2>
 
<h2>Sequences and Recursively Defined Functions</h2>
   
[[File:Sequences1.png|300px|thumb|right|Click to enlarge]]
+
[[File:RecursiveSequence1.png|300px|thumb|right|Click to enlarge]]
 
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
 
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
 
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.
 
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.
 
</p>
 
</p>
* Download file: [[File:Sequences1.txt]] (change the file extension from txt to pg when you save it)
 
  +
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/RecursiveSequence1.pg FortLewis/Authoring/Templates/Sequences/RecursiveSequence1.pg]
* File location in NPL: <code>FortLewis/Authoring/Templates/Sequences/Sequences1.pg</code>
 
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/RecursiveSequence1_PGML.pg FortLewis/Authoring/Templates/Sequences/RecursiveSequence1_PGML.pg]
 
   
 
<br clear="all" />
 
<br clear="all" />
Line 130: Line 133:
 
Context()->texStrings;
 
Context()->texStrings;
 
BEGIN_SOLUTION
 
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
 
 
Solution explanation goes here.
 
Solution explanation goes here.
 
END_SOLUTION
 
END_SOLUTION
Line 152: Line 154:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Latest revision as of 06:44, 18 July 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

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:

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 parserFunction.pl. There is a more basic way to add functions to the context, which is explained in example 2 at AddingFunctions

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 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).

Context()->texStrings;
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
Context()->normalStrings;

Main Text: 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() );

Answer Evaluation:


Context()->texStrings;
BEGIN_SOLUTION
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area