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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 629 - (download) (annotate)
Fri Feb 15 21:32:56 2008 UTC (5 years, 3 months ago) by jj
File size: 5992 byte(s)
Fixed bug 1415, made problem look nicer.

    1 ##DESCRIPTION
    2 ##KEYWORDS('limit','definition', 'left limit')
    3 ##  Find the derivative of an oracle function using
    4 ##  the definition of the derivative.
    5 ##ENDDESCRIPTION
    6 
    7 ##KEYWORDS('Calculus')
    8 ##Tagged by ynw2d
    9 
   10 ##DBsubject('Calculus')
   11 ## DBchapter('Limits and Derivatives')
   12 ##DBsection('Continuity')
   13 
   14 DOCUMENT();
   15 
   16 loadMacros("PG.pl",
   17            "PGbasicmacros.pl",
   18            "PGchoicemacros.pl",
   19            "PGanswermacros.pl",
   20            "PGnumericalmacros.pl",
   21            );
   22 
   23 
   24 # define function1 to be evaluated
   25 $a1= random(-3,3,0.1);
   26 $b1= random(-3,3,0.1);
   27 $c1 = random(-3,3,0.1);
   28 
   29 
   30 $f1_str = FEQ(" ${a1}x^2+${b1}x +$c1 ");
   31 $f1 = sub {
   32   my $x = shift;
   33   $a1*$x*$x + $b1*$x +$c1;
   34 };
   35 
   36 # define function2 to be evaluated
   37 $a2= random(-3,3,0.1);
   38 $b2= random(-3,3,0.1);
   39 $c2 = random(-3,3,0.1);
   40 
   41 
   42 $f2_str = FEQ(" ${a2}x^2+${b2}x +$c2 ");
   43 $f2 = sub {
   44   my $x = shift;
   45   $a2*$x*$x + $b2*$x +$c2;
   46 };
   47 
   48 # define function3 to be evaluated
   49 $a3= random(-3,3,0.1);
   50 $b3= random(-3,3,0.1);
   51 $c3 = random(-3,3,0.1);
   52 
   53 
   54 $f3_str = FEQ(" ${a3}x^2+${b3}x +$c3 ");
   55 $f3 = sub {
   56   my $x = shift;
   57   $a3*$x*$x + $b3*$x +$c3;
   58 };
   59 
   60 
   61 
   62 $llimit = -5; $rlimit = 5;
   63 $del = .05;
   64 $x0=random($llimit+$del,$rlimit-$del , .01);
   65 
   66 #  Calculate the cubic spline approximation
   67 
   68 my $num_of_intervals = 500;  # number of interpolation points
   69 my $delta =  ($rlimit-$llimit)/($num_of_intervals);
   70 my (@x_values, @y_values);
   71 foreach my $i (0..$num_of_intervals) {
   72   my $x = $llimit + $delta*$i;
   73   my $y1 = &$f1($x);
   74   my $y2 = &$f2($x);
   75   my $y3 = &$f3($x);
   76   push(@x_values, $x); push(@y1_values,$y1); push(@y2_values,$y2); push(@y3_values,$y3)
   77 }
   78 
   79 $one =     random(1,3,1);
   80 $two =     random(1,3,1);
   81 $three =   random(1,3,1);
   82 
   83 HEADER_TEXT(javaScript_cubic_spline(~~@x_values,~~@y1_values, name => 'func1', llimit => $llimit, rlimit => $rlimit) );
   84 HEADER_TEXT(javaScript_cubic_spline(~~@x_values,~~@y2_values, name => 'func2', llimit => $llimit, rlimit => $rlimit) );
   85 HEADER_TEXT(javaScript_cubic_spline(~~@x_values,~~@y3_values, name => 'func3', llimit => $llimit, rlimit => $rlimit) );
   86 
   87 $f1_approx = cubic_spline(~~@x_values, ~~@y1_values);
   88 $f2_approx = cubic_spline(~~@x_values, ~~@y2_values);
   89 $f3_approx = cubic_spline(~~@x_values, ~~@y3_values);
   90 
   91 $left_limit  = PG_restricted_eval( qq{ ~~&~~$f${one}_approx($x0)  });
   92 $value       = PG_restricted_eval( qq{ ~~&~~$f${two}_approx($x0)  });
   93 $right_limit = PG_restricted_eval( qq{ ~~&~~$f${three}_approx($x0)  });
   94 
   95 HEADER_TEXT(<<EOF);
   96 <SCRIPT LANGUAGE="JavaScript">
   97 <!-- Begin
   98 function func(x) {
   99   if ( x < $x0 ) {   //determines whether the function is left or right continuous.
  100      return( func$one(x) );
  101   } else if ( x == $x0 ) {
  102     return( func$two(x)  );
  103   } else if ( x > $x0 ) {
  104     return( func$three(x) );
  105   } else {
  106     // do nothing if error.
  107   }
  108 }
  109 -->
  110 </SCRIPT>
  111 
  112 EOF
  113 TEXT(beginproblem());
  114 
  115 
  116 BEGIN_TEXT
  117 Below is an "oracle" function. An oracle function is a function presented interactively.
  118 When you type in an \(x\) value, and press the --f--\(>\) button and
  119 the value \(f(x)\) appears in the right hand window.  There are three lines, so you can easily calculate
  120 three different values of the function at one time.
  121 $BR
  122 $BCENTER
  123 END_TEXT
  124 
  125 # A warning that we are using javaScript
  126 TEXT(MODES(
  127 TeX => "",
  128 Latex2HTML => "\begin{rawhtml}
  129       <NOSCRIPT>$BBOLD This problem requires that Java Script be enabled $BR$EBOLD</NOSCRIPT> \end{rawhtml}
  130       ",
  131 HTML => "$PAR<NOSCRIPT> <B>This problem requires that Java Script be enabled </NOSCRIPT></B>$PAR"
  132 ));
  133 
  134 $javaScript2 = begintable(3) .
  135                MODES(HTML =>q{<TR>
  136           <TH>x</TH><TH>&nbsp;</TH><TH>f(x)</TH>
  137           <TR>},
  138           TeX => "x & \(\rightarrow\) & f(x)\\"
  139         ) .
  140         row(MODES(HTML => qq{<INPUT TYPE="text"   NAME="Input"  Value = "$x0" Size="16">}, TeX => '\fbox{Enter \(x\)}' ),
  141             MODES(HTML => qq{<INPUT TYPE="button" VALUE="---f-->"
  142                         OnClick="this.form.Output.value=func(this.form.Input.value);">}, TeX => '\(\rightarrow\)'    ),
  143                     MODES(HTML => qq{<INPUT TYPE="text"   NAME="Output"   Size="30">}, TeX => 'result: \(f(x)\)')
  144         ) .
  145         row(MODES(HTML => qq{<INPUT TYPE="text"   NAME="Input2"  Value = "$x0" Size="16">}, TeX => '\fbox{Enter \(x\)}' ),
  146             MODES(HTML => qq{<INPUT TYPE="button" VALUE="---f-->"
  147                         OnClick="this.form.Output2.value=func(this.form.Input2.value);">}, TeX => '\(\rightarrow\)'    ),
  148                     MODES(HTML => qq{<INPUT TYPE="text"   NAME="Output2"   Size="30">}, TeX => 'result: \(f(x)\)')
  149         ) .
  150         row(MODES(HTML => qq{<INPUT TYPE="text"   NAME="Input3"  Value = "$x0" Size="16">}, TeX => '\fbox{Enter \(x\)}' ),
  151             MODES(HTML => qq{<INPUT TYPE="button" VALUE="---f-->"
  152                         OnClick="this.form.Output3.value=func(this.form.Input3.value);">}, TeX => '\(\rightarrow\)'    ),
  153                     MODES(HTML => qq{<INPUT TYPE="text"   NAME="Output3"   Size="30">}, TeX => 'result: \(f(x)\)')
  154         ) . endtable();
  155 
  156 TEXT($javaScript2);
  157 
  158 
  159 BEGIN_TEXT
  160 $ECENTER
  161 $BR
  162 Determine the limits for the function \( f(x)\) at  \($x0\).
  163 $BR$BR
  164 \( \displaystyle \lim_{x\to $x0^{-} } f(x) \) = \{ans_rule(20)\}
  165 $BR $BR
  166 \( f($x0) \)   = \{ ans_rule(10) \}
  167 $BR $BR
  168 \( \displaystyle \lim_{x\to $x0^{+}  } f(x) \) = \{ ans_rule(20) \}
  169 $BR $BR
  170 Are all of these values the same? \{ pop_up_list(['?', 'Yes', 'No']) \}.
  171 If so then the function
  172 is $BBOLD continuous $EBOLD at \($x0\) $PAR
  173 
  174 Are the left and right limits the same at \($x0 \)?  \{  pop_up_list(['?', 'Yes', 'No']) \}.  If so then this
  175 function is almost continuous and could be made continuous by redefining one value of the function
  176 namely \( f($x0) \).
  177 END_TEXT
  178 
  179 $continuousQ = 'No';
  180 $continuousQ = 'Yes' if ($left_limit == $value and $value == $right_limit);
  181 $madeContinuousQ = 'No';
  182 $madeContinuousQ = 'Yes' if ($left_limit  == $right_limit);
  183 
  184 
  185 ANS(num_cmp([ $left_limit,$value,$right_limit ]),
  186  #We are allowing 1 percent error for the answer.
  187 strict_str_cmp($continuousQ),
  188 strict_str_cmp($madeContinuousQ));
  189 
  190 
  191 &ENDDOCUMENT;
  192 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9