Forums

Search results: 163

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


Hi Paul,

Below is some code for drawing number lines that you may be able to modify to meet your needs (I omitted the problem text and only inserted one of the three graphs).

Best regards,

Paul Pearson


####################################
# Initialization

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
);

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


####################################
# Setup

Context("Numeric")->variables->are(x=>"Real");

foreach my $i (0..2) {
$gr[$i] = init_graph(-6,-1,6,1, size=>[408,68]);
# x-axis
$gr[$i] -> moveTo(-6,0);
$gr[$i] -> lineTo(6,0,'black','1');
# x-axis ticks entered as y-value, color, list of x-values
$gr[$i] -> h_ticks(0,"black",-5,-4,-3,-2,-1,0,1,2,3,4,5);
# labels for tickmarks
foreach my $j (0..5) {
$gr[$i]->lb( new Label($j,-0.5,$j, 'black','center','middle'));
$gr[$i]->lb( new Label(-$j,-0.5,-$j, 'black','center','middle'));
}
}


$gr[0] -> stamps( closed_circle(-4,0,'blue') );
$gr[0] -> stamps( closed_circle(4,0,'blue') );

$gr[1] -> moveTo(-4,0);
$gr[1] -> lineTo(4,0,'blue',3);
$gr[1] -> stamps( open_circle(-4,0,'blue') );
$gr[1] -> stamps( open_circle(4,0,'blue') );

$gr[2] -> moveTo(-4,0);
$gr[2] -> arrowTo(-6,0,'blue',3);
$gr[2] -> moveTo(4,0);
$gr[2] -> arrowTo(6,0,'blue',3);
$gr[2] -> stamps( open_circle(-4,0,'blue') );
$gr[2] -> stamps( open_circle(4,0,'blue') );

BEGIN_TEXT

\{ image(insertGraph($gr[0]), width=>408, height=>68, tex_size=>700); \}

END_TEXT

ENDDOCUMENT();
Well, here it is - version 2

In so far as the @caseList needs to be modified, to have anything practical, it is more of a "kit" than a problem.
However all the bugs are assembled in the one place

To have a mixture of pythagoras: solve for hyp/ solve for leg:

@caseList = (0,0,1,1);
@caseList = @caseList [NchooseK(scalar @caseList,scalar @caseList)];

would give 2 of each, randomized.

I have assigned from preliminary versions: no complaints yet.
However, I only have 40 math students ( and not all "cases" are addressed)
I am not scheduled to teach triangles again until next fall.

If you use it, let me know where the bugs are.

hp



## Example from here to end vvvvvvvvvvvvvvvvvvvvvvv

##DESCRIPTION
## DBsubject('Trigonometry')
## DBchapter('Triangles')
## DBsection('')
## KEYWORDS('Pythagoras', 'Law of Sines','Law of Cosines')
## Author('Hedley Pinsent')
## Institution('College of the North Atlantic')
##
## This program is more of a KIT than a problem
## To have anything practical you need to adjust the contents of "@caseList"
## After it becomes as "good as it can be" it should be split into
## more manageable, ready-to-use pieces.
##
##ENDDESCRIPTION

DOCUMENT();

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"PGgraphmacros.pl",
"PGasu.pl",
"unionTables.pl","unionMacros.pl"
);
#######################
TEXT($BEGIN_ONE_COLUMN,beginproblem()) ;
$refreshCachedImages = 1;
$showPartialCorrectAnswers = 1;
###############
# case 0 - LL90 pythagoras
# case 0.1 LL90 pythagoras - small numbers
# case 0.1 LL90 pythagoras - large numbers
# case 0.1 LL90 pythagoras - scientific notation
# case 1 - HL90 pythagoras
#etc
#
# case 2 - LL90 solve
# case 3 - HL90 solve
# case 4 - AL90 solve
# case 5 - AH90 solve
# case 6 - sss - random largest angle
# case 7 - sss - one angle obtuse
# case 8 - sas cosine law acute -random
# case 9 sas cosine law acute with unknown obtuse
# case 10 - sas cosine law - given obtuse
# case 11 - ass acute
# case 12 - ass obtuse
# case 13 - asa

###########################################

@caseList = (0,0.1,0.2,0.3,1,2,3,4,5,6,7,8,9,10,11,12,13);
#@caseList = @caseList [NchooseK(scalar @caseList,scalar @caseList)];

