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

www www@source.lon-capa.org
Sun, 07 Nov 2010 13:15:28 -0000


www		Sun Nov  7 13:15:28 2010 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  (Hopefully) correct application of chain rule for second derivative
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.27 loncom/homework/functionplotresponse.pm:1.28
--- loncom/homework/functionplotresponse.pm:1.27	Sun Nov  7 12:28:28 2010
+++ loncom/homework/functionplotresponse.pm	Sun Nov  7 13:15:28 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.27 2010/11/07 12:28:28 www Exp $
+# $Id: functionplotresponse.pm,v 1.28 2010/11/07 13:15:28 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -591,15 +591,19 @@
                    $xiold=$xi;
 # Function value
                    $Apache::functionplotresponse::func[$xi]=&cubic_hermite($t,@yparms);
+# Chain rule
 # dy/dx=dy/dt/(dx/dt)
                    my $dxdt=&ddt_cubic_hermite($t,@xparms);
                    if ($dxdt) {
                       $Apache::functionplotresponse::dfuncdx[$xi]=&ddt_cubic_hermite($t,@yparms)/$dxdt;
                    }
-# d^2y/dx^2
+# Faa di Bruno
+# d^2y/dx^2=(d^2y/dt^2)/(dx/dt)^2+(dy/dt)/(d^2x/dt^2)
                    my $d2xdt2=&d2dt2_cubic_hermite($t,@xparms);
-                   if ($d2xdt2) {
-                      $Apache::functionplotresponse::d2funcdx2[$xi]=&d2dt2_cubic_hermite($t,@yparms)/$d2xdt2;
+                   if (($dxdt) && ($d2xdt2)) {
+                      $Apache::functionplotresponse::d2funcdx2[$xi]=
+                         &d2dt2_cubic_hermite($t,@yparms)/($dxdt*$dxdt)
+                        +&ddt_cubic_hermite($t,@yparms)/$d2xdt2;
                    }
                 }
             }