default
[ class tree: default ] [ index: default ] [ all elements ]

Source for file LMQuadTest.php

Documentation is available at LMQuadTest.php

  1. <?php
  2. /**
  3. * quadratic (p-o)'S'S(p-o)
  4. * solve for o, S
  5. * S is a single scale factor
  6. */
  7. class LMQuadTest {
  8.  
  9.    /**
  10.    * @param array[] $x 
  11.    * @param array[] $a 
  12.    */
  13.    function val($x$a{
  14.  
  15.      if (count($a!= 3die ("Wrong number of elements in array a");
  16.      if (count($x!= 2die ("Wrong number of elements in array x");
  17.  
  18.      $ox $a[0];
  19.      $oy $a[1];
  20.      $s  $a[2];
  21.  
  22.      $sdx $s*($x[0$ox);
  23.      $sdy $s*($x[1$oy);
  24.  
  25.      return $sdx*$sdx $sdy*$sdy;
  26.  
  27.    }
  28.  
  29.  
  30.    /**   
  31.    * z = (p-o)'S'S(p-o)
  32.    * dz/dp = 2S'S(p-o)
  33.    *
  34.    * z = (s*(px-ox))^2 + (s*(py-oy))^2
  35.    * dz/dox = -2(s*(px-ox))*s
  36.    * dz/ds = 2*s*[(px-ox)^2 + (py-oy)^2]
  37.    *
  38.    * z = (s*dx)^2 + (s*dy)^2
  39.    * dz/ds = 2(s*dx)*dx + 2(s*dy)*dy
  40.    *
  41.    * @param array[] $x 
  42.    * @param array[] $a 
  43.    * @param int $a_k 
  44.    * @param array[] $a 
  45.    */
  46.    function grad(double[xdouble[aint a_k{
  47.      
  48.      if (count($a!= 3die ("Wrong number of elements in array a");
  49.      if (count($x!= 2die ("Wrong number of elements in array x");
  50.      if ($a_k 3die ("a_k=".$a_k;);
  51.  
  52.      $ox $a[0];
  53.      $oy $a[1];
  54.      $s  $a[2];
  55.  
  56.      $dx ($x[0$ox);
  57.      $dy ($x[1$oy);
  58.  
  59.      if ($a_k == 0)    
  60.       return -2.*$s*$s*$dx;
  61.      elseif ($a_k == 1)
  62.       return -2.*$s*$s*$dy;
  63.      else
  64.       return 2.*$s*($dx*$dx $dy*$dy);
  65.    
  66.  
  67.  
  68.    /**
  69.    * @return array[] $a
  70.    */
  71.    function initial({
  72.      $a[00.05;
  73.      $a[10.1;
  74.      $a[21.0;
  75.      return $a;
  76.    
  77.  
  78.  
  79.    /**
  80.    * @return Object[] $a
  81.    */
  82.    function testdata({
  83.      
  84.      $npts 25;
  85.  
  86.      $a[00.;
  87.      $a[10.;
  88.      $a[20.9;
  89.  
  90.      $i 0;
  91.      
  92.      for($r = -2$r <= 2$r++ {
  93.       for($c = -2$c <= 2$c++ {
  94.         $x[$i][0$c;
  95.         $x[$i][1$r;
  96.         $y[$i$this->val($x[$i]$a);
  97.         print("Quad ".$c.",".$r." -> ".$y[$i]."<br />");
  98.         $s[$i1.;
  99.         $i++;
  100.       }
  101.      }
  102.      print("quad x= ")
  103.      
  104.      $qx new Matrix($x);
  105.      $qx->print(102);
  106.  
  107.      print("quad y= ");
  108.      $qy new Matrix($y$npts)
  109.      $qy->print(102);      
  110.  
  111.      $o[0$x;
  112.      $o[1$a;
  113.      $o[2$y;
  114.      $o[3$s;
  115.      
  116.      return $o;
  117.    
  118.    
  119.  
  120.  }

Documentation generated on Mon, 05 Jan 2009 20:38:01 +0100 by phpDocumentor 1.4.1