$trial = 0;
$deg = "".sprintf("%c",0xb0);
@n3k = NchooseK(3,3);

foreach my $caseList (@caseList) {
# do something for each frame
$trial = $trial + 1;
$TABLEoverride = 0;

$case = @caseList[$trial - 1];
$fact =1;
$numberType = round (10* ($case - int($case)));

if ($numberType == 1){$fact = list_random (0.01,0.001,0.0001)}
if ($numberType == 2){$fact = list_random (100,1000,10000)}
if ($numberType == 3){$fact = list_random (10**30,10**31,10**-21,10**-20)}

$case = int($case);

if( scalar (@list) <2){@list = (5,6,7,8,9,10,11,12,13,14,15);
@list = @list [NchooseK(11,11)];
@list = (@list,@list[0,2,4,6,8,10,1,3,5,7,9])
}

if( scalar (@listsd) <1){@listsd = (4,5,6,7,8,9);
@listsd = @listsd [NchooseK(6,6)];
@listdd = (11,12,13,14,15,16);
@listdd = @listdd [NchooseK(6,6)];

@listsd = (@listsd, @listsd,@listsd);
@listdd = (@listdd,@listdd[1,2,3,4,5,0], @listdd[2,3,4,5,0,1])
}
if( scalar (@AcuteList) <2){@AcuteList = (20,30,40,55,65,75);
@AcuteList = @AcuteList [NchooseK(6,6)];
@AcuteList = (@AcuteList,@AcuteList[0,1,3,5,2,4])}

if( scalar (@SmallAcuteList) <2){@SmallAcuteList = (10,15,20,25,30,35);
@SmallAcuteList = @SmallAcuteList [NchooseK(6,6)];
@SmallAcuteList = (@SmallAcuteList,@SmallAcuteList[0,1,3,5,2,4])}

if( scalar (@ObtuseList) <2){@ObtuseList = (110,130,140,155 ,115,135);
@ObtuseList = @ObtuseList [NchooseK(6,6)];
@ObtuseList = (@ObtuseList,@ObtuseList[0,1,3,5,2,4])}

@listSingleDigit = (4,5,6,7,8,9);
@listDoubleDigit = (11,12,13,14,15,16);

@n3k = @n3k[1,2,0];
if($trial/3 == int($trial/3)){@n3k = @n3k[0,2,1]}

@n3k_mix_letters = NchooseK(3,3);

# Sets of labels vvvvvvvvvvvvvvvvvvvv
@Angles = ("A","B","C","W","X","Y","X","Y","Z","I","J","K");
@Sides = ("a","b","c","w","x","y","x","y","z","i","j","k");
$tmpSTART = random(0,9,3);
$AL = @Angles[$tmpSTART + $n3k_mix_letters[0]];
$LL[$n3k[0]] = $AL;
$BL = @Angles[$tmpSTART + $n3k_mix_letters[1]];
$LL[$n3k[1]] = $BL;
$CL = @Angles[$tmpSTART + $n3k_mix_letters[2]];
$LL[$n3k[2]] = $CL;
$aL = @Sides[$tmpSTART + $n3k_mix_letters[0]];
$ll[$n3k[0]] = $aL;
$bL = @Sides[$tmpSTART + $n3k_mix_letters[1]];
$ll[$n3k[1]] = $bL;
$cL = @Sides[$tmpSTART + $n3k_mix_letters[2]];
$ll[$n3k[2]] = $cL;
# Sets of labels ^^^^^^^^^^^^^^^^^^^

if ($case == 0){ ###LL90 find hyptoneuse only, large numbers

$x[1] = pop @listsd;
$X[0] = 90;
$x[2] = pop @listdd; # the other leg

$x[0] = sqrt($x[1]**2 + $x[2]**2 ); #the hypotenuse
$X[1] = 180 / $PI * asin( $x[1] / $x[0] );
$X[2] = 180 - $X[0] - $X[1];

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact} #scale the problem

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "";
$b = $x[$n3k[1]];
$given[1] = "= ".sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "= ". sprintf("%G",$x[2]);

$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];


$TableOverRide = 1;
##Constructing the data table vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
$table = BeginTable(spacing => 3);


$table .= AlignedRow(["The length of side $ll[0] is ",NAMED_ANS_RULE("answer".$trial,6)]);


