I'm not discovering my error, so I'm asking for help. The problem generates a sinusoid with random frequency and asks students to identify the graph of the function. It works the first time, but fails to work when the student or prof uses get a new version of the problem. The frequency is changed in the question formulation, but the graphs are not changed. I've checked the macro files, set $refreshCachedImages = 1 in various places.

Here's the code, Thanks

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;

#$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');

## force a refresh of the image after changes

$refreshCachedImages = 1;

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

$refreshCachedImages = 1;

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();