Пример #1
0
 /**
  * Find and return an array of the minimums of the Polynomial
  * 
  * By default the method returns all minimums, if you want the minimums 
  * within an interval, pass in the $x_min and $x_max parameters. 
  * 
  * @access public
  * 
  * @see Math_PolynomialOp::getLocalMaximums()
  * 
  * @param object $p
  * @param float $x_min
  * @param float $x_max
  * @return array
  */
 function getLocalMinimums($p, $x_min = null, $x_max = null)
 {
     if (!is_a($p, 'Math_Polynomial')) {
         $p = new Math_Polynomial($p);
     }
     $mins = array();
     $der = Math_PolynomialOp::getDerivative($p);
     foreach (Math_PolynomialOp::getRoots($der) as $critical) {
         if (Math_PolynomialOp::evaluate($der, $critical - 0.1) < 0 && Math_PolynomialOp::evaluate($der, $critical + 0.1) > 0) {
             // Check if its a min.
             $mins[] = $critical;
         }
     }
     if ($x_min && $x_max) {
         foreach ($mins as $key => $min) {
             if ($min < $x_min || $min > $x_max) {
                 unset($mins[$key]);
             }
         }
     }
     return $mins;
 }
Пример #2
0
 function testGetRootsQuadratic()
 {
     $p = new Math_Polynomial('2x^2 + 7x - 4');
     $roots = Math_PolynomialOp::getRoots($p);
     $this->assertEquals(array(0.5, -4), $roots);
 }