push @namedCmp , "answer".$trial=>num_cmp( $x[0], tolType => "absolute", tolerance=>0.03 * $x[0] ) ;

$table .= EndTable();
}

if ($case == 1){ ###HL90 missing side only

$x[1] = pop @list;
$X[0] = 90;

$x[0] = random(int(1.2 * $x[1] + 1),int(5 * $x[1])); # the hypotenuse

$X[1] = 180 / $PI * asin( $x[1] / $x[0] );
$X[2] = 180 - $X[0] - $X[1];

$x[2] = sqrt($x[0]**2 - $x[1]**2 );

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];


$TableOverRide = 1;
##Constructing the data table vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
$table = BeginTable(spacing => 3);


$table .= AlignedRow(["The length of side $ll[2] is ",NAMED_ANS_RULE("answer".$trial,6)]);


push @namedCmp , "answer".$trial=>num_cmp( $x[2],tolType => "absolute", tolerance=>0.03 * $x[2] ) ;




$table .= EndTable();
}

if ($case == 2){ ###LL90 solve scientific notation

$x[1] = pop @listsd;
$X[0] = 90;
$x[2] = pop @listdd; # the other leg
$x[0] = sqrt($x[1]**2 + $x[2]**2 ); #the hypotenuse
$X[1] = 180 / $PI * asin( $x[1] / $x[0] );
$X[2] = 180 - $X[0] - $X[1];

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "";
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "= ". sprintf("%G",$x[2]);
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($ll[0] => $x[0],$LL[1] => $X[1], $LL[2] => $X[2] );
}

if ($case == 3){ ###HL90 solve scientific notation

$x[1] = pop @listsd;
$X[0] = 90;

$x[0] = pop @listdd; # the hypotenuse

$X[1] = 180 / $PI * asin( $x[1] / $x[0] );
$X[2] = 180 - $X[0] - $X[1];
$x[2] = sqrt($x[0]**2 - $x[1]**2 );

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";

$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;

#%QA = ($LL[2] => $X[2],$LL[1] => $X[1], $ll[2] => $x[2] );

%QA = ($ll[2] => $x[2], $LL[1]=>$X[1] , $LL[2]=>$X[2]);
}

if ($case == 4){ ###as90 scientific notation

# given vvvvvvvvvvvvvvv
$x[1] = pop @list;
$X[0] = pop @AcuteList;

$X[2] = 90;
# given ^^^^^^^^^^^^^^^^^^^^^^
$X[1] = 180 - $X[0] - $X[2] ;
$x[2] = $x[1] / sin ($PI / 180 * $X[1]);
$x[0] = sin ($PI / 180 * $X[0]) * $x[1] / sin ($PI / 180 * $X[1]);


for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "=".$X[2].$deg;
$a = $x[$n3k[0]];
$given[0] = "";
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($ll[0] => $x[0],$ll[2] => $x[2], $LL[1] => $X[1] );

}

if ($case == 5){ ###ah90 -scientific notation

# given vvvvvvvvvvvvvvv
$x[1] = pop @list;
$X[0] = pop @AcuteList;

$X[1] = 90;
# given ^^^^^^^^^^^^^^^^^^^^^^

$X[2] = 180 - $X[0] - $X[1] ;
$x[2] = sin ($PI / 180 * $X[2]) * $x[1] ;
$x[0] = sin ($PI / 180 * $X[0]) * $x[1] ;

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = " = ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = " = ".$X[1].$deg;
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "";
$b = $x[$n3k[1]];
$given[1] = " = ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($ll[0] => $x[0],$ll[2] => $x[2], $LL[2] => $X[2] );
}
if ($case == 6){ ###sss random largest angle - scientific notation

@printtest = @list;
$x[0] = pop @list;
$x[1] = pop @list;
$x[2] = random( abs($x[0] - $x[1])+2, $x[0] + $x[1] - 2 );

#use cosine law to find angles
$X[0] = (180/$PI)*acos (( $x[1]**2 + $x[2]**2- $x[0]**2)/(2*$x[1]*$x[2]));
$X[1] = (180/$PI)*acos (( $x[0]**2 + $x[2]**2- $x[1]**2)/(2*$x[0]*$x[2]));

$X[2] = 180 - $X[0] - $X[1] ;

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "";
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] =" = ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = " = ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = " = ". sprintf("%G",$x[2]);
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($LL[0] => $X[0],$LL[1] => $X[1], $LL[2] => $X[2] );

}

