[npl] / trunk / NationalProblemLibrary / Rochester / setIntegrals0Theory / S05.01.AreaDistance.PTP02.pg Repository:
ViewVC logotype

View of /trunk/NationalProblemLibrary/Rochester/setIntegrals0Theory/S05.01.AreaDistance.PTP02.pg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1552 - (download) (annotate)
Fri Oct 15 20:57:38 2010 UTC (2 years, 7 months ago) by pearson
File size: 6347 byte(s)
Upgraded to MathObjects, improved graph

    1 #DESCRIPTION
    2 #KEYWORDS('Integrals', 'Area and Distance','Riemann sums','area')
    3 #  Interpreting Riemann sums in terms of area
    4 #ENDDESCRIPTION
    5 
    6 ## DBsubject('Calculus')
    7 ## DBchapter('Integrals')
    8 ## DBsection('Area and Distance')
    9 ## Date('5/10/2008')
   10 ## Author('Paul Pearson')
   11 ## Institution('University of Rochester')
   12 ## TitleText1('Calculus: Early Transcendentals')
   13 ## EditionText1('6')
   14 ## AuthorText1('Stewart')
   15 ## Section1('5.1')
   16 ## Problem1('2,3,4')
   17 
   18 DOCUMENT();
   19 loadMacros(
   20 "PGstandard.pl",
   21 "PGchoicemacros.pl",
   22 "PGgraphmacros.pl",
   23 "MathObjects.pl",
   24 "weightedGrader.pl",
   25 #           "PGanswermacros.pl",
   26 #           "PGnumericalmacros.pl",
   27 #           "extraAnswerEvaluators.pl",
   28 );
   29 
   30 TEXT(beginproblem());
   31 
   32 install_weighted_grader();
   33 
   34 $refreshCachedImages = 1;
   35 $showPartialCorrectAnswers = 1;
   36 
   37 # Construct a graph for the left endpoint Riemann sum,
   38 # define the function to be graphed, and add it to the graph
   39 $graphL = init_graph(-1,-1,9,9,ticks=>[10,10],axes=>[0,0],pixels=>[400,400]);
   40 $graphL->lb('reset');
   41 foreach my $i (1..8) {
   42   $graphL->lb( new Label($i,-0.5,$i, 'black','center','middle'));
   43   $graphL->lb( new Label(-0.5,$i,$i, 'black','center','middle'));
   44 }
   45 $graphL->lb(new Label ( 8.5,0.25,'x','black','center','middle'));
   46 $graphL->lb(new Label ( 0.25,8.5,'y','black','center','middle'));
   47 
   48 
   49 $c = random(12,17,1); # a constant for scaling the function
   50 $f = FEQ("$c / x for x in <-1,9> using color:blue and weight:2");
   51 $ftex = "\frac{$c}{x}";
   52 # the parentheses around $fRefL are necessary
   53 ($fRefL) = plot_functions( $graphL, $f );
   54 
   55 
   56 # Generate arrays of x and y values for the Riemann sum.
   57 # There are n+1 entries in each array so that we can use
   58 # only one pair of arrays for both the left and the right
   59 # endpoint Riemann sums.
   60 $a = random(2,4,1); # left endpoint of interval
   61 $b = $a+4; # right endpoint of interval
   62 $n = 8; # number of rectangles
   63 $deltax = ($b - $a)/$n;
   64 foreach $k (0..$n) { $x[$k] = $a + $k * $deltax; }
   65 foreach $k (0..$n) { $y[$k] = &{$fRefL->rule}($x[$k]); }
   66 
   67 
   68 # Graph the left endpoint Riemann sum
   69 $lightblue = $graphL->im->colorAllocate(148,201,255);
   70 $darkblue = $graphL->im->colorAllocate(100,100,255);
   71 # Create arrays of pixel references for x and y values
   72 foreach $k (0..8) {
   73    $xpixL[$k] = $graphL->ii($x[$k]);
   74    $ypixL[$k] = $graphL->jj($y[$k]);
   75 }
   76 $xaxisL = $graphL->jj(0);
   77 # Plot the rectangles in the Riemann sum
   78 foreach $k (0..$n-1) {
   79    $graphL->im->filledRectangle($xpixL[$k],$ypixL[$k],$xpixL[$k+1],$xaxisL,$lightblue);
   80    $graphL->im->rectangle($xpixL[$k],$ypixL[$k],$xpixL[$k+1],$xaxisL,$darkblue);
   81 }
   82 
   83 
   84 # Construct a graph for the right endpoint Riemann sum
   85 $graphR = init_graph(-1,-1,9,9,ticks=>[10,10],axes=>[0,0],pixels=>[400,400]);
   86 $graphR->lb('reset');
   87 foreach my $i (1..8) {
   88   $graphR->lb( new Label($i,-0.5,$i, 'black','center','middle'));
   89   $graphR->lb( new Label(-0.5,$i,$i, 'black','center','middle'));
   90 }
   91 $graphR->lb(new Label ( 8.5,0.25,'x','black','center','middle'));
   92 $graphR->lb(new Label ( 0.25,8.5,'y','black','center','middle'));
   93 
   94 # the parentheses around $fRefR are necessary
   95 ($fRefR) = plot_functions( $graphR, $f );
   96 
   97 
   98 # Graph the right endpoint Riemann sum
   99 $lightblue = $graphR->im->colorAllocate(148,201,255);
  100 $darkblue = $graphR->im->colorAllocate(100,100,255);
  101 # Create arrays of pixel references for x and y values
  102 foreach $k (0..8) {
  103    $xpixR[$k] = $graphR->ii($x[$k]);
  104    $ypixR[$k] = $graphR->jj($y[$k]);
  105 }
  106 $xaxisR = $graphR->jj(0);
  107 # Plot the rectangles in the Riemann sum
  108 foreach $k (1..$n) {
  109    $graphR->im->filledRectangle($xpixR[$k-1],$ypixR[$k],$xpixR[$k],$xaxisR,$lightblue);
  110    $graphR->im->rectangle($xpixR[$k-1],$ypixR[$k],$xpixR[$k],$xaxisR,$darkblue);
  111 }
  112 
  113 
  114 ##############################################
  115 #  Main text
  116 
  117 BEGIN_TEXT
  118 The rectangles in the graph below illustrate a left endpoint Riemann sum for \( \displaystyle f(x) = $ftex \) on the interval \( \lbrack $a, $b \rbrack \).
  119 $BR
  120 The value of this left endpoint Riemann sum is \{NAMED_ANS_RULE('optional1',30)\},
  121 and this Riemann sum is an \{ NAMED_POP_UP_LIST('optional2',['?','overestimate
  122 of','equal to','underestimate of','there is ambiguity']) \} the area
  123 of the region enclosed by \(\displaystyle y = f(x) \), the x-axis, and
  124 the vertical lines x = $a and x = $b.
  125 $BR
  126 $BR
  127 $BCENTER
  128 \{ begintable(1) \}
  129 \{ row( image( insertGraph($graphL), height=>400, width=>400, tex_size=>800 ) ) \}
  130 \{ row("Left endpoint Riemann sum for \( y = $ftex \) on \( \lbrack $a, $b \rbrack \)") \}
  131 \{ endtable() \}
  132 $ECENTER
  133 $BR
  134 $HR
  135 $BR
  136 The rectangles in the graph below illustrate a right endpoint Riemann sum for \( \displaystyle f(x) = $ftex \) on the interval \( \lbrack $a, $b \rbrack \).
  137 $BR
  138 The value of this right endpoint Riemann sum is \{NAMED_ANS_RULE('optional3',30)\},
  139 and this Riemann sum is an \{ NAMED_POP_UP_LIST('optional4',['?','overestimate of','equal to','underestimate of','there is ambiguity']) \} the area of the region enclosed by \(\displaystyle y = f(x) \), the x-axis, and the vertical lines x = $a and x = $b.
  140 $BR
  141 $BR
  142 $BCENTER
  143 \{ begintable(1) \}
  144 \{ row( image( insertGraph($graphR), height=>400, width=>400, tex_size=>800 ) ) \}
  145 \{ row("Right endpoint Riemann sum for \( y = $ftex \) on \( \lbrack $a, $b \rbrack \)") \}
  146 \{ endtable() \}
  147 $ECENTER
  148 END_TEXT
  149 
  150 
  151 
  152 ##################################################
  153 #  Answer evaluation
  154 
  155 $LeftRiemannSum = 0;
  156 foreach $k (0..$n-1) { $LeftRiemannSum = $LeftRiemannSum + $y[$k]; }
  157 $LeftRiemannSum = Real("$deltax * $LeftRiemannSum");
  158 NAMED_WEIGHTED_ANS('optional1',$LeftRiemannSum->cmp(),45);
  159 
  160 NAMED_WEIGHTED_ANS('optional2',str_cmp("overestimate of"),5);
  161 
  162 $RightRiemannSum = 0;
  163 foreach $k (1..$n) { $RightRiemannSum = $RightRiemannSum + $y[$k]; }
  164 $RightRiemannSum = Real("$deltax * $RightRiemannSum");
  165 NAMED_WEIGHTED_ANS('optional3',$RightRiemannSum->cmp(),45);
  166 
  167 NAMED_WEIGHTED_ANS('optional4',str_cmp("underestimate of"),5);
  168 
  169 
  170 SOLUTION(EV3(<<'END_SOLUTION'));
  171 $BR
  172 $HR
  173 ${BBOLD}Solution:${EBOLD}
  174 $BR
  175 $BR
  176 
  177 (A) The left endpoint Riemann sum is
  178 \( f($x[0]) \cdot 0.5 + f($x[1]) \cdot 0.5 + \cdots + f($x[$n-1]) \cdot 0.5
  179 = ( $y[0] + $y[1] + \cdots + $y[7] ) \cdot 0.5 = $LeftRiemannSum.\)
  180 $BR
  181 $BR
  182 
  183 (B) The right endpoint Riemann sum is
  184 \( f($x[1]) \cdot 0.5 + f($x[2]) \cdot 0.5 + \cdots + f($x[$n]) \cdot 0.5
  185 = ( $y[1] + $y[2] + \cdots + $y[$n] ) \cdot 0.5  = $RightRiemannSum.\)
  186 
  187 END_SOLUTION
  188 
  189 COMMENT('MathObject version');
  190 ENDDOCUMENT();

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9