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',
    'niceTables.pl', 'PGcourse.pl'
);

Preamble

The dynamic graph is generated with PGtikz.pl, so this is needed. The matching is done with popups, so parserPopUp.pl is need and lastly a LayoutTable is used from niceTables.pl.

@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 osciallates and passes through the '
            . 'origin'
    },
);

for $i (0 .. $#all_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
    ] (-7,-7) rectangle (7,7);
    \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=$all_plots[$i]->{domain},smooth] (\x,{$all_plots[$i]->{form}});
END_TIKZ
    $all_plots[$i]->{graph} = $graph;
}

@plots = random_subset(4, @all_plots);

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

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

$tab = LayoutTable(
    [
        [
            map {
                image(
                    $plots[$_]->{graph},
                    width           => 300,
                    tex_size        => 400,
                    extra_html_tags => "alt = '$plots[$_]->{alt}'"
                )
            } (0 .. 1)
        ],
        [ map { $dropdowns[$_]->menu } (0 .. 1) ],
        [
            map {
                image(
                    $plots[$_]->{graph},
                    width           => 300,
                    tex_size        => 400,
                    extra_html_tags => "alt = '$plots[$_]->{alt}'"
                )
            } (2 .. 3)
        ],
        [ map { $dropdowns[$_]->menu } (2 .. 3) ]

    ],
    align => 'cc'
);

$showPartialCorrectAnswers = 0;

Setup

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

The graphs of all plots and then created by calling commands from PGtikz.pl. See Dynamic Graph for a simpler example using tikz. Note that alternate text is provided to the image command and for accessibility should always be considered and this should be provided.

The dropdowns are created in the @dropdown array which pulls all options.

The LayoutTable is used to make an accessible table that is nicely laid out.

Although this matching problem creates graphs dynamically, these can use static images by changing the call to image to just pass in the image names.

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

[$tab]*
END_PGML

Statement

This is the problem statement in PGML.
ANS($dropdowns[$_]->cmp) for (0 .. 3);

Answer

Because the dropdowns are created in the older fashion, we use the ANS form to check the answer

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.