if ($case == 7){ ###sss obtuse angle - scientific notation

$x[0] = pop @list;
$x[1] = pop @list;

#forcing longest side longer than would-be hypotenuse vvvvvvvvvvvvvvvvv
$shortest = int (1.2 * sqrt ($x[0] **2 + $x[1]**2) +1);
$longest = $x[0] + $x[1] -2;
$x[2] = random ($shortest, $longest,1);
#forcing longest side longer than would-be hypotenuse ^^^^^^^^^^^^^^^^^^


#use cosine law to find angles
$X[0] = (180/$PI)*acos (( $x[1]**2 + $x[2]**2- $x[0]**2)/(2*$x[1]*$x[2]));
$X[1] = (180/$PI)*acos (( $x[0]**2 + $x[2]**2- $x[1]**2)/(2*$x[0]*$x[2]));

$X[2] = 180 - $X[0] - $X[1] ;
for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}


$A = $X[$n3k[0]];
$Given[0] = "";
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] =" = ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = " = ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = " = ". sprintf("%G",$x[2]);
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];


$TableOverRide = 0;
%QA = ($LL[0] => $X[0],$LL[1] => $X[1], $LL[2] => $X[2] );


##Constructing the data table vvvvvvvvvvvvvvvvvvvvvvvvvvvvv

}
if ($case == 8){ ###sas acute angle#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

$x[0] = pop @list;
$x[1] = pop @list;
$X[2] = pop @AcuteList;

$x[2] = sqrt ($x[0]**2 + $x[1]**2 - 2 * $x[0] * $x[1] * cos($PI / 180 * $X[2]));
#use cosine law to find angles
$X[0] = (180/$PI)*acos (( $x[1]**2 + $x[2]**2 - $x[0]**2)/(2*$x[1]*$x[2]));
$X[1] = (180/$PI)*acos (( $x[0]**2 + $x[2]**2 - $x[1]**2)/(2*$x[0]*$x[2]));
for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "";
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "=". $X[2].$deg;
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];


$TableOverRide = 0;
%QA = ($LL[0] => $X[0],$LL[1] => $X[2], $ll[2] => $x[2]);

} #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

if ($case == 9){ ###sas acute angle#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

$x[0] = pop @listdd;
$lower = pop @listsd;
$X[2] = pop @SmallAcuteList;

$x[1] = random( $lower, round (sqrt ($x[0]**2 - ($x[0] * $X[2]*$PI / 180)**2))-2) ;

$x[2] = sqrt ($x[0]**2 + $x[1]**2 - 2 * $x[0] * $x[1] * cos($PI / 180 * $X[2]));
#use cosine law to find angles
$X[0] = (180/$PI)*acos (( $x[1]**2 + $x[2]**2 - $x[0]**2)/(2*$x[1]*$x[2]));
$X[1] = (180/$PI)*acos (( $x[0]**2 + $x[2]**2 - $x[1]**2)/(2*$x[0]*$x[2]));
for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "";
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "=". $X[2].$deg;
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];
$TableOverRide = 0;
%QA = ($LL[0] => $X[0],$LL[1] => $X[1], $ll[2] => $x[2] );
}

if ($case == 10){ ###sas obtuse ###vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

$x[0] = pop @list;
$x[1] = pop @list;
$X[2] = pop @ObtuseList;

$x[2] = sqrt ($x[0]**2 + $x[1]**2 - 2 * $x[0] * $x[1] * cos($PI / 180 * $X[2]));
#use cosine law to find angles
$X[0] = (180/$PI)*acos (( $x[1]**2 + $x[2]**2 - $x[0]**2)/(2*$x[1]*$x[2]));
$X[1] = (180/$PI)*acos (( $x[0]**2 + $x[2]**2 - $x[1]**2)/(2*$x[0]*$x[2]));
for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "";
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "= ". $X[2].$deg;
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($LL[0] => $X[0],$LL[1] => $X[1], $ll[2] => $x[2] );
} # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


