MathPHP\Functions\Polynomial::__construct PHP Метод

__construct() публичный Метод

When a polynomial is instantiated, set the coefficients and degree of that polynomial as its object parameters.
public __construct ( array $coefficients, $variable = "x" )
$coefficients array An array of coefficients in decreasing powers. Example: new Polynomial([1, 2, 3]) will create a polynomial that looks like x² + 2x + 3.
    public function __construct(array $coefficients, $variable = "x")
    {
        // Remove coefficients that are leading zeros
        for ($i = 0; $i < count($coefficients); $i++) {
            if ($coefficients[$i] != 0) {
                break;
            }
            unset($coefficients[$i]);
        }
        // If coefficients remain, re-index them. Otherwise return [0] for p(x) = 0
        $coefficients = $coefficients != [] ? array_values($coefficients) : [0];
        $this->degree = count($coefficients) - 1;
        $this->coefficients = $coefficients;
        $this->variable = $variable;
    }