Dynamically generated graph of a function with shading
Download file: GraphShading.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'PGcourse.pl');
Preamble
The macro PGtikz.pl is used to create the plot.
$a = random(-4, 2);
$b = random( 1, 4);
$g = Compute("$b + sqrt(x - $a)")->reduce;
$area = Compute("3*$b + 14/3");
$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, -2) rectangle (6, 8);
\begin{scope}
\clip[rounded corners = 14pt] (-6, -2) rectangle (6, 8);
\draw[ultra thin] (-6, -2) grid (6, 8);
\end{scope}
\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, -2) -- (0, 8) node[below right, outer sep = 3pt] {\(y\)};
\foreach \y in {-1, 1, 2, ..., 7}
\draw (5pt, \y) -- (-5pt, \y) node[left] {\(\y\)};
\filldraw[draw = blue, fill = blue!50!white, fill opacity = 0.5]
({$a + 1}, 0) -- ({$a + 1}, {$b + 1})
-- plot[domain = {$a + 1}:{$a + 4}, samples = 100] (\x, {$b + sqrt(\x - $a)})
-- ({$a + 4}, 0) -- cycle;
\draw[blue, ultra thick, ->]
plot[domain = {$a}:6, samples = 100] (\x, {$b + sqrt(\x - $a)});
END_TIKZ
$altText =
"The graph of f(x) is shown starting at the point ($a, $b) and increasing "
. "to the right, sharply at first, and less sharply as it continues to the "
. "right. The region from x = "
. ($a + 1)
. " to x = "
. ($a + 4)
. " that is above the x-axis and below the function is shaded.";
Setup
A randomly transformed version of sqrt(x) is created as
the function with a reasonably straightforward answer.
The graph is created with PGtikz.pl,
a robust plotting package. The shading in done with the
\filldraw command with the fill opacity = 0.5.
Also note that one of the sides of the filled area is the square root
function.
BEGIN_PGML
Use the graph to find the area of the shaded region under [`f(x) = [$g]`].
>>[![$altText]!]{$graph}{400}<<
>>Graph of [`y = f(x)`].<<
Area: [_]{$area}{15}
END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.