Пример #1
0
 /**
  * Get the roots of this Polynomial
  * 
  * For Polynomials of degree less than or equal to 4, the exact value of any 
  * real roots (zeros) of the Polynomial are returned. For Polynomials of 
  * higher degrees, the roots are estimated using the Newton-Raphson method 
  * from the {@link http://pear.php.net/package/Math_Numerical_RootFinding/ 
  * Math_Numerical_RootFinding} package. Remember that these roots are 
  * *estimates* and for high-degree polynomials all of the roots may not be 
  * calculated and returned!
  * 
  * If you're calculating roots for a higher-degree Polynomial and want to 
  * provide the initial guesses for the roots, you can pass them in as an 
  * array parameter. 
  * 
  * If possible, this function will return integers instead of floats. 
  * 
  * @see Math_PolynomialOp::getRootsLinear(), Math_PolynomialOp::getRootsQuadratic(), Math_PolynomialOp::getRootsCubic(), Math_PolynomialOp::getRootsQuartic(), Math_PolynomialOp::getRootsHighDegree(), Math_Numerical_RootFinding
  * 
  * @access public
  * 
  * @param object $p
  * @param array $guesses
  * @return array An array of roots ( points where y = 0 )
  */
 function getRoots($p, $guesses = array())
 {
     if (!is_a($p, 'Math_Polynomial')) {
         $p = new Math_Polynomial($p);
     }
     if ($p->degree() == 0) {
         // Constant
         return array();
     } else {
         if ($p->degree() == 1) {
             // Linear
             return Math_PolynomialOp::getRootsLinear($p);
         } else {
             if ($p->degree() == 2) {
                 // Quadratic
                 return Math_PolynomialOp::getRootsQuadratic($p);
             } else {
                 if ($p->degree() == 3) {
                     // Cubic
                     return Math_PolynomialOp::getRootsCubic($p);
                 } else {
                     if ($p->degree() == 4) {
                         // Quartic
                         return Math_PolynomialOp::getRootsQuartic($p);
                     } else {
                         return Math_PolynomialOp::getRootsHighDegree($p, $guesses);
                     }
                 }
             }
         }
     }
 }