Difference between revisions of "GraphsInTables"
m |
|||
Line 60: | Line 60: | ||
Context("Numeric"); |
Context("Numeric"); |
||
− | $a = random(2,3,1); |
+ | $a = random(2,3,1); # -$a is the left x-intercept |
− | $b = random(2,4,2); |
+ | $b = random(2,4,2); # $b is the right x-intercept |
− | $c = random( |
+ | $c = random(1,4,1); # -$c is the y-intercept |
− | $k = |
+ | $k = $c/($a * $b); |
$A = $k; |
$A = $k; |
||
Line 81: | Line 81: | ||
<p> |
<p> |
||
<b>Setup:</b> |
<b>Setup:</b> |
||
− | Generate a graph to be included in the main text. This graph is a parabola opening |
+ | Generate a graph to be included in the main text. This graph is a parabola opening up with roots <code>-$a, $b</code> and y-intercept <code>-$c</code>. |
</p> |
</p> |
||
</td> |
</td> |
||
Line 140: | Line 140: | ||
$showPartialCorrectAnswers = 1; |
$showPartialCorrectAnswers = 1; |
||
− | ANS( List($c)->cmp() ); |
+ | ANS( List(-$c)->cmp() ); |
ANS( List(-$a,$b)->cmp() ); |
ANS( List(-$a,$b)->cmp() ); |
Revision as of 19:59, 11 February 2010
Putting Graphs into Tables
This PG code shows how to put graphs into tables so that they will be displayed compactly and a proper size in both HTML and TeX modes.
- Example 1: Putting a text block and a graph side-by-side using ColumnTable from unionTables.pl
Example 1: Putting a text block and a graph side-by-side using ColumnTable from unionTables.pl
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGgraphmacros.pl", "MathObjects.pl", "unionTables.pl", # or "PGunion.pl", ); TEXT(beginproblem()); $refreshCachedImages=1; |
Initialization:
Be sure to load |
Context("Numeric"); $a = random(2,3,1); # -$a is the left x-intercept $b = random(2,4,2); # $b is the right x-intercept $c = random(1,4,1); # -$c is the y-intercept $k = $c/($a * $b); $A = $k; $B = $k*($a - $b); $C = -($k * $a * $b); $gr = init_graph(-5,-5,5,5,axes=>[0,0],grid=>[10,10]); add_functions($gr, "$A*x**2+$B*x+$C for x in <-5,5> using color:blue and weight:2"); $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')); |
Setup:
Generate a graph to be included in the main text. This graph is a parabola opening up with roots |
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). $BR. $BR. "(b) \( f \big( \) ".ans_rule(7)." \( \big) = 0 \). ", # comma! image(insertGraph($gr), width=>400, height=>400, tex_size=>700). $BR.$BCENTER. "(Click on graph to enlarge)". $ECENTER, # comma! indent => 0, separation => 30, valign => "TOP" ) \} END_TEXT Context()->normalStrings; |
Main Text:
We use Using ColumnTable has two main advantages.
|
$showPartialCorrectAnswers = 1; ANS( List(-$c)->cmp() ); ANS( List(-$a,$b)->cmp() ); ENDDOCUMENT(); |
Answer Evaluation:
Since there may be multiple answers, we use |