Matching Problem with Graphs

Matching problem with graphs

Complete Code

Download file: MatchingGraphs.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros(
    'PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'parserPopUp.pl',
    'PGcourse.pl'
);

Preamble

The dynamic graph is generated with PGtikz.pl, so that macro is loaded. Matching is done with pop ups, so parserPopUp.pl is loaded. Finally, a LayoutTable is used from niceTables.pl which is loaded by the PGML.pl macro.

@all_plots = (
    {
        f      => 'x^2',
        form   => '\x*\x',
        domain => '-3:3',
        alt    =>
            'A graph of a curve with a minimum at the origin and opening '
            . 'upward.'
    },
    {
        f      => 'e^x',
        form   => 'exp(\x)',
        domain => '-6:3',
        alt    => 'A graph of a curve starting near the negative x axis and '
            . 'rising steeply toward the first quadrant.'
    },
    {
        f      => 'x^3',
        form   => '\x*\x*\x',
        domain => '-2:2',
        alt    => 'A graph of a curve from the third quadrant (where is it '
            . 'concave down) to the first quadrant (where it is concave up).'
    },
    {
        f      => 'ln(x)',
        form   => 'ln(\x)',
        domain => '0.1:6',
        alt    => 'A graph of a curve that approaches the negative y-axis '
            . 'and rises to the first quadrant and everywhere it is concave'
            . 'down.'
    },
    {
        f      => '3x+2',
        form   => '3*\x+2',
        domain => '-6:6',
        alt    =>
            'The graph of a line from the 3rd quadrant to the first quadrant'
    },
    {
        f      => 'sin(x)',
        form   => 'sin(\x r)',
        domain => '-6:6',
        alt    => 'A graph of a curve that oscillates and passes through the '
            . 'origin'
    },
);

@plots = random_subset(4, @all_plots);

for (@plots) {
    my $graph = createTikZImage();
    $graph->tikzLibraries('arrows.meta');
    $graph->BEGIN_TIKZ
    \tikzset{>={Stealth[scale = 1.5]}}
    \filldraw[
        draw = LightBlue,
        fill = white,
        rounded corners = 10pt,
        thick,
        use as bounding box
    ] (-6, -6) rectangle (6, 6);
    \draw[->, thick] (-6, 0) -- (6, 0)
        node[above left, outer sep = 3pt] {\(x\)};
    \foreach \x in {-5, ..., -1, 1, 2, ..., 5}
        \draw (\x, 5pt) -- (\x, -5pt) node[below] {\(\x\)};
    \draw[->, thick] (0, -6) -- (0, 6)
        node[below right, outer sep = 3pt] {\(y\)};
    \foreach \y in {-5, ..., -1, 1, 2, ..., 5}
        \draw (5pt, \y) -- (-5pt, \y) node[left] {\(\y\)};
    \draw[blue, ultra thick] plot[domain = $_->{domain}, smooth]
        (\x, {$_->{form}});
END_TIKZ
    $_->{graph} = $graph;
}

# sorted list of possible answers
$list = [ lex_sort(map { $_->{f} } @all_plots) ];

@dropdowns = map { DropDown($list, $_->{f}) } @plots;

$showPartialCorrectAnswers = 0;

Setup

The array @all_plots contains the display form f of the function, the functional form of the function needed in TikZ format, the domain of the function, and the alteratnive text (alt).

The graphs of all plots are then created by calling commands from PGtikz.pl. See PGtikz.pl for more information. Note that alternate text for accessibility should always be provided.

The dropdowns are created in the @dropdown array.

BEGIN_PGML
Match the graph with the formula for the graph
(Click on image for a larger view.)

[#
    [.
        [![$plots[0]{alt}]!]{$plots[0]{graph}}{300}{
            image_options => { tex_size => 400 }
        }
    .]
    [.
        [![$plots[1]{alt}]!]{$plots[1]{graph}}{300}{
            image_options => { tex_size => 400 }
        }
    .]*

    [.[_]{$dropdowns[0]}.] [.[_]{$dropdowns[1]}.]*

    [.
        [![$plots[2]{alt}]!]{$plots[2]{graph}}{300}{
            image_options => { tex_size => 400 }
        }
    .]
    [.
        [![$plots[3]{alt}]!]{$plots[3]{graph}}{300}{
            image_options => { tex_size => 400 }
        }
    .]*

    [.[_]{$dropdowns[2]}.] [.[_]{$dropdowns[3]}.]*
#]*{ align => 'cc' }
END_PGML

Statement

A LayoutTable from niceTables.pl is used via its PGML syntax to organize the graphs and pop ups nicely.

Although this matching problem creates graphs dynamically, static images could also be used by changing the image sources in the [!alt text!]{image source} calls to the image file names.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.