[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm /html/adm/help/tex Function_Plot_Response_Evaluation_Rule.tex /xml lonxml.pm

www www at source.lon-capa.org
Wed Oct 12 21:54:22 EDT 2011


www		Thu Oct 13 01:54:22 2011 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
    /loncom/html/adm/help/tex	
                             	Function_Plot_Response_Evaluation_Rule.tex 
    /loncom/xml	lonxml.pm 
  Log:
  Values in functionplotresponse rules can be evaluated
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.64 loncom/homework/functionplotresponse.pm:1.65
--- loncom/homework/functionplotresponse.pm:1.64	Wed Sep 28 23:33:52 2011
+++ loncom/homework/functionplotresponse.pm	Thu Oct 13 01:54:12 2011
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.64 2011/09/28 23:33:52 www Exp $
+# $Id: functionplotresponse.pm,v 1.65 2011/10/13 01:54:12 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,6 +31,7 @@
 use Apache::response();
 use Apache::lonlocal;
 use Apache::lonnet;
+use Apache::run;
  
 BEGIN {
   &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
@@ -563,7 +564,7 @@
                                    ['lt','less than'],
                                    ['le','less than or equal']],$token).
              $result.= &Apache::edit::select_or_text_arg('Value:','value',
-                                               [['undef','not defined']],$token,'8').
+                                               [['undef','not defined']],$token,'30').
              &Apache::edit::text_arg('Percent error:','percenterror',
                                      $token,'8').
              &Apache::edit::end_row();
@@ -979,15 +980,49 @@
    my ($i,$xmin,$xmax)=@_;
    return $xmin+$i/400.*($xmax-$xmin);
 }
+
+sub fpr_f {
+   my ($arg)=@_;
+   return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin,
+                                                           $Apache::functionplotresponse::fpr_xmax,
+                                                           $arg)];
+}
+
+sub fpr_dfdx {
+   my ($arg)=@_;
+   return $Apache::functionplotresponse::dfuncdx[&array_index($Apache::functionplotresponse::fpr_xmin,
+                                                              $Apache::functionplotresponse::fpr_xmax,
+                                                              $arg)];
+}
+
+sub fpr_d2fdx2 {
+   my ($arg)=@_;
+   return $Apache::functionplotresponse::d2funcdx2[&array_index($Apache::functionplotresponse::fpr_xmin,
+                                                                $Apache::functionplotresponse::fpr_xmax,
+                                                                $arg)];
+}
  
 sub functionplotrulecheck {
-   my ($rule,$xmin,$xmax,$ymin,$ymax)=@_;
+   my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
 
    my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent)
       =split(/\:/,$rule);
    $percent=($percent>0?$percent:5);
    &addlog("=================");
    &addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value");
+#
+# Evaluate the value
+#
+   if ($value=~/\D/) {
+      $Apache::functionplotresponse::fpr_xmin=$xmin;
+      $Apache::functionplotresponse::fpr_xmax=$xmax;
+      $value=&Apache::run::run($value,$safeeval);
+      &addlog("Value evaluated to $value");
+   }
+
+#
+# Minimum and maximum lengths of the interval
+#
    if ((defined($minimumlength)) || (defined($maximumlength))) {
       &addlog("Minimumlength $minimumlength Maximumlength $maximumlength");
    }
@@ -1186,7 +1221,7 @@
 
 # We have a function that we can actually grade, go through the spline rules.
            foreach my $rule (@Apache::functionplotresponse::functionplotrules) {
-              unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax)) {
+              unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)) {
                  $ad='INCORRECT';
                  last;
               }
Index: loncom/html/adm/help/tex/Function_Plot_Response_Evaluation_Rule.tex
diff -u loncom/html/adm/help/tex/Function_Plot_Response_Evaluation_Rule.tex:1.1 loncom/html/adm/help/tex/Function_Plot_Response_Evaluation_Rule.tex:1.2
--- loncom/html/adm/help/tex/Function_Plot_Response_Evaluation_Rule.tex:1.1	Fri Jan 14 01:56:37 2011
+++ loncom/html/adm/help/tex/Function_Plot_Response_Evaluation_Rule.tex	Thu Oct 13 01:54:17 2011
@@ -16,7 +16,7 @@
 
 ``Relationship''  - The heart of the rule.  This choice determines whether the chosen 'Function' is greater than, less than, equal to, etc. a certain 'value'.
 
-``Value'' - See above.  It is also possible to choose 'not defined', in the event the answer should not have a value for the given domain.
+``Value'' - See above.  It is also possible to choose 'not defined', in the event the answer should not have a value for the given domain. Within the value argument, the function itself can be evaluated using \&fpr\_f(), its derivative using \&fpr\_dfdx, and its second derivative using \&fpr\_d2fdx2().
 
 ``Percent error'' - This allows for a margin of error in the y-direction.  For instance, if the rule requires that the derivative be equal to 5, the server will accept values close enough to 5 that are within the percent error defined here. Note: Choosing 10\% would not mean that the answer is correct as long as it is within the range 4.5-5.5.  Instead, the percent corresponds to the total size of the graph.  For the function itself, the 'percent error' is multiplied by the ymax-ymin; for the first derivative, it's multiplied by (ymax-ymin)/(xmax-xmin); for the second derivative, it's multiplied by (ymax-ymin)/(xmax-xmin)^2; and for the integral, it's multiplied by (ymax-ymin)*(xmax-xmin).
 
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.519 loncom/xml/lonxml.pm:1.520
--- loncom/xml/lonxml.pm:1.519	Fri May 27 19:07:25 2011
+++ loncom/xml/lonxml.pm	Thu Oct 13 01:54:21 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.519 2011/05/27 19:07:25 raeburn Exp $
+# $Id: lonxml.pm,v 1.520 2011/10/13 01:54:21 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -112,6 +112,7 @@
 use Apache::lonr();
 use Apache::lonlocal;
 use Apache::lonhtmlcommon();
+use Apache::functionplotresponse();
 
 #====================================   Main subroutine: xmlparse  
 
@@ -787,6 +788,10 @@
   $safehole->wrap(\&Apache::lonnet::logthis,$safeeval,'&LONCAPA_INTERNAL_LOGTHIS');
   $safehole->wrap(\&Apache::inputtags::finalizeawards,$safeeval,'&LONCAPA_INTERNAL_FINALIZEAWARDS');
   $safehole->wrap(\&Apache::caparesponse::get_sigrange,$safeeval,'&LONCAPA_INTERNAL_get_sigrange');
+  $safehole->wrap(\&Apache::functionplotresponse::fpr_f,$safeeval,'&fpr_f');
+  $safehole->wrap(\&Apache::functionplotresponse::fpr_dfdx,$safeeval,'&fpr_dfdx');
+  $safehole->wrap(\&Apache::functionplotresponse::fpr_d2fdx2,$safeeval,'&fpr_d2fdx2');
+
 #  use Data::Dumper;
 #  $safehole->wrap(\&Data::Dumper::Dumper,$safeeval,'&LONCAPA_INTERNAL_Dumper');
 #need to inspect this class of ops




More information about the LON-CAPA-cvs mailing list