Метод |
Описание |
|
__construct ( array $coefficients, $variable = "x" ) |
When a polynomial is instantiated, set the coefficients and degree of
that polynomial as its object parameters. |
|
__invoke ( number $x₀ ) : float |
When a polynomial is being evaluated at a point x₀, build a callback
function and return the value of the callback function at x₀
Example: $polynomial = new Polynomial([1, -8, 12, 3]);
echo $polynomial(4);
prints -13 |
|
__toString ( ) : string |
When a polynomial is to be treated as a string, return it in a readable format. |
|
add ( Polynomial $polynomial ) : Polynomial |
Return a new polynomial that is the sum of the current polynomial and an
input polynomial
Example: $polynomial = new Polynomial([3, -16, 12]); // 3x² - 16x + 12
$integral = $polynomial->integrate(); // x³ - 8x² + 12x
$sum = $polynomial->add($integral); // x³ - 5x² - 4x + 12 |
|
differentiate ( ) : Polynomial |
Calculate the derivative of a polynomial and return it as a new polynomial
Example: $polynomial = new Polynomial([1, -8, 12, 3]); // x³ - 8x² + 12x + 3
$derivative = $polynomial->differentiate(); // 3x² - 16x + 12 |
|
getCoefficients ( ) : array |
Getter method for the coefficients of a polynomial |
|
getDegree ( ) : integer |
Getter method for the degree of a polynomial |
|
getVariable ( ) : string |
Getter method for the dependent variable of a polynomial |
|
integrate ( ) : Polynomial |
Calculate the indefinite integral of a polynomial and return it as a new polynomial
Example: $polynomial = new Polynomial([3, -16, 12]); // 3x² - 16x + 12
$integral = $polynomial->integrate(); // x³ - 8x² + 12x |
|
multiply ( Polynomial $polynomial ) : Polynomial |
Return a new polynomial that is the product of the current polynomial and an
input polynomial
Example: $polynomial = new Polynomial([2, -16]); // 2x - 16
$integral = $polynomial->integrate(); // x² - 16x
$product = $polynomial->multiply($integral); // 2x³ - 48x² + 256x |
|
setVariable ( string $variable ) |
Setter method for the dependent variable of a polynomial |
|