Thanks - moving the $refreshCachedImages to before the generation of graphs "helps" - but only if I manually clear the cache (ctrl-shift-delete) between using "get a new version" If I simply hit "get a new version" without the manual clear cache, I see the same images as the original seed. How about trying the sequence generate original problem (I use update tab, view tab will use old images) with seed 323 you should get F=4 and consistent graphs. Now repeatedly hit "get a new version" and check the graphs. I get the same graphs but in different order. The right answer is always the graph with the correct answer for F=4. Now try, with the graphs for F=4, clear cache(ctrl-shift-delete) and get new version, check the graphs and repeat.
here is my current code
DOCUMENT();
loadMacros("PG.pl",
"PGstandard.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"extraAnswerEvaluators.pl",
"MathObjects.pl",
"PGcourse.pl"
);
TEXT(beginproblem());
Context("Numeric");
Context("Numeric")->functions->add(
step => {
class => 'Parser::Legacy::Numeric',
perl => 'Parser::Legacy::Numeric::do_step'
},
);
$showPartialCorrectAnswers = 1;
$refreshCachedImages = 1;
#$a = 2;
#$b = 3;
Context()->variables->add(t=>'Real');
Context()->variables->add(F=>'Real');
$func = Formula("sin(2 pi F t)");
@eq = ("\( y=-2f(-t) \)",
"\( y=2f(-t) \)",
"\( y=-2f(t) \)",
"\( y=-f \left( - \frac{1}{2} t \right) \)",
"\( y=-\frac{1}{2} f(-t) \)",
"\( y=f \left( \frac{1}{2} t \right) \)" );
@descript = ("is a reflection about both the \(t\)-axis and \(y\)-axis as well as a vertical stretch by a factor of 2.",
"is a horizontal reflection about the \(y\)-axis as well as a vertical stretch by a factor of 2.",
"is a vertical reflection about the \(t\)-axis as well as a vertical stretch by a factor of 2.",
"is a reflection about both the \(t\)-axis and \(y\)-axis as well as a horizontal stretch by a factor of 2.");
$p1[0] = FEQ("step(t) - step(t-1) for t in <-1,10> using color:blue and weight:2");
$p2[0] = FEQ("step(t) - step(t-0.5) for t in <-1,10> using color:blue and weight:2");
$p3[0] = FEQ("step(t) - step(t-2) for t in <-1,10> using color:blue and weight:2");
$p4[0] = FEQ("step(t+1) - step(t) for t in <-1,10> using color:blue and weight:2");
$p1[1] = FEQ(qq! step(t) - step(t-0.5) + step(t) - step(t-2) for t in <-1,10> using color:blue and weight:2!);
##$graphf = init_graph(@opts);
## (plot_functions($graphf,"$f for x in <-$dom,$dom> using color:blue"))[0]->steps(250);
## $labelf = new Label(@gr_lab, 'y = f(x)', 'blue' , 'center', 'center');
## $graphf->lb($labelf);
$gr = init_graph(-2,-2,10,4,'axes'=>[0,0],'ticks'=>[6,6] );
$gr->lb('reset');
for ($i = -2; $i <= 4; $i++) { if ($i != 0) {
$gr->lb(new Label(-.1,$i,$i,'black','right','middle')) }};
for ($i = -1; $i <= 5; $i++) {
$gr->lb(new Label(2*$i,-.2,2*$i,'black','center','top')) };
$gr->lb(new Label(-.2,4.5,"y",'black','right','top'));
$gr->lb(new Label(9.5,-.2,"t",'black','right','top'));
$gr->lb(new Label(3.5,4,"s(t)",'black','left','bottom'));
## parentheses in ($fn1) are necessary
($f1n) = plot_functions( $gr, $p1[1] );
$f1n->steps(200);
$orig = image(insertGraph($gr),width => 400,height => 300,tex_size => 600);
$F = random(1,5,1);
$g[0] = "sin(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[1] = "sin(2*pi*(-$F*t)) for t in <-1,1> using color:blue and weight:2";
$g[2] = "sin(pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[4] = "cos(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[3] = "-cos(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[5] = "sin(0.5*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$graph[0] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[1] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[2] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[3] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[4] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[5] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
for ($j = 0; $j <=5; $j++) {
$graph[$j]->lb('reset');
$graph[$j]->lb(new Label(-.07,-1,-1,'black','right','middle'));
$graph[$j]->lb(new Label(-.07,1,1,'black','right','middle'));
for ($i = -3; $i <= 3; $i++) { if ($i != 0) {
$graph[$j]->lb(new Label(0.25*$i,-.2,0.25*$i,'black','center','top')) }};
$graph[$j]->lb(new Label(-.05,1.9,"y",'black','right','top'));
$graph[$j]->lb(new Label(0.95,0.1,"t",'black','right','bottom'));
plot_functions( $graph[$j], $g[$j]);
$fig[$j] = image(insertGraph($graph[$j]),width => 240,height => 180,tex_size => 200); };
# $pick = random(0,3,1);
# if ( $pick != 0 ) { $temp_eq = $eqn[0];
# $temp_gr = $fig[0];
# $eq[0] = $eq[$pick];
# $fig[0] = $fig[$pick];
# $eq[$pick] = $temp_eq;
# $fig[$pick] = $temp_gr};
$mc = new_multiple_choice();
$mc->qa('On a separate piece of paper, sketch an accurate graph of this function for \( F = $F \) and \( t \in [-1, 1] \). Which (if any) of the graphs below matches the graph you drew?','$fig[0]');
$mc->extra('$fig[1] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[2] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[3] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[4] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[5] $BR $BITALIC(click on image to enlarge)$EITALIC');
$mc->makeLast('None of the above');
Context()->texStrings;
BEGIN_TEXT
This problem reflects Problem 1.21a in the text
$PAR
Consider the function
$BR
$BR
\( y = $func \).
$BR
$BR
\{ $mc->print_q() \} $BR
\{ $mc->print_a() \}
END_TEXT
Context()->normalStrings;
ANS(radio_cmp($mc->correct_ans));
## force a refresh of the image after changes
Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR
$BBOLD SOLUTION $EBOLD
$PAR
Setting \( F = $F \) gives the function \( y = \sin(2 \pi $F t) \). This has $F cycles in one unit of time. It starts at zero at t = 0, since it is a sine and is positive for the first values greater than zero. Therefore the correct graph is
$PAR
$BCENTER
$fig[0]
$ECENTER
$BR
which is answer \{ $mc->correct_ans \}.
END_SOLUTION
Context()->normalStrings;
ENDDOCUMENT();