[npl] / trunk / NationalProblemLibrary / Rochester / setLimitsRates2Limits / ur_lr_2_10.pg Repository:
ViewVC logotype

View of /trunk/NationalProblemLibrary/Rochester/setLimitsRates2Limits/ur_lr_2_10.pg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 594 - (download) (annotate)
Thu Oct 18 22:40:46 2007 UTC (5 years, 7 months ago) by jj
File size: 9608 byte(s)
Fixed one typesetting issue.

    1 #DESCRIPTION
    2 #KEYWORDS('limits', 'sequences')
    3 # Find limits (intuitively or by experimental calculations).
    4 #ENDDESCRIPTION
    5 
    6 ##KEYWORDS('Calculus')
    7 ##Tagged by ynw2d
    8 
    9 ##DBsubject('Calculus')
   10 ##DBchapter('Limits and Derivatives')
   11 ##DBsection('The Limit of a Function')
   12 ## TitleText1('Calculus: Early Transcendentals')
   13 ## EditionText1('1')
   14 ## AuthorText1('Rogawski')
   15 ## Section1('2.2')
   16 ## Problem1('37')
   17 
   18 ## TitleText2('Calculus: Early Transcendentals')
   19 ## EditionText2('6')
   20 ## AuthorText2('Stewart')
   21 ## Section2('2.3')
   22 ## Problem2('2')
   23 
   24 
   25 
   26 DOCUMENT();        # This should be the first executable line in the problem.
   27 
   28 loadMacros("PG.pl",
   29            "PGbasicmacros.pl",
   30            "PGchoicemacros.pl",
   31            "PGanswermacros.pl",
   32            "PGauxiliaryFunctions.pl",
   33            "PGgraphmacros.pl");
   34 
   35 $showPartialCorrectAnswers=1;
   36 
   37 # utility
   38 sub rnd {
   39   my $x = shift;
   40   my $places = shift;
   41   $places = 0 unless defined($places);
   42   my $sign = ($x <0 ) ? -1 : 1;
   43   $x = abs($x);
   44 
   45   $x = int( $x*10 **(-$places) +.5) *10 **($places);
   46   $sign*$x;
   47 }
   48 
   49 # define a broken graph f and a broken graph g:
   50 
   51 # do .. until to protect against L'Hopital type questions
   52 do {
   53 $ok = 1;
   54 
   55 # first define the parameters (value and first derivatives)
   56 foreach my $i (0..5) {
   57   $f1y[$i] = random(0, 3, 1);
   58   $f1yp[$i] = random(-1,1, 2);
   59   $f2y[$i] = random(0, 3, 1);
   60   $f2yp[$i] = random(-1,1, 2);
   61   $g1y[$i] = random(0, 3, 1);
   62   $g1yp[$i] = random(-1,1, 2);
   63   $g2y[$i] = random(0, 3, 1);
   64   $g2yp[$i] = random(-1,1, 2);
   65 }
   66 
   67 # define the functions
   68 $hermite_f1 = new Hermite( [ -1  , 0,  1, 2 , 3, 4 ],
   69                    [ @f1y ],
   70                    [ @f1yp  ]);
   71 $hermite_f2 = new Hermite( [ -1  , 0,  1, 2 , 3, 4 ],
   72                    [ @f2y ],
   73                    [ @f2yp  ]);
   74 $hermite_g1 = new Hermite( [ -1  , 0,  1, 2 , 3, 4 ],
   75                    [ @g1y ],
   76                    [ @g1yp  ]);
   77 $hermite_g2 = new Hermite( [ -1  , 0,  1, 2 , 3, 4 ],
   78                    [ @g2y ],
   79                    [ @g2yp  ]);
   80 
   81 # define the break points where we switch from one hemite function to the other
   82 # and the value of the function at that point
   83 
   84   $xf = random(0,3);
   85   $yf = random(-1,4);
   86 do {  $xg = random(0,3); } until ($xf != $xg);
   87   $yg = random(-1,4);
   88 
   89 # Now check to see if we might produce a L'Hoptital type question,
   90 # which would be much harder for some students than others
   91 
   92   $ok = 0 if(($xf<$xg) and (rnd($hermite_f1->rf_f->($xf)) == 0 or rnd($hermite_f2->rf_f->($xf)) == 0)
   93     and (rnd($hermite_g1->rf_f->($xf)) == 0) );
   94   $ok = 0 if(($xf>$xg) and (rnd($hermite_f2->rf_f->($xg)) == 0)
   95     and (rnd($hermite_g1->rf_f->($xg)) == 0 or rnd($hermite_g2->rf_f->($xg)) == 0));
   96   $ok = 0 if(($xf==$xg) and (rnd($hermite_f1->rf_f->($xg)) == 0 or rnd($hermite_f2->rf_f->($xg)) == 0)
   97     and (rnd($hermite_g1->rf_f->($xg)) == 0 or rnd($hermite_g2->rf_f->($xg)) == 0));
   98 
   99 } until ($ok == 1);
  100 
  101 # define the broken functions themselves -- we'll need them to answer questions.
  102 sub f_rule {
  103    my $x = shift;
  104      my $out;
  105      if ($x < $xf ) {
  106         $out = $hermite_f1->rf_f->($x);
  107      } elsif ($x == $xf) {
  108       $out = $yf;
  109      } else {
  110         $out = $hermite_f2->rf_f->($x);
  111      }
  112       $out;
  113 };
  114 sub g_rule {
  115   my $x = shift;
  116     my $out;
  117     if ($x < $xg ) {
  118       $out = $hermite_g1->rf_f->($x);
  119      } elsif ($x == $xg) {
  120         $out = $yg;
  121      } else {
  122         $out = $hermite_g2->rf_f->($x);
  123      }
  124      $out;
  125 };
  126 
  127 
  128 # plot the f graph
  129 
  130 $graphf = init_graph(-2,-2,5,5,grid =>[7,7], axes => [0,0], size =>[500,500]);
  131 $graphg = init_graph(-2,-2,5,5,,grid =>[7,7], axes => [0,0], size =>[500,500]);
  132 $f1 = new Fun($hermite_f1->rf_f,$graphf);
  133 $f2 = new Fun($hermite_f2->rf_f,$graphf);
  134 $graphf->stamps(open_circle($xf, $hermite_f1->rf_f->($xf), 'red')   );
  135 $graphf->stamps(open_circle($xf, $hermite_f2->rf_f->($xf), 'red')   );
  136 $graphf ->stamps( closed_circle($xf, $yf, 'red') ); # value at $xf;
  137 $f1->color('red');
  138 $f2->color('red');
  139 # restrict the two partial graph domains so that only the 'active' one is drawn
  140 $f1->domain(-1, $xf);
  141 $f2->domain($xf, 4);
  142 
  143 #plot the g graph
  144 $g1 = new Fun($hermite_g1->rf_f,$graphg);
  145 $g2 = new Fun($hermite_g2->rf_f,$graphg);
  146 $graphg->stamps(open_circle($xg, $hermite_g1->rf_f->($xg), 'blue')  );
  147 $graphg->stamps(open_circle($xg, $hermite_g2->rf_f->($xg), 'blue')  );
  148 $graphg ->stamps(closed_circle($xg, $yg, 'blue') ); # value at $xg;
  149 $g2->color('blue');
  150 $g2->color('blue');
  151 # restrict the two partial graph domains so that only the 'active' one is drawn
  152 $g1->domain(-1, $xg);
  153 $g2->domain($xg, 4);
  154 
  155 TEXT(beginproblem());
  156 
  157 
  158 # draw the graphs
  159 TEXT(
  160 begintable(2),
  161 row( image( insertGraph($graphf), tex_size =>400), image( insertGraph($graphg) , tex_size =>400 )   ),
  162 row(EV2('\(f(x)\)'), EV2('\(g(x)\)')),
  163 endtable(),
  164 );
  165 # now construct the questions
  166 @questions = ();
  167 @answers = ();
  168 
  169 qa( ~~@questions, ~~@answers,
  170 '\( \displaystyle \lim_{x\to $xf^-} [f(x) + g(x) ] \) ',
  171 num_cmp(rnd( f_rule($xf-.00001) +g_rule($xf-.00001)  ), strings => ['DNE'] ),  # we are expecting integer answers
  172 '\( \displaystyle \lim_{x\to $xf^+} [f(x) + g(x) ] \) ',
  173 num_cmp(rnd( f_rule($xf+.00001) +g_rule($xf+.00001)  ), strings => ['DNE'] ),  # we are expecting integer answers
  174 '\( f($xf) + g($xf) \)',
  175 num_cmp(f_rule($xf) + g_rule($xf), strings => ['DNE'] ),
  176 
  177 '\( \displaystyle \lim_{x\to $xf^-} [f(x)g(x) ] \) ',
  178 num_cmp(rnd( f_rule($xf-.00001)*g_rule($xf-.00001) ), strings => ['DNE'] ),  # we are expecting integer answers
  179 '\( \displaystyle \lim_{x\to $xf^+} [f(x)g(x) ] \) ',
  180 num_cmp(rnd( f_rule($xf+.00001)*g_rule($xf+.00001)  ), strings => ['DNE'] ),  # we are expecting integer answers
  181 '\( f($xf)g($xf) \)',
  182 num_cmp(f_rule($xf)*g_rule($xf), strings => ['DNE'] ),
  183 
  184 '\( \displaystyle \lim_{x\to $xf^-} [f( g(x) ) ] \) ',
  185 num_cmp(rnd( f_rule(g_rule($xf-.00001)  ) ), strings => ['DNE'] ),  # we are expecting integer answers
  186 '\( \displaystyle \lim_{x\to $xf^+} [f( g(x) ) ] \) ',
  187 num_cmp(rnd( f_rule(g_rule($xf+.00001) ) ), strings => ['DNE'] ),  # we are expecting integer answers
  188 '\( f( g($xf) ) \)',
  189 num_cmp(f_rule( g_rule($xf) ), strings => ['DNE'] ),
  190 
  191 #check for zeros in answering the division limits
  192 '\( \displaystyle \lim_{x\to $xf^-} [f(x)/g(x) ] \) ',
  193 ( not rnd(g_rule($xf-.00001) ) and  rnd(f_rule($xf-.00001) ) ) ? num_cmp('DNE', strings => ['DNE'] )        # if g is zero, but f is not
  194            : num_cmp(rnd( f_rule($xf-.00001)/g_rule($xf-.00001) , -3 ), tol =>.002, strings => ['DNE'] ),  # the chances of g being identically zero are small since the derivatives at defined points are never zero.
  195 # we are expecting integer answers
  196 '\( \displaystyle \lim_{x\to $xf^+} [f(x)/g(x) ] \) ',
  197 ( not rnd(g_rule($xf+.00001) ) and  rnd(f_rule($xf+.00001) ) ) ? num_cmp('DNE', strings => ['DNE'] )
  198            : num_cmp(rnd( f_rule($xf+.00001)/g_rule($xf+.00001) , -3 ), tol =>.002, strings => ['DNE'] ) ,
  199 # we are expecting integer answers
  200 '\( f($xf)/g($xf) \)',
  201 (rnd(g_rule($xf)) ) ? num_cmp( rnd(f_rule($xf)/g_rule($xf), -3), tol =>.002, strings => ['DNE'] ) : num_cmp('DNE', strings => ['DNE'] ),
  202 
  203 '\( \displaystyle \lim_{x\to $xg^-} [f(x) + g(x) ] \) ',
  204 num_cmp(rnd( f_rule($xg-.00001) +g_rule($xg-.00001) ), strings => ['DNE'] ),   # we are expecting integer answers
  205 '\( \displaystyle \lim_{x\to $xg^+} [f(x) + g(x) ] \) ',
  206 num_cmp(rnd( f_rule($xg+.00001) +g_rule($xg+.00001)  ), strings => ['DNE'] ),  # we are expecting integer answers
  207 '\( f($xg) + g($xg) \)',
  208 num_cmp(f_rule($xg) + g_rule($xg), strings => ['DNE'] ),
  209 
  210 '\( \displaystyle \lim_{x\to $xg^-} [f(x)g(x) ] \) ',
  211 num_cmp(rnd( f_rule($xg-.00001)*g_rule($xg-.00001) ), strings => ['DNE'] ),  # we are expecting integer answers
  212 '\( \displaystyle \lim_{x\to $xg^+} [f(x)g(x) ] \) ',
  213 num_cmp(int( f_rule($xg+.00001)*g_rule($xg+.00001) +.4 ), strings => ['DNE'] ),  # we are expecting integer answers
  214 '\( f($xg)g($xg) \)',
  215 num_cmp(f_rule($xg)*g_rule($xg), strings => ['DNE'] ),
  216 
  217 '\( \displaystyle \lim_{x\to $xg^-} [f( g(x) ) ] \) ',
  218 num_cmp(rnd( f_rule( g_rule($xg-.00001) )), strings => ['DNE'] ) ,  # we are expecting integer answers
  219 '\( \displaystyle \lim_{x\to $xg^+} [f( g(x) ) ] \) ',
  220 num_cmp(rnd( f_rule( g_rule( $xg + .00001 ) ) ), strings => ['DNE']  ),  # we are expecting integer answers
  221 '\( f( g($xg) ) \)',
  222 num_cmp(f_rule( g_rule($xg) ), strings => ['DNE'] ),
  223 
  224 #check for zeros in answering the division limits
  225 '\( \displaystyle \lim_{x\to $xg^-} [f(x)/g(x) ] \) ',
  226 ( not rnd(g_rule($xg-.00001) ) and  rnd(f_rule($xg-.00001) ) ) ? num_cmp('DNE', strings => ['DNE'] )        # if g is zero, but f is not
  227            : num_cmp(rnd( f_rule($xg-.00001)/g_rule($xg-.00001) , -3 ), tol =>.002, strings => ['DNE'] ),  # the chances of g being identically zero are small since the derivatives at defined points are never zero.
  228 # we are expecting integer answers
  229 '\( \displaystyle \lim_{x\to $xg^+} [f(x)/g(x) ] \) ',
  230 ( not rnd(g_rule($xg+.00001) ) and  rnd(f_rule($xg+.00001) ) ) ? num_cmp('DNE', strings => ['DNE'] )
  231            : num_cmp(rnd( f_rule($xg+.00001)/g_rule($xg+.00001) , -3 ), tol =>.002, strings => ['DNE'] ) ,
  232 # we are expecting integer answers
  233 '\( f($xg)/g($xg) \)',
  234 (rnd(g_rule($xg)) ) ? num_cmp( rnd(f_rule($xg)/g_rule($xg), -3), tol =>.002, strings => ['DNE'] ) : num_cmp('DNE', strings => ['DNE'] ),
  235 
  236 );
  237 
  238 @slice = NchooseK(scalar(@questions) ,4);
  239 
  240 BEGIN_TEXT
  241 $BR
  242 The graphs of \( f \) and \( g \) are given above.  Use them to evaluate each quantity below.
  243 Write $BITALIC DNE$EITALIC if the limit or value does not exist
  244 (or if it's infinity).
  245 $BR
  246 \{ match_questions_list(@questions[@slice]  ) \}
  247 END_TEXT
  248 
  249 ANS(@answers[@slice]     );
  250 ENDDOCUMENT();        # This should be the last executable line in the problem.

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9