### Error messages

`Timeout after processing this problem for 60 seconds. Check for infinite loops in problem source Died within WeBWorK::PG::Local::alarm_handler called at line 26 of [PG]/lib/Value/Real.pm from within (eval) called at line 26 of [PG]/lib/Value/Real.pm from within Value::Real::new called at line 726 of [PG]/lib/Value.pm from within Value::promote called at line 742 of [PG]/lib/Value.pm from within Value::checkOpOrderWithPromote called at line 90 of [PG]/lib/Value/Real.pm from within Value::Real::div called at line 752 of [PG]/lib/Value.pm from within Value::binOp called at line 762 of [PG]/lib/Value.pm from within Value::_div called at line 326 of [PG]/macros/PGnumericalmacros.pl from within main::create_cubic_spline called at line 71 of [TMPL]/alfredLibrary/samples/oraclefunctionexample.pg `

### Error details

Problem1 ERROR caught by Translator while processing problem file:alfredLibrary/samples/oraclefunctionexample.pg **************** Timeout after processing this problem for 60 seconds. Check for infinite loops in problem source Died within WeBWorK::PG::Local::alarm_handler called at line 26 of [PG]/lib/Value/Real.pm from within (eval) called at line 26 of [PG]/lib/Value/Real.pm from within Value::Real::new called at line 726 of [PG]/lib/Value.pm from within Value::promote called at line 742 of [PG]/lib/Value.pm from within Value::checkOpOrderWithPromote called at line 90 of [PG]/lib/Value/Real.pm from within Value::Real::div called at line 752 of [PG]/lib/Value.pm from within Value::binOp called at line 762 of [PG]/lib/Value.pm from within Value::_div called at line 326 of [PG]/macros/PGnumericalmacros.pl from within main::create_cubic_spline called at line 71 of [TMPL]/alfredLibrary/samples/oraclefunctionexample.pg **************** ------Input Read 1 ##DESCRIPTION 2 # 3 # File Created: 4 # Last Modified: 5/13/2008 5 # Problem Author: 6 # WeBWorK Entry: 7 # Location: 8 # 9 ##ENDDESCRIPTION 10 11 ##KEYWORDS() 12 ## 13 14 ## DBsubject('WeBWorK') 15 ## DBchapter('WeBWorK Tutorial') 16 ## DBsection('Alfred Samples') 17 ## Date('') 18 ## Author('') 19 ## Institution('Rochester') 20 ## TitleText1('') 21 ## EditionText1('') 22 ## AuthorText1('') 23 ## Section1('') 24 ## Problem1('') 25 26 27 &DOCUMENT(); 28 29 loadMacros("PG.pl", 30 "PGbasicmacros.pl", 31 "PGchoicemacros.pl", 32 "PGanswermacros.pl", 33 "PGnumericalmacros.pl", 34 "PGauxiliaryFunctions.pl", 35 "MathObjects.pl" 36 ); 37 38 TEXT(beginproblem()); 39 40 ## By default numbers are displayed at 6 decimal places of accuracy, this flag 41 ## displays them in their full precision. 42 Context()->{format}{number} = ""; 43 44 # define function to be evaluated 45 $a= random(1,3,.1); 46 $b= random(-4,4,.1); 47 $c = random(-4,4,.1); 48 $x0=random(-2,2,0.1); 49 $function = Formula(" $a*x^2+$b*x +$c "); 50 $f = $function->perlFunction; 51 $df = $function->D('x'); 52 $dfx0 = $df->eval(x=>$x0); 53 54 55 ## There are two sections of code now to create the oracle function. The first 56 ## section is to create a cubic spline approximation to the function that 57 ## can be passed to the html code that actually prints the oracle function. 58 59 ## Section 1: Creating the cubic spline approximation to f. 60 61 $llimit = -5; $rlimit = 5; 62 my $num_of_intervals = 500; # number of interpolation points 63 my $delta = ($rlimit-$llimit)/($num_of_intervals); 64 my (@x_values, @y_values); 65 foreach my $i (0..$num_of_intervals) { 66 my $x = $llimit + $delta*$i; 67 my $y = &$f($x); 68 push(@x_values, $x); push(@y_values,$y); 69 } 70 71 ($t_ref, $a_ref, $b_ref, $c_ref, $d_ref) = create_cubic_spline (~~@x_values, ~~@y_values); 72 73 $f_approx = cubic_spline(~~@x_values, ~~@y_values); 74 75 #calculate a javaScript runtime cubic spline representation of this function. 76 77 HEADER_TEXT(javaScript_cubic_spline(~~@x_values,~~@y_values, name => 'func', llimit => -3, rlimit => 3) ); 78 79 ## End cubic spline creation. 80 81 82 83 # A warning that we are using javaScript 84 TEXT(M3("", 85 "\begin{rawhtml} 86 <NOSCRIPT> This problem requires that Java Script be enabled </NOSCRIPT> \end{rawhtml} 87 ", 88 "<NOSCRIPT> This problem requires that Java Script be enabled </NOSCRIPT>" 89 )); 90 91 92 BEGIN_TEXT 93 $PAR 94 The oracle function \( f(x) \) is presented below. For each \(x\) value you enter the oracle will 95 tell you the value \( f(x) \). 96 Calculate the derivative of the function at \( $x0 \) using the Newton quotient definition. 97 $PAR 98 END_TEXT 99 100 101 ## This section is the javascript to print the oracle function. 102 103 $javaScript2 = begintable(3) . 104 MODES(HTML =>q{<TR> 105 <TH>x</TH><TH></TH><TH>f(x)</TH> 106 <TR>}, 107 TeX => "x & \(\rightarrow\) & f(x)\\" 108 ) . 109 row(MODES(HTML => qq{<INPUT TYPE="text" NAME="Input" Value = "$x0" Size="16">}, TeX => '\fbox{Enter \(x\)}' ), 110 MODES(HTML => qq{<INPUT TYPE="button" VALUE="---f-->" 111 OnClick="this.form.Output.value=func(this.form.Input.value);">}, TeX => '\(\rightarrow\)' ), 112 MODES(HTML => qq{<INPUT TYPE="text" NAME="Output" Size="30">}, TeX => 'result: \(f(x)\)') 113 ) . 114 row(MODES(HTML => qq{<INPUT TYPE="text" NAME="Input2" Value = "$x0" Size="16">}, TeX => '\fbox{Enter \(x\)}' ), 115 MODES(HTML => qq{<INPUT TYPE="button" VALUE="---f-->" 116 OnClick="this.form.Output2.value=func(this.form.Input2.value);">}, TeX => '\(\rightarrow\)' ), 117 MODES(HTML => qq{<INPUT TYPE="text" NAME="Output2" Size="30">}, TeX => 'result: \(f(x)\)') 118 ) . 119 row(MODES(HTML => qq{<INPUT TYPE="text" NAME="Input3" Value = "$x0" Size="16">}, TeX => '\fbox{Enter \(x\)}' ), 120 MODES(HTML => qq{<INPUT TYPE="button" VALUE="---f-->" 121 OnClick="this.form.Output3.value=func(this.form.Input3.value);">}, TeX => '\(\rightarrow\)' ), 122 MODES(HTML => qq{<INPUT TYPE="text" NAME="Output3" Size="30">}, TeX => 'result: \(f(x)\)') 123 ) . endtable(); 124 125 TEXT($javaScript2); 126 127 ## End the javascript printing section. 128 129 130 BEGIN_TEXT 131 $PAR 132 Remember the technique for finding instantaneous velocities from average velocities? 133 This is the same thing. 134 135 END_TEXT 136 # The answer 137 138 Context()->flags->set( 139 tolerance => 1, 140 tolType => 'relative', 141 format => '%0.14g'); 142 143 my ($ans_eval) = num_cmp( $dfx0, reltol => 1, format => '%0.14g'); 144 145 146 # we'll modify the answer messages a bit to give some encouragement. 147 my $answer_evaluator = sub { 148 my $x = shift; 149 my $ans_hash = $ans_eval->evaluate($x); 150 return $ans_hash unless $x; 151 # otherwise fix the error message 152 $correct_answer = $ans_hash->{correct_ans}; 153 my $error = $correct_answer - $ans_hash ->{student_ans}; 154 #warn "correct answer $correct_answer and student answer", $ans_hash ->{student_ans}, "error $error"; 155 my $relerror = 100* abs($error/$correct_answer) unless abs($correct_answer) <.000000001 ; 156 $relerror = .000000001 unless defined($relerror); 157 if ($relerror < 1 ) { 158 $ans_hash->{ans_message} = "Good. Your answer is off by only about $error"; 159 } elsif ($relerror < 10 ) { 160 $ans_hash->{ans_message} = 'Your answer is within 10%. '; 161 } elsif($relerror < 50) { 162 $ans_hash->{ans_message} = 'Your answer is within 50%. '; 163 } else { 164 $ans_hash->{ans_message} = 'Your answer is off by more than 50%.'; 165 } 166 $ans_hash; 167 }; 168 169 ANS($answer_evaluator ); #We are allowing 1 percent error for the answer. 170 171 172 &ENDDOCUMENT;