TableOfValues1: Difference between revisions
Jump to navigation
Jump to search
(Created page with '<h2>Fill in a Table of Values for a Function</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> This PG code shows how to create a table with answer b…') |
(add historical tag and give links to newer problems.) |
||
(10 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/Algebra/TableOfValues.html a newer version of this problem]</p> | |||
<h2>Fill in a Table of Values for a Function</h2> | <h2>Fill in a Table of Values for a Function</h2> | ||
<p style="background-color:# | [[File:TableOfValues1.png|300px|thumb|right|Click to enlarge]] | ||
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;"> | |||
This PG code shows how to create a table with answer blanks in it. | This PG code shows how to create a table with answer blanks in it. | ||
</p> | </p> | ||
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/TableOfValues1.pg FortLewis/Authoring/Templates/Precalc/TableOfValues1.pg] | |||
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/TableOfValues1_PGML.pg FortLewis/Authoring/Templates/Precalc/TableOfValues1_PGML.pg] | |||
<br clear="all" /> | |||
<p style="text-align:center;"> | <p style="text-align:center;"> | ||
[[SubjectAreaTemplates|Templates by Subject Area]] | [[SubjectAreaTemplates|Templates by Subject Area]] | ||
Line 65: | Line 70: | ||
<pre> | <pre> | ||
Context("Numeric"); | Context("Numeric"); | ||
$f = Formula("3^(-x)"); | |||
@answer = (); | @answer = (); | ||
foreach my $i (0..2) { | foreach my $i (0..2) { | ||
$answer[$i] = $f->eval(x=>$i); | $answer[$i] = $f->eval(x=>$i); | ||
Line 78: | Line 82: | ||
<p> | <p> | ||
<b>Setup:</b> | <b>Setup:</b> | ||
We create an empty array <code>@answer</code> and use a foreach loop to simplify filling it with values. | |||
</p> | </p> | ||
</td> | </td> | ||
Line 106: | Line 111: | ||
<p> | <p> | ||
<b>Main Text:</b> | <b>Main Text:</b> | ||
Notice that the table is inside a Perl code block <code>\{ \}</code> and that there are periods at the end of each line (after each of the subroutines <code>begintable(num | Notice that the table is inside a Perl code block <code>\{ \}</code> and that there are periods at the end of each line (after each of the subroutines <code>begintable(num cols)</code> and <code>row( )</code>) except for the last line. These periods are Perl's string concatenation operator. | ||
</p> | </p> | ||
</td> | </td> | ||
Line 159: | Line 164: | ||
[[Category:Top]] | [[Category:Top]] | ||
[[Category: | [[Category:Sample Problems]] | ||
[[Category:Subject Area Templates]] |
Latest revision as of 10:05, 18 July 2023
This problem has been replaced with a newer version of this problem
Fill in a Table of Values for a Function

This PG code shows how to create a table with answer blanks in it.
- File location in OPL: FortLewis/Authoring/Templates/Precalc/TableOfValues1.pg
- PGML location in OPL: FortLewis/Authoring/Templates/Precalc/TableOfValues1_PGML.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", ); TEXT(beginproblem()); |
Initialization: |
Context("Numeric"); $f = Formula("3^(-x)"); @answer = (); foreach my $i (0..2) { $answer[$i] = $f->eval(x=>$i); } |
Setup:
We create an empty array |
Context()->texStrings; BEGIN_TEXT If \( f(x) = $f \), fill in the table of values with numbers. \{ AnswerFormatHelp("numbers") \} $PAR $BCENTER \{ begintable(5) . row( "\(x = \)", "0", "1", "2" ) . row( "\(f(x) = \)", ans_rule(5), ans_rule(5), ans_rule(5) ) . endtable(); \} $ECENTER END_TEXT Context()->normalStrings; |
Main Text:
Notice that the table is inside a Perl code block |
$showPartialCorrectAnswers = 1; foreach my $i (0..2) { ANS( $answer[$i]->cmp() ); } |
Answer Evaluation: |
Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); |
Solution: |