Class for operations on Math_Polynomial objects
Mathematical operations on Polynomial objects. All class methods are static methods and take as parameters either a Polynomial object or a string respresentation of a Polynomial in the form of: ax^n + bx^(n-1) + cx^(n-2) + ... yx + z
Divide one Polynomial by another, returning the result
Divide the first polynomial by another polynomial object or a string represention of another polynomial. Optionally, you can pass another Polynomial object by reference to store the remainder of the division operator.
$a = new Polynomial("4x^2 + 2x");
$b = new Polynomial("2x");
$remainder = new Polynomial();
$result = PolynomialOp::div($a, $b, $remainder);
print("A divided by B is: " . $result->toString() . " with a remainder of " . $remainder->toString() . "\n");
Returns the nth derivative of the Polynomial. Derivatives are commonly used in calculus as they represent slopes or acceleration. To get the first derivative, the second parameter should be a 1. For the second derivative parameter should be a two, etc. etc.
Return: polynomial object representing the nth derivative
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:
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 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.
Estimate and return the roots of a high-degree Polynomial ( degree 5 or greater )
This function uses Newton's method using the Math_Numerical_RootFinding PEAR package to estimate the real roots of high-degree Polynomials. If you already have estimates of where the roots might be, you can pass in an array of guesses. Otherwise, the method will try to calculate some good initial guesses for you.
You must have the Math_Numerical_RootFinding package installed for this method to work!