DOCUMENT();

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

$plot = Plot(
    xmin       => 0,
    xmax       => 5,
    ymin       => 0,
    ymax       => 20,
    aria_label => 'Riemann Sum plot of y=x^3+3',
);

$f = Formula('x^2 + 3');
$plot->add_function(
    $f,
    'x',
    0,
    5,
    color        => 'blue',
    name         => 'A',
    fill         => 'xaxis',
    fill_min     => 0,
    fill_max     => 4,
    fill_color   => 'green',
    fill_opacity => 0.2
);

$dx = 0.5;
for $i (0 .. 7) {
    my $x0 = $i * $dx;
    my $x1 = $x0 + $dx;
    my $y  = $f->eval(x => $x0 + $dx / 2);
    $plot->add_dataset(
        [ $x0, 0 ],
        [ $x0, $y ],
        [ $x1, $y ],
        [ $x1, 0 ],
        [ $x0, 0 ],
        fill         => 'self',
        fill_color   => 'blue',
        fill_opacity => 0.2,
    );
}

$image = image($plot);

BEGIN_PGML
The following is a graph of the function [`y=[$f]`] and the midpoint Riemann
sum rectangles.

>>[! Plot of y=x^2+3 and the Reimann sums !]{$plot}{500} <<

END_PGML

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();