Class Polynomial

    • Field Detail

      • ZERO

        public static final Polynomial ZERO
        a polynomial representing 0
      • ONE

        public static final Polynomial ONE
        a polynomial representing 1
    • Constructor Detail

      • Polynomial

        public Polynomial​(double... coefficients)
        Construct a polynomial from an array of coefficients. The first/0-th entry corresponds to the xn term. The last/n-th entry corresponds to the constant term. The degree of the polynomial is n, the array length minus 1.

        For example,

        new Polynomial(1, -2, 3, 2)
        creates an instance of Polynomial representing x3 - 2x2 + 3x + 2.
        Parameters:
        coefficients - the polynomial coefficients
      • Polynomial

        public Polynomial​(Polynomial that)
        Copy constructor.
        Parameters:
        that - a polynomial
    • Method Detail

      • degree

        public int degree()
        Get the degree of this polynomial. It is equal to the largest exponent of the variable. For example, x4 + 1 has a degree of 4.
        Returns:
        the polynomial degree
      • getCoefficients

        public double[] getCoefficients()
        Get a copy of the polynomial coefficients. In general, coefficients[i] is the coefficient of xn-i, where n is the polynomial degree. Specifically, coefficients[0] is the leading coefficient and coefficients[n] the constant term.
        Returns:
        a copy of the polynomial coefficients
      • getCoefficient

        public double getCoefficient​(int i)
        Get an-i, the coefficient of xn-i.
        Parameters:
        i - the i-th coefficient in this polynomial, counting from 0
        Returns:
        an-i
        See Also:
        getCoefficients()
      • getNormalization

        public Polynomial getNormalization()
        Get the normalized version of this polynomial so the leading coefficient is 1.
        Returns:
        a scaled version of the polynomial that has a leading coefficient 1
      • evaluate

        public Complex evaluate​(Number x)
        Evaluate this polynomial at x.
        Parameters:
        x - the argument
        Returns:
        p(x)
      • evaluate

        public double evaluate​(double x)
        Evaluate this polynomial at x.
        Specified by:
        evaluate in interface UnivariateRealFunction
        Parameters:
        x - the argument
        Returns:
        p(x)
      • evaluate

        public Complex evaluate​(Complex z)
        Evaluate this polynomial at x.
        Parameters:
        z - the argument
        Returns:
        p(x)
      • minus

        public Polynomial minus​(Polynomial that)
        Description copied from interface: AbelianGroup
        - : G × G → G

        The operation "-" is not in the definition of of an additive group but can be deduced. This function is provided for convenience purpose. It is equivalent to

        this.add(that.opposite())
        .
        Specified by:
        minus in interface AbelianGroup<Polynomial>
        Parameters:
        that - the object to be subtracted (subtrahend)
        Returns:
        this - that
      • ZERO

        public Polynomial ZERO()
        Description copied from interface: AbelianGroup
        The additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.
        Specified by:
        ZERO in interface AbelianGroup<Polynomial>
        Returns:
        0, the additive identity
      • ONE

        public Polynomial ONE()
        Description copied from interface: Monoid
        The multiplicative element 1 in the group such that for any elements a in the group, the equation 1 × a = a × 1 = a holds.
        Specified by:
        ONE in interface Monoid<Polynomial>
        Returns:
        1
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object