Class RealPolynomialFunction1D

  • All Implemented Interfaces:
    DoubleFunction1D, DoubleUnaryOperator

    public class RealPolynomialFunction1D
    extends Object
    implements DoubleFunction1D
    Class representing a polynomial that has real coefficients and takes a real argument. The function is defined as: $$ \begin{align*} p(x) = a_0 + a_1 x + a_2 x^2 + \ldots + a_{n-1} x^{n-1} \end{align*} $$
    • Constructor Detail

      • RealPolynomialFunction1D

        public RealPolynomialFunction1D​(double... coefficients)
        Creates an instance. The array of coefficients for a polynomial $p(x) = a_0 + a_1 x + a_2 x^2 + ... + a_{n-1} x^{n-1}$ is $\\{a_0, a_1, a_2, ..., a_{n-1}\\}$.
        Parameters:
        coefficients - the array of coefficients, not null or empty
    • Method Detail

      • getCoefficients

        public double[] getCoefficients()
        Gets the coefficients of this polynomial.
        Returns:
        the coefficients of this polynomial
      • add

        public RealPolynomialFunction1D add​(double a)
        Adds a constant to the polynomial (equivalent to adding the value to the constant term of the polynomial). The result is also a polynomial.
        Specified by:
        add in interface DoubleFunction1D
        Parameters:
        a - the value to add
        Returns:
        $P+a$
      • derivative

        public RealPolynomialFunction1D derivative()
        Returns the derivative of this polynomial (also a polynomial), where $$ \begin{align*} P'(x) = a_1 + 2 a_2 x + 3 a_3 x^2 + 4 a_4 x^3 + \dots + n a_n x^{n-1} \end{align*} $$.
        Specified by:
        derivative in interface DoubleFunction1D
        Returns:
        the derivative polynomial
      • divide

        public RealPolynomialFunction1D divide​(double a)
        Divides the polynomial by a constant value (equivalent to dividing each coefficient by this value). The result is also a polynomial.
        Specified by:
        divide in interface DoubleFunction1D
        Parameters:
        a - the divisor
        Returns:
        the polynomial
      • multiply

        public RealPolynomialFunction1D multiply​(double a)
        Multiplies the polynomial by a constant value (equivalent to multiplying each coefficient by this value). The result is also a polynomial.
        Specified by:
        multiply in interface DoubleFunction1D
        Parameters:
        a - the multiplicator
        Returns:
        the polynomial
      • subtract

        public RealPolynomialFunction1D subtract​(double a)
        Subtracts a constant from the polynomial (equivalent to subtracting the value from the constant term of the polynomial). The result is also a polynomial.
        Specified by:
        subtract in interface DoubleFunction1D
        Parameters:
        a - the value to add
        Returns:
        $P-a$
      • toMonic

        public RealPolynomialFunction1D toMonic()
        Converts the polynomial to its monic form. If $$ \begin{align*} P(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 \dots + a_n x^n \end{align*} $$ then the monic form is $$ \begin{align*} P(x) = \lambda_0 + \lambda_1 x + \lambda_2 x^2 + \lambda_3 x^3 \dots + x^n \end{align*} $$ where $$ \begin{align*} \lambda_i = \frac{a_i}{a_n} \end{align*} $$
        Returns:
        the polynomial in monic form
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object