Difference between revisions of "ExplicitSequence1"

From WeBWorK_wiki
Jump to navigation Jump to search
(PGML example link)
(switch to PGML and remove answerFormatHelp.pl macro)
Line 5: Line 5:
 
This PG code shows how to evaluate answers that are (possibly alternating) sequences with explicit formulas.
 
This PG code shows how to evaluate answers that are (possibly alternating) sequences with explicit formulas.
 
</p>
 
</p>
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/ExplicitSequence1.pg FortLewis/Authoring/Templates/Sequences/ExplicitSequence1.pg]
+
<!--* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/ExplicitSequence1.pg FortLewis/Authoring/Templates/Sequences/ExplicitSequence1.pg]-->
 
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/ExplicitSequence1_PGML.pg FortLewis/Authoring/Templates/Sequences/ExplicitSequence1_PGML.pg]
 
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/ExplicitSequence1_PGML.pg FortLewis/Authoring/Templates/Sequences/ExplicitSequence1_PGML.pg]
   
Line 16: Line 16:
   
 
<tr valign="top">
 
<tr valign="top">
<th> PG problem file </th>
+
<th style="width: 50%"> PG problem file </th>
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
Line 42: Line 42:
 
DOCUMENT();
 
DOCUMENT();
   
loadMacros(
 
  +
loadMacros('PGstandard.pl','MathObjects.pl','PGML.pl','PGcourse.pl');
"PGstandard.pl",
 
"MathObjects.pl",
 
"AnswerFormatHelp.pl",
 
);
 
 
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
</pre>
 
</pre>
Line 64: Line 59:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Numeric");
+
Context('Numeric');
Context()->variables->are(n=>"Real");
+
Context()->variables->are(n=>'Real');
   
 
$answer = Compute("(-1)^n / n!");
 
$answer = Compute("(-1)^n / n!");
 
$answer->{test_points} = [[1],[2],[3],[4],[5],[6]];
 
$answer->{test_points} = [[1],[2],[3],[4],[5],[6]];
   
@seq = (
 
  +
$sequence = 'a_0=1, a_1 = -1, a_2 = \frac{1}{2}, a_3 = -\frac{1}{6}'
"a_0 = 1",
 
  +
. 'a_4 = \frac{1}{24}, a_5 = -\frac{1}{120}, \ldots';
"a_1 = -1",
 
"a_2 = \frac{1}{2}",
 
"a_3 = -\frac{1}{6}",
 
"a_4 = \frac{1}{24}",
 
"a_5 = -\frac{1}{120}",
 
"\ldots"
 
);
 
 
$sequence = join(", ", @seq);
 
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 87: Line 73:
 
<b>Setup:</b>
 
<b>Setup:</b>
 
We set the test points to be positive integers to avoid errors when evaluating the answer. Even if you expect students to enter answers such as <code>cos(pi * n) / n!</code>, you should still restrict the domain to positive integers, because some students may simplify this to <code>(-1)^n / n!</code> and receive errors because the answer checker is substituting things such as <code>n=0.5</code> into their formula.
 
We set the test points to be positive integers to avoid errors when evaluating the answer. Even if you expect students to enter answers such as <code>cos(pi * n) / n!</code>, you should still restrict the domain to positive integers, because some students may simplify this to <code>(-1)^n / n!</code> and receive errors because the answer checker is substituting things such as <code>n=0.5</code> into their formula.
</p>
 
<p>
 
We create an array of strings <code>@seq</code> and use Perl's join function to paste the entries in this array together into one long string with entries separated by commas.
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 99: Line 82:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
  +
Find a formula for [` n^{th} `] term of the sequence [` [$sequence] `].
Find a formula for \( n^{th} \) term of the sequence \( $sequence \).
 
  +
$BR
 
  +
[` a_n = `] [__________________]{$answer}
$BR
 
  +
\( a_n = \)
 
  +
[@ helpLink('formulas') @]*
\{ ans_rule(20) \}
 
  +
END_PGML
\{ AnswerFormatHelp("formulas") \}
 
END_TEXT
 
Context()->normalStrings;
 
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
Line 116: Line 96:
 
</td>
 
</td>
 
</tr>
 
</tr>
 
<!-- Answer evaluation section -->
 
 
<tr valign="top">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
$showPartialCorrectAnswers = 1;
 
 
ANS( $answer->cmp() );
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<b>Answer Evaluation:</b>
 
</p>
 
</td>
 
</tr>
 
 
 
<!-- Solution section -->
 
<!-- Solution section -->
   
Line 138: Line 101:
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML_SOLUTION
BEGIN_SOLUTION
 
 
Solution explanation goes here.
 
Solution explanation goes here.
END_SOLUTION
 
  +
END_PGML_SOLUTION
Context()->normalStrings;
 
 
COMMENT('MathObject version.');
 
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();

Revision as of 09:55, 4 April 2023

Sequences with Explicit Formulas

Click to enlarge

This PG code shows how to evaluate answers that are (possibly alternating) sequences with explicit formulas.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros('PGstandard.pl','MathObjects.pl','PGML.pl','PGcourse.pl');
TEXT(beginproblem());

Initialization:

Context('Numeric');
Context()->variables->are(n=>'Real');

$answer = Compute("(-1)^n / n!");
$answer->{test_points} = [[1],[2],[3],[4],[5],[6]];

$sequence = 'a_0=1, a_1 = -1, a_2 = \frac{1}{2}, a_3 = -\frac{1}{6}'
  . 'a_4 = \frac{1}{24}, a_5 = -\frac{1}{120}, \ldots';

Setup: We set the test points to be positive integers to avoid errors when evaluating the answer. Even if you expect students to enter answers such as cos(pi * n) / n!, you should still restrict the domain to positive integers, because some students may simplify this to (-1)^n / n! and receive errors because the answer checker is substituting things such as n=0.5 into their formula.

BEGIN_PGML
Find a formula for [` n^{th} `] term of the sequence [` [$sequence] `].

[` a_n = `] [__________________]{$answer}

[@ helpLink('formulas') @]*
END_PGML

Main Text:

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution:

Templates by Subject Area