I am having a problem detecting this error that only appears for a few of my students. How is infinity even being called as an input here?
Below is the error statement and code:
Any help is most appreciated:
Problem4 ERROR caught by Translator while processing problem file:Payer/M105_HW_4/Derivative_by_definition2.pg **************** ERRORS from evaluating PG file:
Can't convert an Infinity to a Real Number at line 411 of [PG]/macros/PGnumericevaluators.pl Died within main::NUM_CMP called at line 411 of [PG]/macros/PGnumericevaluators.pl from within main::num_cmp called at line 110 of (eval 2863)
****************
------Input Read 1 ## DESCRIPTION 2 ## Calculus 3 ## ENDDESCRIPTION 4 5 ## Tagged by dgt5v 6 ## Library/Rochester/setDerivatives1/ur_dr_1_10 7 8 9 ## DBsubject(Calculus - single variable) 10 ## DBchapter(Differentiation) 11 ## DBsection(Definition of the derivative) 12 ## Date(6/3/2002) 13 ## Institution(ASU) 14 ## Author(Utah ww group) 15 ## Level(3) 16 ## TitleText1('Calculus: Early Transcendentals') 17 ## AuthorText1('Rogawski') 18 ## EditionText1('1') 19 ## Section1('3.1') 20 ## Problem1('') 21 ## TitleText2('Calculus: Early Transcendentals') 22 ## AuthorText2('Stewart') 23 ## EditionText2('6') 24 ## Section2('2.8') 25 ## Problem2('') 26 ## TitleText3('Calculus I') 27 ## AuthorText3('Jerrold Marsden and Alan Weinstein') 28 ## EditionText3('2') 29 ## Section3('Derivatives and Limits') 30 ## Problem3('') 31 ## TitleText4('Calculus') 32 ## AuthorText4('Dale Varberg, Edwin J. Purcell, and Steven E. Rigdon') 33 ## EditionText4('9') 34 ## Section4('Limits') 35 ## Problem4('') 36 ## TitleText5('Calculus: Early Transcendentals') 37 ## AuthorText5('Stewart') 38 ## EditionText5('5') 39 ## Section5('2.8') 40 ## Problem5('') 41 ## KEYWORDS('tangent line', 'derivatives','calculus') 42 43 DOCUMENT(); # This should be the first executable line in the problem. 44 45 loadMacros( 46 "PGstandard.pl", 47 "PGchoicemacros.pl", 48 "PGanswermacros.pl", 49 "PGauxiliaryFunctions.pl", 50 "extraAnswerEvaluators.pl" 51 ); 52 53 TEXT(beginproblem()); 54 $showPartialCorrectAnswers = 1; 55 56 $a = non_zero_random(2,10,1); 57 $am = -$a; 58 $aa =$a**2; 59 $am2 = Compute("2*$am"); 60 $p1 = $a - 4; 61 $p2 = $a - 3; 62 $p3 = $a - 2; 63 $p4 = $a - 1; 64 $p5 = $a + 1; 65 $p6 = $a + 2; 66 $p7 = $a + 3; 67 $p8 = $a + 4; 68 69 $px1 = random($p1,$p2,1); 70 $px2 = random($p3,$p4,1); 71 $x1 = Compute("-$px1"); 72 $x2 = Compute("-$px2"); 73 $x3 = random($p5,$p6,1); 74 $x4 = random($p7,$p8,1); 75 76 $m1 = -($x1+$am)**(-2); 77 $m2 = -($x2+$am)**(-2); 78 $m3 = -($x3+$am)**(-2); 79 $m4 = -($x4+$am)**(-2); 80 81 $xx = $x1*$x1; 82 $amx2 =$am2*$x1; 83 $den1 =Compute("$xx +$amx2 +$aa"); 84 85 $xxii = $x2*$x2; 86 $amii =$am2*$x2; 87 $den2 =Compute("$xxii +$amii +$aa"); 88 89 $xxiii = $x3*$x3; 90 $amiii =$am2*$x3; 91 $den3 =Compute("$xxiii +$amiii +$aa"); 92 $ans3 =Compute("-1/$den3"); 93 $xxiv = $x4*$x4; 94 $amiv =$am2*$x4; 95 $den4 =Compute("$xxiv +$amiv +$aa"); 96 97 98 99 TEXT(EV2(<<EOT)); 100 Let \[ f(x) = \frac{1}{x $am } \] 101 Use the limit definition of the derivative to find 102 $BR (i) \( f'( $x1 ) = \) \{ ans_rule(20) \} 103 $BR (ii) \( f'( $x2 ) = \) \{ ans_rule(20) \} 104 $BR (iii) \( f'( $x3 ) = \) \{ ans_rule(20) \} 105 $BR (iv) \( f'( $x4 ) = \) \{ ans_rule(20) \} 106 $PAR 107 To avoid calculating four separate limits, Find the general case of the derivative first, then evaluate for the four inputs of \(x = $x1\), \(x = $x2\), \(x = $x3\) and \(x = $x4\). 108 EOT 109 110 ANS(num_cmp($m1),num_cmp($m2),num_cmp($m3),num_cmp($m4)); 111 112 113 SOLUTION(EV3(<<'END_SOLUTION')); 114 $PAR SOLUTION $PAR 115 116 117 Applying the definition of the derivative requires that we apply the limit as \({h\to 0}\) to the rational expression of \(\frac{f(x+h)-f(x)}{h}\). $BR 118 "h" is the horizontal distance between two given coordinate points of `f(x)`. The average rate of change between two coordinate points is called a secant slope. When these two points are driven together as is the case when \({h\to 0}\), the secant slope becomes a tangent slope for the given coordinate point. Here we will apply the definition once to the function `f(x)` and then evaluate the derivative for the four given inputs. $PAR 119 120 Take the derivative using the definition for:\[ f(x) = \frac{1}{x $am} \] $BR 121 ``\begin{aligned}&\\ 122 f'(x) &= \displaystyle\lim_{h\to 0}\frac{\frac{1}{x +h $am}-\left(\frac{1}{x $am}\right)}{h} && \text{Apply the definition of the derivative. } \\ 123 &=\displaystyle\lim_{h\to 0}\frac{\frac{1\cdot(x $am)}{(x +h $am)(x $am)}-\left(\frac{1\cdot (x +h $am)}{(x $am)(x +h $am)}\right)}{h} && \text{Form a common denominator.} \\ 124 &=\displaystyle\lim_{h\to 0}\frac{\frac{x $am -x - h +$a}{(x +h $am)(x $am)}}{h} && \text{Distribute the negative through the numerator.} \\ 125 &=\displaystyle\lim_{h\to 0}\frac{\frac{ - h }{(x +h $am)(x $am)}}{h} && \text{Cancel like terms.}\\ 126 &=\displaystyle\lim_{h\to 0}\frac{\frac{ - h }{(x +h $am)(x $am)}\cdot \frac{1}{h}}{h\cdot \frac{1}{h}} && \text{Multiply the numerator and denominator by } \frac{1}{h}.\\ 127 &=\frac{ - 1 }{(x +0 $am)(x $am)} && \text{Take the limit as } {h\to 0}.\\ 128 &=\frac{ - 1 }{(x $am)(x $am)} && \text{Reducing.. } \\ 129 &=\frac{ - 1 }{x^2 $am x $am x +$aa} && \text{Squaring the denominator. }\\ 130 f'(x)&=\frac{ - 1 }{x^2 $am2 x +$aa} && \text{The derivative. } 131 \end{aligned}`` 132 $BR 133 Now we have only to evaluate for each input:$BR 134 i) ``\begin{aligned}&\\ 135 f'($x1) &= \frac{ - 1 }{($x1)^2 $am2 ($x1) +$aa} \\ 136 f'($x1)&=\frac{ - 1 }{$xx + $amx2 +$aa} && \text{Evaluating. }\\ 137 f'($x1)&=\frac{ - 1 }{$den1} && \text{The derivative. } 138 \end{aligned}`` 139 140 ii) ``\begin{aligned}&\\ 141 f'($x2) &= \frac{ - 1 }{($x2)^2 $am2 ($x2) +$aa} \\ 142 f'($x2)&=\frac{ - 1 }{$xxii + $amii +$aa} && \text{Evaluating. }\\ 143 f'($x2)&=\frac{ - 1 }{$den2} && \text{The derivative. } 144 \end{aligned}`` 145 146 iii) ``\begin{aligned}&\\ 147 f'($x3) &= \frac{ - 1 }{($x3)^2 $am2 \cdot $x3 +$aa} \\ 148 f'($x3)&=\frac{ - 1 }{$xxiii $amiii +$aa} && \text{Evaluating. }\\ 149 f'($x3)&=\frac{ - 1 }{$den3} && \text{The derivative. }\\ 150 f'($x3)&=$ans3 && \text{The derivative. } 151 \end{aligned}`` 152 153 iv) ``\begin{aligned}&\\ 154 f'($x4) &= \frac{ - 1 }{($x4)^2 $am2 \cdot $x4 +$aa} \\ 155 f'($x4)&=\frac{ - 1 }{$xxiv $amiv +$aa} && \text{Evaluating. }\\ 156 f'($x4)&=\frac{ - 1 }{$den4} && \text{The derivative. } 157 \end{aligned}`` 158 159 160 END_SOLUTION 161 162 163 ENDDOCUMENT(); # This should be the last executable line in the problem.