Dynamic Graph

Dynamically generated graph of a function

Complete Code

Download file: DynamicGraph.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

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

Preamble

The dynamic graph is generated with PGtikz.pl, so this is needed.

$a = random(2, 3, 1);    # negative of left x-intercept
$b = random(2, 4, 2);    # right x-intercept
$c = random(3, 6, 1);    # y-intercept

$k = -$c / ($a * $b);

$A = $k;
$B = $k * ($a - $b);
$C = -$k * $a * $b;

$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,7) rectangle (6,-1);
\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,-1) -- (0,7) node[below right,outer sep=3pt] {\(y\)};
\foreach \y in {1,...,6}
    \draw (5pt,\y) -- (-5pt,\y) node[left] {\(\y\)};
\draw[blue,ultra thick] plot[domain=-6:6,smooth] (\x,{$A*\x*\x+$B*\x+$C});
END_TIKZ

Setup

The code between $graph->BEGIN_TIKZ and END_TIKZ are tikz commands. Information on tikz can be found at the homepage for tikz and details on using tikz within pg problems can be found in PGtikz.pl.

BEGIN_PGML
Use the graph to find the missing values. There may be more than one correct
answer, in which case you should enter your answers as a comma separated list.
If there are no correct answers, enter NONE.

[@ image($graph, width => 400, tex_size => 600) @]*

a) [`f(0) =`] [__]{$c}

b) [`f\Big(`] [__]{List(-$a, $b)} [`\Big) = 0`]
END_PGML

Statement

Note that the tikz graph in $graph to be shown is placed in the image function and since this is a function, it must go in a [@ ... @]* block.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.