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 PGikz.pl
is used to create the plot.
$a = random(-4, 2); $b = random(1, 4); $g = Compute("$b + sqrt(x - $a)"); $gtex = "$b + \sqrt{" . nicestring([ 1, -$a ]) . '}'; $ans = 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
Setup
We create a randomly transformed version of sqrt(x)
as the function with a reasonably straightforward answer.
The nicestring
function is useful for printing polynomials in a nice way.
The graph is created with PGtikz.pl
, a very 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) = [$gtex]`]. >>[@ image($graph, width => 400, tex_size => 800) @]*<< >>Graph of [`y = f(x)`].<< Area: [_]{$ans}{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.