Forum archive 2000-2006

Michael Gage - Static graphics example

Michael Gage - Static graphics example

by Arnold Pizer -
Number of replies: 0
inactiveTopicStatic graphics example topic started 5/9/2000; 4:03:48 PM
last post 7/15/2001; 9:43:54 AM
userMichael Gage - Static graphics example  blueArrow
5/9/2000; 4:03:48 PM (reads: 3912, responses: 1)

The static graphics example

To obtain this problem



(1 pt) rochesterLibrary/setMAAtutorial/staticgraphicsexample/staticgraphicsexample.pg

Static graphics Example

This is a graph of the function F(x): ( Click on image for a larger view )

gage-54321-setMAAtutorial-prob1-1.png

Enter the letter of the graph below which corresponds to the transformation of the function.

 1. F(x^2)
 2. -F(-x)
 3. 5F(x)
 4. F(3x)

gage-54321-setMAAtutorial-prob1-1-34859.png gage-54321-setMAAtutorial-prob1-1-96355.png gage-54321-setMAAtutorial-prob1-1-42639.png gage-54321-setMAAtutorial-prob1-1-89540.png
ABCD

 

 


WARNINGS
µ¦å{h­
Enter this code:
DOCUMENT();
loadMacros("PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);
TEXT($BEGIN_ONE_COLUMN);
TEXT(beginproblem(), $BR,$BBOLD, "Static graphics Example", $EBOLD, $BR,$BR);

$showPartialCorrectAnswers = 0;
# Define which of the three sets of pictures to use

# The pictures are labeled 1.png, 2.png and 3.png and
# stored in the same directory as staticgraphicsexample.png
# These are the corresponding transformed pictures.
# Be careful with the labeling, since the URL's could give the
# correct answers away.
# (In this example the middle integer tells you
# the correct position.)

$pictID[1] = [
"1-31126.png", # "\( F(x+3)\)",
"1-76239.png", # "\(F(x-3) \)" ,
"1-96355.png", # "\( -F(-x)\)",
"1-24438.png", # "\( F(-x) \)",
"1-89540.png", # "\( 5F(x) \)",
"1-42639.png", # "\( F(3x) \)" ,
"1-91734.png", # "\( F(x/3) \)",
"1-34859.png", # "\( F(x^2) \)",
];
$pictID[2] = [
"2-70190.png", # ditto
"2-49261.png",
"2-62384.png",
"2-54427.png",
"2-64591.png",
"2-42653.png",
"2-81779.png",
"2-92879.png",
];
$pictID[3] = [
"3-14197.png",
"3-89262.png",
"3-99389.png",
"3-68458.png",
"3-14538.png",
"3-37616.png",
"3-46739.png",
"3-52898.png",
];
$ml = new_match_list();

$pictSet=random(1,3,1); # Choose one of the three picture sets
$pictSet=1;
$pictSetname = $pictSet.".png";
$ml->qa (
"\( F(x+3)\) ",
image($pictID[$pictSet][0],tex_size=>200),
"\(F(x-3) \)" ,
image($pictID[$pictSet][1],tex_size=>200),
"\( -F(-x)\) ",
image($pictID[$pictSet][2],tex_size=>200),
"\( F(-x) \)",
image($pictID[$pictSet][3],tex_size=>200),
"\( 5F(x) \)",
image($pictID[$pictSet][4],tex_size=>200),
"\( F(3x) \)" ,
image($pictID[$pictSet][5],tex_size=>200),
"\( F(x/3) \)",
image($pictID[$pictSet][6],tex_size=>200),
"\( F(x^2) \)",
image($pictID[$pictSet][7],tex_size=>200),
);

$ml->choose(4);
sub format_graphs {
my $self = shift;
my @in = @_;
my $out = "";
while(@in) {
$out .= shift(@in). "#" ;
}
$out; # The output has to be a string in order to conform to the
# specs for the match list object, but I've put some
# markers in (#) so that
# I can break the string up into a list for use
# as an input into row.
}

# We need to change the output, since the normal
# output routine will put the pictures one above another.
$ml->rf_print_a(~~&format_graphs);

BEGIN_TEXT
This is a graph of the function \( F(x) \):
($BBOLD Click on image for a larger view $EBOLD)
$PAR
\{ image($pictSetname, tex_size => 200) \}
$PAR
Enter the letter of the graph below which corresponds to the transformation
of the function.
\{ $ml -> print_q \}
END_TEXT

# Place the output into a table
TEXT(
begintable(4),
row( split("#",$ml->print_a() ) ),
row('A', 'B', 'C', 'D' ),
endtable(),
);

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

TEXT($END_ONE_COLUMN);
ENDDOCUMENT();


Comments:

  1. Set $showPartialCorrectAnswers to 0 so that students can't tell which matches are wrong.
  2. pictID is perl's version of a multi-dimensional array. Strictly speaking @pictID is a list of references (pointers) to arrays, each of which has a number of entries. $pictID[1] is a pointer to an array, and $pictID[1][3] chooses an item in that array (the 4th item since we are counting from 0).
  3. The way the code is set up the first entry, $pictID[0] is blank, $pictIC[1] points to an array with entries numbered from 0 to 7, and so forth.
  4. GIF files containing the appropriate graphs have already been created and placed in the directory containing the static graphics PG template. The numbering convention is meant to try to keep from giving the answer away, while still allowing the instructor to do some error checking. Note the center numbers in each label.
  5. The variable $pictSet, chosen as a number between 1 and 3, chooses a picture set. This set is placed in the matching list object $ml, along with the matching answers. David Eck's program xFunctions (for the Macintosh, and now available in java) was used to draw the graphs and the transformations of the graphs.
  6. Next we want to print the graphs in a table. The standard print function for matching list objects prints the answers in a vertically spaced, ordered list which would take up too much space, so we write a new print function (or subroutine) for the matching list object called format_graphs. This print function outputs a string of IMG tags for the chosen graphs, separated by the # symbol. (The specs for the matching list require that the output of the print function be a string and not an array.)
  7. $ml->rf_print_a(~~&format_graphs); installs the new print function in the matching list object $ml. (The convenction rf_... means that we require a reference to a function. ) &format_graphs is a function, and ~~&format_graphs is a value which is a reference to that function. Recall that in PG we use ~~ rather than \ as in ordinary perl, because backslashes are reserved for TeX like commands for formatting mathematics.
  8. Next comes the text of the problem, including the graph of the original function F { image($pictSet) } and the questions involving the transformation of F { $ml -> print_q } .
  9. Next we print the table, with just one row of pictures. The command split("\#",$ml->print_a() ) splits the string of answers at the # symbol into a list, which is what the macro row requires.
  10. The answers are letters and are placed in the ANS function by $ml->ra_correct_ans(). The ra_... convention, means that the ouput is a reference to an array.

 

<| Post or View Comments |>


userThomas R. Shemanske - Re: Static graphics example  blueArrow
7/15/2001; 9:43:54 AM (reads: 2331, responses: 0)
Using matched lists to accomplish the static graph problem works well in html mode, but not in (hardcopy) TeX mode (your tutorial page)

The problem is that in html, the images are rendered as thumbnails, but when LaTeXed, they are rendered full size, making the hardcopy unusable. This was not the case in the old style static graphics example (set0) in which you used imageRow and had explicit instructions for rendering TeX. Given the inherent complexity of the $ml structure, this seems somewhat harder here.

Any "easy" fixes?

Tom Shemanske

<| Post or View Comments |>