Difference between revisions of "DynamicGraph1"
(add historical tag and give links to newer problems.) |
|||
(5 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/DynamicGraph.html a newer version of this problem]</p> |
||
+ | |||
+ | |||
<h2>Dynamically Generated Graph</h2> |
<h2>Dynamically Generated Graph</h2> |
||
Line 5: | Line 10: | ||
This PG code shows how to create a dynamically generated graph with labels that is appropriately sized and positioned. |
This PG code shows how to create a dynamically generated graph with labels that is appropriately sized and positioned. |
||
</p> |
</p> |
||
− | * Download file: [[File:DynamicGraph1.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/Precalc/DynamicGraph1.pg FortLewis/Authoring/Templates/Precalc/DynamicGraph1.pg] |
||
− | * File location in NPL: <code>FortLewis/Authoring/Templates/Precalc/DynamicGraph1.pg</code> |
||
+ | * PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/DynamicGraph1_PGML.pg FortLewis/Authoring/Templates/Precalc/DynamicGraph1_PGML.pg] |
||
<br clear="all" /> |
<br clear="all" /> |
||
Line 58: | Line 63: | ||
<p> |
<p> |
||
<b>Initialization:</b> |
<b>Initialization:</b> |
||
− | It is important to set <code>$refreshCachedImages = 1</code> if you want the image to be generated and delivered every time the page is refreshed, otherwise a cached image may be used. |
+ | Dynamically generated graphs require <code>PGgraphmacros.pl</code>, and we will use <code>unionTables.pl</code> to put the text and the graph side-by-side in two columns. It is important to set <code>$refreshCachedImages = 1</code> if you want the image to be generated and delivered every time the page is refreshed, otherwise a cached image may be used. |
</p> |
</p> |
||
</td> |
</td> |
||
Line 153: | Line 158: | ||
</p> |
</p> |
||
<p> |
<p> |
||
− | Using a <code>ColumnTable</code> is best because in HTML mode the text and graph will be side by side, while in the PDF output the columns will be stacked on top of each other so that the text is on top of the graph. Pay attention to the size of your graph in HTML and in PDF output, and make it big enough to read easily in either format |
+ | Using a <code>ColumnTable</code> is best because in HTML mode the text and graph will be side by side, while in the PDF output the columns will be stacked on top of each other so that the text is on top of the graph. Pay attention to the size of your graph in HTML and in PDF output, and make it big enough to read easily in either format. |
+ | </p> |
||
+ | <p> |
||
+ | Many existing questions generate image files with larger dimensions than necessary, but scale them down so as to be unreadable in HTML and PDF output, which makes them hard or impossible to use. If you have the time to make a graph, take the extra time to make it an appropriate size in both HTML and PDF output. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 207: | Line 212: | ||
[[Category:Top]] |
[[Category:Top]] |
||
− | [[Category: |
+ | [[Category:Sample Problems]] |
+ | [[Category:Subject Area Templates]] |
Latest revision as of 05:03, 18 July 2023
This problem has been replaced with a newer version of this problem
Dynamically Generated Graph
This PG code shows how to create a dynamically generated graph with labels that is appropriately sized and positioned.
- File location in OPL: FortLewis/Authoring/Templates/Precalc/DynamicGraph1.pg
- PGML location in OPL: FortLewis/Authoring/Templates/Precalc/DynamicGraph1_PGML.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "PGgraphmacros.pl", "unionTables.pl", ); TEXT(beginproblem()); $refreshCachedImages = 1; |
Initialization:
Dynamically generated graphs require |
Context("Numeric"); $a = random(2,3,1); # left x-intercept $b = random(2,4,2); # right x-intercept $c = random(5,6,1); # y-intercept $k = -($c)/($a * $b); $A = $k; $B = $k*($a - $b); $C = -($k * $a * $b); # # Graph canvas # $gr = init_graph(-5,-1,5,9,axes=>[0,0],grid=>[10,10],size=>[300,300]); $gr -> lb('reset'); # # Graph labels and functions # $gr -> lb(new Label ( 4.5,0,'x','black','left','bottom')); $gr -> lb(new Label ( 0.25,8.5,'y','black','left','bottom')); $gr -> lb(new Label ( 0.25,$c,'y = f(x)','black','left','bottom')); foreach my $i (1..4) { $gr -> lb(new Label ( $i,-0.5, $i,'black','center','middle')); $gr -> lb(new Label (-$i,-0.5,-$i,'black','center','middle')); } foreach my $j (1..8) { $gr -> lb(new Label (-4.5,$j,$j,'black','center','middle')); } add_functions($gr, "$A*x**2+$B*x+$C for x in <-5,5> using color:blue and weight:2"); |
Setup:
For more details on the graph object |
Context()->texStrings; BEGIN_TEXT \{ ColumnTable( "Use the graph to find the missing values. There may be more than one correct answer, in which case you should enter your answers as a comma separated list. If there are no correct answers, enter ${BITALIC}NONE.${EITALIC} $BR $BR (a) \( f(0) = \) " . ans_rule(7).$SPACE. AnswerFormatHelp("numbers"). "$BR $BR (b) \( f \big( \) ".ans_rule(7)." \( \big) = 0 \). ". AnswerFormatHelp("numbers") , image(insertGraph($gr), width=>300, height=>300, tex_size=>700). $BR.$BCENTER. $BR. "Graph of \( y = f(x) \)". $ECENTER , indent => 0, separation => 30, valign => "TOP" ) \} END_TEXT Context()->normalStrings; |
Main Text:
We use a two column format provided by
Using a Many existing questions generate image files with larger dimensions than necessary, but scale them down so as to be unreadable in HTML and PDF output, which makes them hard or impossible to use. If you have the time to make a graph, take the extra time to make it an appropriate size in both HTML and PDF output. |
$showPartialCorrectAnswers = 1; ANS(List($c)->cmp() ); ANS(List(-$a,$b)->cmp() ); |
Answer Evaluation: |
Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); |
Solution: |