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