## PREP 2014 Question Authoring - Archived

### refreshing dynamic graphs ### refreshing dynamic graphs

by Joel Trussell -
Number of replies: 5
I can't get the webwork to refresh the dynamic graph. I have set
$refreshCachedImages = 1; DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "PGgraphmacros.pl", "unionTables.pl", "PGanswermacros.pl", "PGchoicemacros.pl", "PGgraphmacros.pl", "extraAnswerEvaluators.pl", "parserCustomization.pl" ); TEXT(beginproblem()); Context(Complex)->variables->are(t=>"Real",F=>"Real",a=>"Real",w=>"Real");$showPartialCorrectAnswers = 1;
$a = random(1,9,1);$b = random(2,1,9);
$w_max = 10;$func = Formula("$a*j*w/($b + (j*w)**2)");

@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 = FEQ("sin(t) for t in <-1,10> using color:blue and weight:2");$p2 = FEQ("cos(t) for t in <-1,10> using color:blue and weight:2");
$p3 = FEQ("exp(t) for t in <-1,10> using color:blue and weight:2");$p4 = FEQ("sin(t+1)  for t in <-1,10> using color:blue and weight:2");
$p1 = FEQ(qq! sin(t)- cos(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"))->steps(250);
## $labelf = new Label(@gr_lab, 'y = f(x)', 'blue' , 'center', 'center'); ##$graphf->lb($labelf);$gr = init_graph(-1,$w_max,10,4,'axes'=>[0,0],'ticks'=>[10,6] );$gr->lb('reset');
for ($i = -1;$i <= $wmax;$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 );$f1n->steps(200);

$orig = image(insertGraph($gr),width => 400,height => 300,tex_size => 600);

$F = random(1,5,1);$g = "abs($a*j*w/($b + (j*w)**2)) for w in <0,$w_max> using color:blue and weight:2";$g = "abs(2*$a*j*w/($b + (j*w)**2)) for w in <0,$w_max> using color:blue and weight:2";$g = "abs($a*j*w/($b - (j*w)**2)) for w in <0,$w_max> using color:blue and weight:2";$g = "abs($a*j*w/($b + 10*(j*w)**2)) for w in <0,$w_max> using color:blue and weight:2";$g = "abs($a*j*w/($b + (j*w))) for w in <0,$w_max> using color:blue and weight:2";$g = "abs($a*j*w/(($b + (j*w))**2)) for w in <0,$w_max> using color:blue and weight:2"; for ($j = 0; $j <=5;$j++) {
$graph[$j] = init_graph(0,-1,$w_max,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,"|H|",'black','right','top'));
$graph[$j]->lb(new Label(0.95,0.1,"w",'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;
#                    $temp_gr =$fig;
#                    $eq =$eq[$pick]; #$fig = $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 the magnitude of this function, $$|H(w)|$$, for $$w$$ and $$w \in [0, w_max]$$.  Which (if any) of the graphs below matches the graph you drew?','$fig');$mc->extra('$fig$BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig$BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig$BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig$BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig$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
Plotting graphs of complex functions
$PAR Consider the complex valued function$BR
$BR $$H(w) = func$$.$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$ECENTER
$BR which is answer \{$mc->correct_ans \}.

END_SOLUTION
Context()->normalStrings;

ENDDOCUMENT(); ### Re: refreshing dynamic graphs

by Davide Cervone -
It may be that the browser it caching the image, not WeBWorK. Make sure you do a "forced reload" in your browser, which should cause it to reload the images if they have changed. How you do that depends on the browser you are using. ### Re: refreshing dynamic graphs

by Joel Trussell -
I looked up forcing reload and tried a couple of those - last one for chrome was ctrl/shft/del and clearing images. I tried a ctrl/R and ctrl/F5 for firefox. I've zero'ed out one of my graphs but this still doesn't show. Where are the dynamic graphics stored in webwork? or do they exist only in the browser chache? ### Re: refreshing dynamic graphs

by Arnold Pizer -
Hi,

Where images are stored in WeBWorK depends on how you set things up.  Place the cursor over the image and look at the path to the image.  If you see webwork2_files, that is the directory /opt/webwork/webwork2/htdocs.  If you see something else (e.g. wwtmp), your should know where you put that (maybe /var/www/wwtmp or /var/www/html/wwtmp).

Arnie ### Re: refreshing dynamic graphs

by Joel Trussell -
OK - found the folder  but I don't have permission as a course manager. Need to be an admin. I'll have to leave it to him.

any suggestions for me at this point? I've tried a entirely new browser (MS Internet Explorer, which I hate) but I get the same images You might try moving the $refreshCachedImages = 1 to earlier in the problem. Currently, it is after the image is referenced the problem. I'm not sure when it has its effect, but I suspect the image is created and linked in at the point where the image is referenced, and that is probably where the value of $refreshCachedImages is used. Changing it afterword would have no effect in that case.