#DESCRIPTION #KEYWORDS('Integrals', 'Area and Distance') # Interpreting Riemann sums in terms of area #ENDDESCRIPTION ## DBsubject('Calculus') ## DBchapter('Integrals') ## DBsection('Area and Distance') ## Date('5/10/2008') ## Author('Paul Pearson') ## Institution('University of Rochester') ## TitleText1('Calculus: Early Transcendentals') ## EditionText1('6') ## AuthorText1('Stewart') ## Section1('5.1') ## Problem1('2,3,4') DOCUMENT(); loadMacros("PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", "PGgraphmacros.pl", "PGnumericalmacros.pl", "extraAnswerEvaluators.pl" ); TEXT(beginproblem()); # Construct a graph for the left endpoint Riemann sum, # define the function to be graphed, and add it to the graph $graphL = init_graph(-1,-1,9,9,ticks=>[10,10],axes=>[0,0],pixels=>[400,400]);$c = random(12,17,1); # a constant for scaling the function $f = FEQ("$c / x for x in <-1,9> using color:blue and weight:2"); $ftex = "\frac{$c}{x}"; # the parentheses around $fRefL are necessary ($fRefL) = plot_functions( $graphL,$f ); # Generate arrays of x and y values for the Riemann sum. # There are n+1 entries in each array so that we can use # only one pair of arrays for both the left and the right # endpoint Riemann sums. $a = random(2,4,1); # left endpoint of interval$b = $a+4; # right endpoint of interval$n = 8; # number of rectangles $deltax = ($b - $a)/$n; foreach $k (0..$n) { @x[$k] =$a + $k *$deltax; } foreach $k (0..$n) { @y[$k] = &{$fRefL->rule}(@x[$k]); } # Graph the left endpoint Riemann sum$lightblue = $graphL->im->colorAllocate(148,201,255);$darkblue = $graphL->im->colorAllocate(100,100,255); # Create arrays of pixel references for x and y values foreach$k (0..8) { @xpixL[$k] =$graphL->ii(@x[$k]); @ypixL[$k] = $graphL->jj(@y[$k]); } $xaxisL =$graphL->jj(0); # Plot the rectangles in the Riemann sum foreach $k (0..$n-1) { $graphL->im->filledRectangle(@xpixL[$k],@ypixL[$k],@xpixL[$k+1],$xaxisL,$lightblue); $graphL->im->rectangle(@xpixL[$k],@ypixL[$k],@xpixL[$k+1],$xaxisL,$darkblue); } $graphL->lb(new Label ( 8.5,0,'x','black','right','top'));$graphL->lb(new Label ( -0.25,8.5,'y','black','right','top')); # Construct a graph for the right endpoint Riemann sum $graphR = init_graph(-1,-1,9,9,ticks=>[10,10],axes=>[0,0],pixels=>[400,400]); # the parentheses around$fRefR are necessary ($fRefR) = plot_functions($graphR, $f ); # Graph the right endpoint Riemann sum$lightblue = $graphR->im->colorAllocate(148,201,255);$darkblue = $graphR->im->colorAllocate(100,100,255); # Create arrays of pixel references for x and y values foreach$k (0..8) { @xpixR[$k] =$graphR->ii(@x[$k]); @ypixR[$k] = $graphR->jj(@y[$k]); } $xaxisR =$graphR->jj(0); # Plot the rectangles in the Riemann sum foreach $k (1..$n) { $graphR->im->filledRectangle(@xpixR[$k-1],@ypixR[$k],@xpixR[$k],$xaxisR,$lightblue); $graphR->im->rectangle(@xpixR[$k-1],@ypixR[$k],@xpixR[$k],$xaxisR,$darkblue); } $graphR->lb(new Label ( 8.5,0,'x','black','right','top'));$graphR->lb(new Label ( -0.25,8.5,'y','black','right','top')); BEGIN_TEXT The rectangles in the graph below illustrate a left endpoint Riemann sum for $$\displaystyle f(x) = ftex$$ on the interval $$\lbrack a, b \rbrack$$. $BR The value of this left endpoint Riemann sum is \{ans_rule(30)\}$BR $BR$BCENTER \{ begintable(1) \} \{ row( image( insertGraph($graphL), height=>400, width=>400, tex_size=>800 ) ) \} \{ row("Left endpoint Riemann sum for $$y = ftex$$ on $$\lbrack a, b \rbrack$$") \} \{ endtable() \}$ECENTER $BR$HR $BR The rectangles in the graph below illustrate a right endpoint Riemann sum for $$\displaystyle f(x) = ftex$$ on the interval $$\lbrack a, b \rbrack$$.$BR The value of this right endpoint Riemann sum is \{ans_rule(30)\} $BR$BR $BCENTER \{ begintable(1) \} \{ row( image( insertGraph($graphR), height=>400, width=>400, tex_size=>800 ) ) \} \{ row("Right endpoint Riemann sum for $$y = ftex$$ on $$\lbrack a, b \rbrack$$") \} \{ endtable() \} $ECENTER END_TEXT$LeftRiemannSum = 0; foreach $k (0..$n-1) { $LeftRiemannSum =$LeftRiemannSum + @y[$k]; }$LeftRiemannSum = $deltax *$LeftRiemannSum; ANS(num_cmp($LeftRiemannSum));$RightRiemannSum = 0; foreach $k (1..$n) { $RightRiemannSum =$RightRiemannSum + @y[$k]; }$RightRiemannSum = $deltax *$RightRiemannSum; ANS(num_cmp($RightRiemannSum)); SOLUTION(EV3(<<'END_SOLUTION'));$BR $HR${BBOLD}Solution:${EBOLD}$BR $BR (A) The left endpoint Riemann sum is $$f(@x[0]) \cdot 0.5 + f(@x[1]) \cdot 0.5 + \cdots + f(@x[n-1]) \cdot 0.5 = ( @y[0] + @y[1] + \cdots + @y[7] ) \cdot 0.5 = LeftRiemannSum.$$$BR \$BR (B) The right endpoint Riemann sum is $$f(@x[1]) \cdot 0.5 + f(@x[2]) \cdot 0.5 + \cdots + f(@x[n]) \cdot 0.5 = ( @y[1] + @y[2] + \cdots + @y[n] ) \cdot 0.5 = RightRiemannSum.$$ END_SOLUTION ENDDOCUMENT();