if ($case == 11){ ###ass acute

$x[1] = pop @list;
$X[0] = pop @SmallAcuteList;

# for the other given side vvvvvvvvvvv
$minLength = int( 1.1 *$x[1]* sin ($PI / 180 * $X[0]) + 1);
$maxLength = int(0.7 * $x[1]);
$x[0] = random ($minLength, $maxLength);
#for the other given side ^^^^^^^^^^^^

$X[1] = 180 / $PI * asin(sin ($PI / 180 * $X[0]) / $x[0] * $x[1]);
$X[2] = 180 - $X[0] - $X[1];
$x[2] = sqrt($x[0]**2 + $x[1]**2 - 2 * $x[0]*$x[1] * cos($PI / 180 * $X[2]));

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}


$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "(acute)";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($LL[1] => $X[1],$LL[2] => $X[2], $ll[2] => $x[2] );
}

if ($case == 12){ ###ass obtuse

$x[1] = pop @list;
$X[0] = pop @SmallAcuteList;

# for the other given side vvvvvvvvvvv
$minLength = int( 1.1 *$x[1]* sin ($PI / 180 * $X[0]) + 1);
$maxLength = int(0.7 * $x[1]);
$x[0] = random ($minLength, $maxLength);
#for the other given side ^^^^^^^^^^^^

$X[1] = 180 - (180 / $PI) * asin(sin ($PI / 180 * $X[0]) / $x[0] * $x[1]);
$X[2] = 180 - $X[0] - $X[1];
$x[2] = sqrt($x[0]**2 + $x[1]**2 - 2 * $x[0]*$x[1] * cos($PI / 180 * $X[2]));

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "(obtuse)";
$C = $X[$n3k[2]];
$Given[2] = "";
$a = $x[$n3k[0]];
$given[0] = "= ". sprintf("%G",$x[0]);
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];

$TableOverRide = 0;
%QA = ($LL[1] => $X[1],$LL[2] => $X[2], $ll[2] => $x[2] );

}

if ($case == 13){ ###asa

# given vvvvvvvvvvvvvvv
$x[1] = pop @list;
$X[0] = pop @SmallAcuteList;

$X[2] = random(30,160 - $X[0],5);
# given ^^^^^^^^^^^^^^^^^^^^^^

$X[1] = 180 - $X[0] - $X[2] ;
$x[2] = sin ($PI / 180 * $X[2]) * $x[1] / sin ($PI / 180 * $X[1]);
$x[0] = sin ($PI / 180 * $X[0]) * $x[1] / sin ($PI / 180 * $X[1]);

for ($i = 0; $i <3; $i++) {$x[$i] *= $fact}

$A = $X[$n3k[0]];
$Given[0] = "= ". $X[0].$deg;
$B = $X[$n3k[1]];
$Given[1] = "";
$C = $X[$n3k[2]];
$Given[2] = "=".$X[2].$deg;
$a = $x[$n3k[0]];
$given[0] = "";
$b = $x[$n3k[1]];
$given[1] = "= ". sprintf("%G",$x[1]);
$c = $x[$n3k[2]];
$given[2] = "";
$Alabel = $AL.$Given[$n3k[0]];
$Blabel = $BL.$Given[$n3k[1]];
$Clabel = $CL.$Given[$n3k[2]];
$alabel = $aL.$given[$n3k[0]];
$blabel = $bL.$given[$n3k[1]];
$clabel = $cL.$given[$n3k[2]];


$TableOverRide = 0;
%QA = ($LL[1] => $X[1],$ll[0] => $x[0], $ll[2] => $x[2] );

}

if ($TableOverRide == 0){
@sortedKey = ();
foreach $key (keys %QA)
{
push @sortedKey , $key;
}
@sortedKey = lex_sort(@sortedKey);

@xxxPrint = @sortedKey;

$table = "";
$table = BeginTable(spacing => 3);

$cycle = 0 ; # named answer is not case sensitive - a eq A
foreach $key (@sortedKey){
$cycle = $cycle + 1;
if ($key eq uc($key)){$QLabel = "\( \angle \)". $key . " = "}
else {$QLabel = "side ".$key . " = "}
$table .= AlignedRow([$QLabel ,NAMED_ANS_RULE($trial.$cycle,10)]);
$answer = $QA{$key};
push @namedCmp ,$trial.$cycle=>num_cmp( $answer, tolType => "absolute", tolerance=>0.03 * $answer ) ;
}


$table .= EndTable();
@sortedKey = ( );
%QA = ();
}

