[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm

www www at source.lon-capa.org
Wed Sep 28 19:33:52 EDT 2011


www		Wed Sep 28 23:33:52 2011 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Allow for piece-wise defined functions if splines seamlessly connected
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.63 loncom/homework/functionplotresponse.pm:1.64
--- loncom/homework/functionplotresponse.pm:1.63	Fri May 27 23:00:58 2011
+++ loncom/homework/functionplotresponse.pm	Wed Sep 28 23:33:52 2011
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.63 2011/05/27 23:00:58 raeburn Exp $
+# $Id: functionplotresponse.pm,v 1.64 2011/09/28 23:33:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -751,7 +751,7 @@
 #
 
 sub populate_arrays {
-    my ($id,$xmin,$xmax)=@_;
+    my ($id,$xmin,$xmax,$ymin,$ymax)=@_;
     for (my $i=0; $i<=400; $i++) {
        $Apache::functionplotresponse::actualxval[$i]=undef;
        $Apache::functionplotresponse::func[$i]=undef;
@@ -779,12 +779,19 @@
                 my $xi=&array_index($xmin,$xmax,$xreal);
                 if ($xi<$xiold) { return 'no_func'; }
                 if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) {
-                   if (defined($Apache::functionplotresponse::func[$xi])) { return 'no_func'; }
                    $xiold=$xi;
                    $Apache::functionplotresponse::actualxval[$xi]=$xreal;
 # Function value
                    my $funcval=&cubic_hermite($t, at yparms);
+
+# Do we already have a value for this point, and is it different from the new one?
+                   if ((defined($Apache::functionplotresponse::func[$xi])) &&
+                       (abs($Apache::functionplotresponse::func[$xi]-$funcval)>($ymax-$ymin)/100.)) { 
+                       return 'no_func'; 
+                   }
+# Okay, remember the new point
                    $Apache::functionplotresponse::func[$xi]=$funcval;
+
                    if (defined($funcval)) {
                       if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) {
                          $Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi;
@@ -1169,7 +1176,7 @@
         $Apache::functionplotresponse::ruleslog='';
         $Apache::functionplotresponse::functionplotrulelabels{'start'}=400;
         $Apache::functionplotresponse::functionplotrulelabels{'end'}=0;
-        if (&populate_arrays($internalid,$xmin,$xmax) eq 'no_func') {
+        if (&populate_arrays($internalid,$xmin,$xmax,$ymin,$ymax) eq 'no_func') {
            $ad='NOT_FUNCTION';
         } else {
            &addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ".




More information about the LON-CAPA-cvs mailing list