|
| 1 | +## DESCRIPTION |
| 2 | +## Matching problem with graphs |
| 3 | +## ENDDESCRIPTION |
| 4 | + |
| 5 | +## DBsubject(WeBWorK) |
| 6 | +## DBchapter(WeBWorK tutorial) |
| 7 | +## DBsection(PGML tutorial 2015) |
| 8 | +## Date(07/15/2023) |
| 9 | +## Institution(Fitchburg State University) |
| 10 | +## Author(Peter Staab) |
| 11 | +## MO(1) |
| 12 | +## KEYWORDS('matching', 'dynamic graph') |
| 13 | + |
| 14 | +#:% name = Matching Problem with Graphs |
| 15 | +#:% type = Sample |
| 16 | +#:% subject = [algebra, precalculus] |
| 17 | +#:% categories = [graph] |
| 18 | + |
| 19 | +#:% section = preamble |
| 20 | +#: The dynamic graph is generated with `PGtikz.pl`, so this is needed. |
| 21 | +#: The matching is done with popups, so `parserPopUp.pl` is need and lastly |
| 22 | +#: a `LayoutTable` is used from `niceTables.pl`. |
| 23 | +DOCUMENT(); |
| 24 | + |
| 25 | +loadMacros( |
| 26 | + 'PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'parserPopUp.pl', |
| 27 | + 'niceTables.pl', 'PGcourse.pl' |
| 28 | +); |
| 29 | + |
| 30 | +#:% section = setup |
| 31 | +#: The array `@all_plots` contains the display form (f) of the function, |
| 32 | +#: the functional form (form) of the function needed in tikz format, |
| 33 | +#: the domain of the function and the alterative text. |
| 34 | +#: |
| 35 | +#: The graphs of all plots and then created by calling commands from `PGtikz.pl`. |
| 36 | +#: See PROBLINK('DynamicGraph.pg') for a simpler example using tikz. Note |
| 37 | +#: that alternate text is provided to the `image` command and for accessibility |
| 38 | +#: should always be considered and this should be provided. |
| 39 | +#: |
| 40 | +#: The dropdowns are created in the `@dropdown` array which pulls all |
| 41 | +#: options. |
| 42 | +#: |
| 43 | +#: The `LayoutTable` is used to make an accessible table that is nicely |
| 44 | +#: laid out. |
| 45 | +#: |
| 46 | +#: Although this matching problem creates graphs dynamically, these can use |
| 47 | +#: static images by changing the call to `image` to just pass in the |
| 48 | +#: image names. |
| 49 | +@all_plots = ( |
| 50 | + { |
| 51 | + f => 'x^2', |
| 52 | + form => '\x*\x', |
| 53 | + domain => '-3:3', |
| 54 | + alt => |
| 55 | + 'A graph of a curve with a minimum at the origin and opening ' |
| 56 | + . 'upward.' |
| 57 | + }, |
| 58 | + { |
| 59 | + f => 'e^x', |
| 60 | + form => 'exp(\x)', |
| 61 | + domain => '-6:3', |
| 62 | + alt => 'A graph of a curve starting near the negative x axis and ' |
| 63 | + . 'rising steeply toward the first quadrant.' |
| 64 | + }, |
| 65 | + { |
| 66 | + f => 'x^3', |
| 67 | + form => '\x*\x*\x', |
| 68 | + domain => '-2:2', |
| 69 | + alt => 'A graph of a curve from the third quadrant (where is it ' |
| 70 | + . 'concave down) to the first quadrant (where it is concave up).' |
| 71 | + }, |
| 72 | + { |
| 73 | + f => 'ln(x)', |
| 74 | + form => 'ln(\x)', |
| 75 | + domain => '0.1:6', |
| 76 | + alt => 'A graph of a curve that approaches the negative y-axis ' |
| 77 | + . 'and rises to the first quadrant and everywhere it is concave' |
| 78 | + . 'down.' |
| 79 | + }, |
| 80 | + { |
| 81 | + f => '3x+2', |
| 82 | + form => '3*\x+2', |
| 83 | + domain => '-6:6', |
| 84 | + alt => |
| 85 | + 'The graph of a line from the 3rd quadrant to the first quadrant' |
| 86 | + }, |
| 87 | + { |
| 88 | + f => 'sin(x)', |
| 89 | + form => 'sin(\x r)', |
| 90 | + domain => '-6:6', |
| 91 | + alt => 'A graph of a curve that osciallates and passes through the ' |
| 92 | + . 'origin' |
| 93 | + }, |
| 94 | +); |
| 95 | + |
| 96 | +for $i (0 .. $#all_plots) { |
| 97 | + my $graph = createTikZImage(); |
| 98 | + $graph->tikzLibraries('arrows.meta'); |
| 99 | + $graph->BEGIN_TIKZ |
| 100 | + \tikzset{>={Stealth[scale=1.5]}} |
| 101 | + \filldraw[ |
| 102 | + draw=LightBlue, |
| 103 | + fill=white, |
| 104 | + rounded corners=10pt, |
| 105 | + thick,use as bounding box |
| 106 | + ] (-7,-7) rectangle (7,7); |
| 107 | + \draw[->,thick] (-6,0) -- (6,0) node[above left,outer sep=3pt] {\(x\)}; |
| 108 | + \foreach \x in {-5,...,-1,1,2,...,5} |
| 109 | + \draw(\x,5pt) -- (\x,-5pt) node [below] {\(\x\)}; |
| 110 | + \draw[->,thick] (0,-6) -- (0,6) node[below right,outer sep=3pt] {\(y\)}; |
| 111 | + \foreach \y in {-5,...,-1,1,2,...,5} |
| 112 | + \draw (5pt,\y) -- (-5pt,\y) node[left] {\(\y\)}; |
| 113 | + \draw[blue,ultra thick] plot[domain=$all_plots[$i]->{domain},smooth] (\x,{$all_plots[$i]->{form}}); |
| 114 | +END_TIKZ |
| 115 | + $all_plots[$i]->{graph} = $graph; |
| 116 | +} |
| 117 | + |
| 118 | +@plots = random_subset(4, @all_plots); |
| 119 | + |
| 120 | +# sorted list of possible answers |
| 121 | +$list = [ lex_sort(map {"$_->{f}"} @all_plots) ]; |
| 122 | + |
| 123 | +@dropdowns = map { DropDown($list, "$_->{f}") } @plots; |
| 124 | + |
| 125 | +$tab = LayoutTable( |
| 126 | + [ |
| 127 | + [ |
| 128 | + map { |
| 129 | + image( |
| 130 | + $plots[$_]->{graph}, |
| 131 | + width => 300, |
| 132 | + tex_size => 400, |
| 133 | + extra_html_tags => "alt = '$plots[$_]->{alt}'" |
| 134 | + ) |
| 135 | + } (0 .. 1) |
| 136 | + ], |
| 137 | + [ map { $dropdowns[$_]->menu } (0 .. 1) ], |
| 138 | + [ |
| 139 | + map { |
| 140 | + image( |
| 141 | + $plots[$_]->{graph}, |
| 142 | + width => 300, |
| 143 | + tex_size => 400, |
| 144 | + extra_html_tags => "alt = '$plots[$_]->{alt}'" |
| 145 | + ) |
| 146 | + } (2 .. 3) |
| 147 | + ], |
| 148 | + [ map { $dropdowns[$_]->menu } (2 .. 3) ] |
| 149 | + |
| 150 | + ], |
| 151 | + align => 'cc' |
| 152 | +); |
| 153 | + |
| 154 | +$showPartialCorrectAnswers = 0; |
| 155 | + |
| 156 | +#:% section = statement |
| 157 | +BEGIN_PGML |
| 158 | +Match the graph with the formula for the graph (Click on image for a larger view.) |
| 159 | + |
| 160 | +[$tab]* |
| 161 | +END_PGML |
| 162 | + |
| 163 | +#:% section = answer |
| 164 | +#: Because the dropdowns are created in the older fashion, we use the `ANS` form |
| 165 | +#: to check the answer |
| 166 | +ANS($dropdowns[$_]->cmp) for (0 .. 3); |
| 167 | + |
| 168 | +#:% section = solution |
| 169 | +BEGIN_PGML_SOLUTION |
| 170 | +Solution explanation goes here. |
| 171 | +END_PGML_SOLUTION |
| 172 | + |
| 173 | +ENDDOCUMENT(); |
0 commit comments