[npl] / trunk / NationalProblemLibrary / Rochester / setLimitsRates1_5Graphs / ur_lr_1-5_3.pg Repository:
ViewVC logotype

View of /trunk/NationalProblemLibrary/Rochester/setLimitsRates1_5Graphs/ur_lr_1-5_3.pg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 627 - (download) (annotate)
Mon Feb 11 21:35:50 2008 UTC (5 years, 3 months ago) by jj
File size: 8711 byte(s)
Partial cleanup of problem.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9