$AX = $b * cos ($PI * $C / 180);
$AY = $b * sin ($PI * $C / 180);


$dimX = max (max ($a, $a - $AX), $AX);
$dimY = $AY ;
#$size = 1.5 * max ($dimX, $dimY);
#$sizeX = 1.5 * $dimX; #world units
$sizeX = $dimX + 0.5 * max($dimX,$dimY ); #plus borders in world units
#$sizeY = 1.5 * $dimY; #world units
$sizeY = $dimY + 0.5 * max($dimX,$dimY ); #plus borders in world units
$marginX = 0.5 * ($sizeX - $dimX); #world units
$marginY = 0.5 * ($sizeY - $AY); #world units

$xmin = min(0,$AX ) - $marginX; #world units
$xmax = $sizeX + $xmin; #world units
$ymin = -1 * $marginY; #world units
$ymax = $sizeY - $marginY; #world units


if ($sizeX >= $sizeY ){
$xPixels = 600;
$yPixels = $xPixels *($ymax - $ymin)/($xmax - $xmin);
}

if ($sizeX < $sizeY ){
$yPixels = 600;
$xPixels = $yPixels *($xmax - $xmin)/($ymax - $ymin);
}

$pic = init_graph($xmin,$ymin,$xmax,$ymax,'pixels'=>[$xPixels,$yPixels]);


$lab=new Label(0,0,$Clabel,'black','top','center');
$pic->lb($lab);

$lab=new Label($AX,$AY,$Alabel,'black','bottom','left');
$pic->lb($lab);

$lab=new Label($a,0,$Blabel);
$pic->lb($lab);

$lab=new Label($a/2,0,$alabel,'black','center','top');
$pic->lb($lab);

$lab=new Label($AX/2- abs(0.03 *$AX),$AY/2 + 0.03*$AX,$blabel,'black','right','middle');
$pic->lb($lab);

$lab=new Label(($AX + $a) / 2 + abs(0.03 *$a), $AY /2 +0.03*($a - $AX) ,$clabel, 'black','left','middle');
$pic->lb($lab);

# $pic->new_color("lightblue", 240,240,240);
$pic->new_color("lightblue", random(200,240),random(200,240),random(200,240));
$pic->moveTo(0,0);
$pic->lineTo($AX,$AY,1);
$pic->lineTo($a,0,1);
$pic->lineTo(0,0,1);
$pic->fillRegion([($a / 2 + $AX)/2,$AY/2,'lightblue']);

BEGIN_TEXT


$HR $HR Number $trial $BR

\{ image(insertGraph($pic), width=>$xPixels, height=>$yPixels) \}


$PAR
$table $BR

END_TEXT

NAMED_ANS(@namedCmp);

}
TEXT($END_ONE_COLUMN);
ENDDOCUMENT();
I think something like this happened to me; I ended up reassigning the problem so that the images get refreshed.

Perhaps it matters if you are editing via an assigned homework problem as opposed to editing via the library browser.

Cached images for assigned problems may need to be "flushed".

hp


Arnie and Jason,

When I take out the refresh cache line in the problem's code and change the graph, it will not update the image--the file for the graph in the var/www/wwtmp/gif folder is not updated. I tried it in IE and Chrome. I edited the file from IE and looked at the problem in Chrome--it was the first time I'd logged into the course using Chrome.

--rac

Hi Robin,

This is strange.  Looking at the code, setting $refreshCachedImages = 1; in the problem code or just editing the problem (which changes its creation date) should both force the images to be recreated.  It strange that setting $refreshCachedImages = 1; in the problem code worked but just editing the problem didn't.

Could it be possible that this is a caching issue?  If you have time, could you try this by viewing the problem in one browser, editing the problem and then viewing it an another (or some other procedure to be sure that your browser it not caching the old image).

Arnie
Hi Robin,

This may be a bug.  Does your problem use insertGraph?  That's defined in PGcore.pm and contains the code 

if( not -e $filePath # does it exist?
 or ((stat "$templateDirectory"."$main::envir{fileName}")[9] > (stat $filePath)[9]) # source has changed
 or $graph->imageName =~ /Undefined_Set/ # problems from SetMaker and its ilk should always be redone
 or $refreshCachedImages

which "should" refresh the image in your case.

Arnie