WeBWorK Main Forum

Error displaying graphs in matching dynamic graphs problem

Error displaying graphs in matching dynamic graphs problem

by Gabriela Sanchis -
Number of replies: 3
The following code worked last semester, but now some of the graphs are not displaying. It seems to be a problem with the links to the second set of graphs. For example the link to the first graph that doesn't work is

https://courses1.webwork.maa.org:8080/wwtmp/ElizabethtownC-MA122/gif/gabriela_sanchis-1125-set10_3_Polar_Coordinates-prob8--https://courses1.webwork.maa.org:8080/wwtmp/ElizabethtownC-MA122/gif/gabriela-Q-sanchis-3828-set10-Q-3_Polar_Coordinatesprob8image1.png

but it should be just the last part: https://courses1.webwork.maa.org:8080/wwtmp/ElizabethtownC-MA122/gif/gabriela-Q-sanchis-3828-set10-Q-3_Polar_Coordinatesprob8image1.png

Here is my code. Thanks in advance for any help.

DOCUMENT();      

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
"PGunion.pl",
"imageChoice.pl",
);

TEXT(beginproblem());
$refreshCachedImages = 1;

##############################################################
#
#  Setup
#
#
Context("Numeric")->variables->are(t=>"Real",x=>"Real");

$a=random(1,5);
$b1=random(1,5);
$b=$a+$b1;
$c=random(1,5);
$d=1.1*($a+$b);
$lb="\(2\pi\)";


for ($i=0; $i<=7; $i++) {$gr[$i] = init_graph(-$d,-$d,$d,$d,axes=>[0,0],size=>[300,300]);$gr[$i]->new_color("darkgreen",    0, 208, 0);
};


#
#  For a polar curve r = f(t),
#  x = r cos(t) = f(t) cos(t)
#  y = r sin(t) = f(t) sin(t)
#

$x[0] = Formula("($b-$a*cos($c*t)) * cos(t)");
$y[0] = Formula("($b-$a*cos($c*t))* sin(t)");
$g[0]=Formula("$b-$a*cos($c*x)");

$x[1] = Formula("($b+$a*cos($c*t)) * cos(t)");
$y[1] = Formula("($b+$a*cos($c*t))* sin(t)");
$g[1]=Formula("$b+$a*cos($c*x)");

#$x[0] = Formula("($a-$b*cos($c*t)) * cos(t)");
#$y[0] = Formula("($a-$b*cos($c*t))* sin(t)");
#$g[0]=Formula("$a-$b*cos($c*x)");


#$x[1] = Formula("($a+$b*cos($c*t)) * cos(t)");
#$y[1] = Formula("($a+$b*cos($c*t))* sin(t)");
#$g[1]=Formula("$a+$b*cos($c*x)");

$x[2] = Formula("($b-$a*sin($c*t)) * cos(t)");
$y[2] = Formula("($b-$a*sin($c*t))* sin(t)");
$g[2]=Formula("$b-$a*sin($c*x)");

$x[3] = Formula("($b+$a*sin($c*t)) * cos(t)");
$y[3] = Formula("($b+$a*sin($c*t))* sin(t)");
$g[3]=Formula("$b+$a*sin($c*x)");

#$x[2] = Formula("($a-$b*sin($c*t)) * cos(t)");
#$y[2] = Formula("($a-$b*sin($c*t))* sin(t)");
#$g[2]=Formula("$a-$b*sin($c*x)");

#$x[3] = Formula("($a+$b*sin($c*t)) * cos(t)");
#$y[3] = Formula("($a+$b*sin($c*t))* sin(t)");
#$g[3]=Formula("$a+$b*sin($c*x)");

for ($i=0; $i<=3; $i++) {$gr1[$i] = init_graph(-1,-$d,7.28,$d,axes=>[0,0],size=>[300,300]);
$gr1[$i]->new_color("darkred",   255, 55, 55);
add_functions($gr1[$i], "$g[$i] for x in <0,6.28>" . " using color:darkred and weight:2");
$gr1[$i]->h_ticks(0,"black",1.57,3.14,4.71,6.28);
$gr1[$i]->v_ticks(0,"black",1);
$gr1[$i]->lb( new Label(6.28,-.5,'2pi',
    'black','center','middle'));
};

for ($i=0; $i<=3; $i++) {$f = new Fun( $x[$i]->perlFunction, $y[$i]->perlFunction, $gr[$i] );
$f->domain(0,6.28);
$f->steps(180);
$f->weight(2);
$f->color('darkgreen');
};

foreach $j (0..3) {
  $fig[$j] = image(insertGraph($gr1[$j]), 
  width => 300, height => 300, tex_size => 310);
}

@QA = ();
foreach my $i (0..3) { push( @QA, "$fig[$i]",  $gr[$i] ); }

$ml = new_image_match_list(
  link => 1,                #  do not link to separate image
  size => [300,300],        #  image size in pixels
  tex_size => 450,          #  tex size in precent times 10
  columns => 1,             #  number of columns
  separation => 20,         #  separation between image columns 
);

$ml->rf_print_q(~~&pop_up_list_print_q); # use pop-up-lists
$ml->ra_pop_up_list([ No_answer=>"?", A=>"A", B=>"B", C=>"C", D=>"D"] );

$ml->qa(@QA);               #  set the questions and answers
$ml->choose(4);             #  select 4 of them
#$ml->choose_extra(0);      #  and show the other 1##############################################################
#
#  Text
#
#

Context()->texStrings;
BEGIN_TEXT
The figures on the left show graphs of \(r\) as a function of \(\theta\) in Cartesian coordinates, where \(0\leq\theta\leq2\pi\). Match each with the corresponding polar curve shown on the right.
$PAR

\{
ColumnTable(
$ml->print_q() # no period!
, # comma!
$BCENTER.
$ml->print_a().
$BR.
$ECENTER # no period!
, # comma!
indent => 0, separation => 30, valign => "TOP"
)
\}
END_TEXT
Context()->normalStrings;

##############################################################
#
#  Answers
#
#
install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 0;

ANS(str_cmp($ml->ra_correct_ans));

foreach my $i (0..3) {
  $a[$i] = $ml->ra_correct_ans->[$i];
}
ENDDOCUMENT();


In reply to Gabriela Sanchis

Re: Error displaying graphs in matching dynamic graphs problem

by Hedley Pinsent -
Works for me and it is absolutely gorgeous.

Therefore it seems environmental. The best I can do is provide a quote about lighttpd. (which I don't use)
Maybe turn this off; maybe review the priviledges of your directories. (spoken as a "newbie")


From "Installation Manual for 2.5 on Ubuntu 12.

Implement Optional B (lighttpd)
...
Apache2 is listening on port 80 so we need an alternate port for lighttp to listen to. Standard alternate ports for this are usually 81, 8000, or 8080. 8080 is the only port that is listed as an official alternate at http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers . Note that in rare cases an installation may block httpd requests to port 8080. If any of your students report that they can not see graphics, they will have to request that access to requests to port 8080 be allowed."

In reply to Gabriela Sanchis

Re: Error displaying graphs in matching dynamic graphs problem

by Davide Cervone -
It turns out that this was due to an interaction between the alternative server for images and the unionImages.pl macro file. I have put a modified version of unionImages.pl in your templates/macros directory, so these problems should work for you now.

Davide