Difference between revisions of "MatchingStaticGraphs"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 123: Line 123:
 
</tr>
 
</tr>
 
</table>
 
</table>
  +
  +
  +
  +
  +
  +
  +
  +
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
  +
<em>This code shows how to create a matching problem for graphs and other graphs.
  +
Students input their answers using drop-down select lists (popup lists).
  +
</em>
  +
</p>
  +
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
  +
loadMacros(
  +
"PG.pl",
  +
"PGbasicmacros.pl",
  +
"PGchoicemacros.pl",
  +
"PGanswermacros.pl",
  +
);
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
Initialization: We need to include the <code>PGchoicemacros.pl</code> macro file.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
@surfaces = (
  +
"Surface02.png",
  +
"Surface04.png",
  +
"Surface09.png",
  +
"Surface10.png",
  +
);
  +
  +
@contours = (
  +
"Contour02.png",
  +
"Contour04.png",
  +
"Contour09.png",
  +
"Contour10.png",
  +
);
  +
  +
$n = scalar(@questions);
  +
$k = $n; # $k can be less than $n
  +
@subset = NchooseK($n,$k);
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
Set-up: This is probably the only section you need to modify.
  +
Create an array of surfaces and a corresponding
  +
array of contour plots. Set the number of questions displayed, $k,
  +
manually if you like. You probably don't want more than five
  +
graphs to be displayed. Image files must be GIF or PNG and
  +
be located in the same directory as the pg file.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
@subset_of_surfaces = @surfaces[@subset];
  +
@subset_of_contours = @contours[@subset];
  +
@permutation = NchooseK($k,$k);
  +
@shuffled_subset_of_contours = @subset_of_contours[@permutation];
  +
@numbercaptions = (1..$k);
  +
@alphacaptions = @ALPHABET[0..$k-1];
  +
  +
TEXT(beginproblem());
  +
  +
BEGIN_TEXT
  +
$BEGIN_ONE_COLUMN
  +
Match each graph with its contour plot. If you click on a graph,
  +
a larger graph will appear in a new window. Green contours represent
  +
lower elevations, and red contours represent higher elevations.
  +
$BR$BR
  +
END_TEXT
  +
  +
for $j (1..$k) {
  +
BEGIN_TEXT
  +
$j. \{ pop_up_list(['?', @alphacaptions]) \} $SPACE$SPACE$SPACE$SPACE$SPACE
  +
END_TEXT
  +
}
  +
  +
BEGIN_TEXT
  +
\{imageRow(~~@subset_of_surfaces,~~@numbercaptions)\}
  +
\{imageRow(~~@shuffled_subset_of_contours,~~@alphacaptions)\}
  +
$END_ONE_COLUMN
  +
END_TEXT
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
Main Text: You may modify the instructions if you want.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#eeddff;border:black 1px dashed;">
  +
<pre>
  +
$showPartialCorrectAnswers = 0;
  +
  +
ANS(str_cmp([@ALPHABET[invert(@permutation)]]));
  +
  +
ENDDOCUMENT();
  +
</pre>
  +
<td style="background-color:#eeccff;padding:7px;">
  +
<p>
  +
Answer Evaluation: You should not need to modify this section at all.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
   
 
<p style="text-align:center;">
 
<p style="text-align:center;">

Revision as of 00:41, 25 October 2009

Matching Problems That Have Static Graphic Images

This code shows how to create a matching problem for functions and their graphs. Students input their answers using drop-down select lists (popup lists).

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
);

Initialization: We need to include the PGchoicemacros.pl macro file.

@questions = (
"\( f(x,y) = \displaystyle \frac{1}{x^2 + y^2} \)",
"\( f(x,y) = - y^2 \)",
"\( f(x,y) = x^3 - \sin(y) \)",
"\( f(x,y) = x + 2y + 3 \)",
"\( f(x,y) = - e^{-x^2 - y^2} \)",
);

@images = (
"12-2-9a.gif",
"12-2-9b.gif",
"12-2-9c.gif",
"12-2-9d.gif",
"12-2-9e.gif",
);

$n = scalar(@questions);
$k = $n; # $k can be less than $n
@subset = NchooseK($n,$k);

Set-up: This is probably the only section you need to modify. Create an array of questions (functions) and a corresponding array of images. Set the number of questions displayed, $k, manually if you like. You probably don't want more than five graphs to be displayed. Image files must be GIF or PNG and be located in the same directory as the pg file.

@subset_of_questions = @questions[@subset];
@subset_of_images = @images[@subset];
@permutation = NchooseK($k,$k);
@shuffled_subset_of_images = @subset_of_images[@permutation];
@captions = @ALPHABET[0..$k-1];

TEXT(beginproblem());

BEGIN_TEXT
$BEGIN_ONE_COLUMN
Match each function with its graph.  If you click on a graph, 
a larger graph will appear in a new window.
$BR$BR
END_TEXT

for $j (1..$k) {
BEGIN_TEXT
$j.  
\{ pop_up_list(['?', @captions]) \} $SPACE 
@subset_of_questions[$j-1]
$BR$BR
END_TEXT
}

BEGIN_TEXT
\{imageRow(~~@shuffled_subset_of_images,~~@captions)\}
$END_ONE_COLUMN
END_TEXT

Main Text: You may modify the instructions if you want.

$showPartialCorrectAnswers = 0;

ANS(str_cmp([@ALPHABET[invert(@permutation)]]));

ENDDOCUMENT();

Answer Evaluation: You should not need to modify this section at all.




This code shows how to create a matching problem for graphs and other graphs. Students input their answers using drop-down select lists (popup lists).


PG problem file Explanation
DOCUMENT();

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
);

Initialization: We need to include the PGchoicemacros.pl macro file.

@surfaces = (
"Surface02.png",
"Surface04.png",
"Surface09.png",
"Surface10.png",
);

@contours = (
"Contour02.png",
"Contour04.png",
"Contour09.png",
"Contour10.png",
);

$n = scalar(@questions);
$k = $n; # $k can be less than $n
@subset = NchooseK($n,$k);

Set-up: This is probably the only section you need to modify. Create an array of surfaces and a corresponding array of contour plots. Set the number of questions displayed, $k, manually if you like. You probably don't want more than five graphs to be displayed. Image files must be GIF or PNG and be located in the same directory as the pg file.

@subset_of_surfaces = @surfaces[@subset];
@subset_of_contours = @contours[@subset];
@permutation = NchooseK($k,$k);
@shuffled_subset_of_contours = @subset_of_contours[@permutation];
@numbercaptions = (1..$k);
@alphacaptions = @ALPHABET[0..$k-1];

TEXT(beginproblem());

BEGIN_TEXT
$BEGIN_ONE_COLUMN
Match each graph with its contour plot.  If you click on a graph, 
a larger graph will appear in a new window.  Green contours represent
lower elevations, and red contours represent higher elevations.
$BR$BR
END_TEXT

for $j (1..$k) {
BEGIN_TEXT
$j. \{ pop_up_list(['?', @alphacaptions]) \} $SPACE$SPACE$SPACE$SPACE$SPACE
END_TEXT
}

BEGIN_TEXT
\{imageRow(~~@subset_of_surfaces,~~@numbercaptions)\}
\{imageRow(~~@shuffled_subset_of_contours,~~@alphacaptions)\}
$END_ONE_COLUMN
END_TEXT

Main Text: You may modify the instructions if you want.

$showPartialCorrectAnswers = 0;

ANS(str_cmp([@ALPHABET[invert(@permutation)]]));

ENDDOCUMENT();

Answer Evaluation: You should not need to modify this section at all.


Problem Techniques Index