예제 #1
0
 /**
  * Get the end behavior of a Polynomial
  * 
  * The end behaviors are determined by the degree of the Polynomial and 
  * whether or not the coefficient is positive or negative. The values 
  * returned correspond to the MATH_POLYNOMIAL_QUADRANT_* constants for the 
  * cartesian coordinate system:
  * <pre>
  * 	Quad 2 | Quad 1
  *  ---------------
  * 	Quad 3 | Quad 4
  * </pre>
  * 
  * Returns an array containing two elements: 
  * <code>
  * 	$end_behaviors = Math_PolynomialOp::getEndBehavior('x^2 + 1');
  * 	print_r($end_behaviors);
  * 
  * 	// prints: 
  * 	Array
  * 	(
  * 		[0] => MATH_POLYNOMAIL_QUADRANT_2 // This is the left-end behavior
  * 		[1] => MATH_POLYNOMIAL_QUADRANT_1 // This is the right-end behavior
  * 	)
  * </code>
  * 
  * @see Math_PolynomialOp::getRightEndBehavior()
  * @see Math_PolynomialOp::getLeftEndBehavior()
  * 
  * @access public
  * @static
  * 
  * @param object $p
  * @return array
  */
 function getEndBehavior($p)
 {
     if (!is_a($p, 'Math_Polynomial')) {
         $p = new Math_Polynomial($p);
     }
     $term = $p->getTerm(0);
     if ($term->getCoefficient() > 0) {
         // Positive leading coefficient
         if ($p->degree() % 2) {
             // Odd degree
             return array(MATH_POLYNOMIAL_QUADRANT_3, MATH_POLYNOMIAL_QUADRANT_1);
         } else {
             // Even degree
             return array(MATH_POLYNOMIAL_QUADRANT_2, MATH_POLYNOMIAL_QUADRANT_1);
         }
     } else {
         // Negative leading coefficient
         if ($p->degree() % 2) {
             // Odd degree
             return array(MATH_POLYNOMIAL_QUADRANT_2, MATH_POLYNOMIAL_QUADRANT_4);
         } else {
             // Even degree
             return array(MATH_POLYNOMIAL_QUADRANT_3, MATH_POLYNOMIAL_QUADRANT_4);
         }
     }
 }