Class RealPolynomialFunction1D
- java.lang.Object
-
- com.opengamma.strata.math.impl.function.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 Summary
Constructors Constructor Description RealPolynomialFunction1D(double... coefficients)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RealPolynomialFunction1D
add(double a)
Adds a constant to the polynomial (equivalent to adding the value to the constant term of the polynomial).DoubleFunction1D
add(DoubleFunction1D f)
Adds a function to the polynomial.double
applyAsDouble(double x)
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*} $$.RealPolynomialFunction1D
divide(double a)
Divides the polynomial by a constant value (equivalent to dividing each coefficient by this value).boolean
equals(Object obj)
double[]
getCoefficients()
Gets the coefficients of this polynomial.int
hashCode()
RealPolynomialFunction1D
multiply(double a)
Multiplies the polynomial by a constant value (equivalent to multiplying each coefficient by this value).DoubleFunction1D
multiply(DoubleFunction1D f)
Multiplies the polynomial by a function.RealPolynomialFunction1D
subtract(double a)
Subtracts a constant from the polynomial (equivalent to subtracting the value from the constant term of the polynomial).DoubleFunction1D
subtract(DoubleFunction1D f)
Subtracts a function from the polynomial.RealPolynomialFunction1D
toMonic()
Converts the polynomial to its monic form.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.opengamma.strata.math.impl.function.DoubleFunction1D
derivative, divide
-
Methods inherited from interface java.util.function.DoubleUnaryOperator
andThen, compose
-
-
-
-
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
-
applyAsDouble
public double applyAsDouble(double x)
- Specified by:
applyAsDouble
in interfaceDoubleUnaryOperator
-
getCoefficients
public double[] getCoefficients()
Gets the coefficients of this polynomial.- Returns:
- the coefficients of this polynomial
-
add
public DoubleFunction1D add(DoubleFunction1D f)
Adds a function to the polynomial. If the function is not aRealPolynomialFunction1D
then the addition takes place as inDoubleFunction1D
, otherwise the result will also be a polynomial.- Specified by:
add
in interfaceDoubleFunction1D
- Parameters:
f
- the function to add- Returns:
- $P+f$
-
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 interfaceDoubleFunction1D
- 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 interfaceDoubleFunction1D
- 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 interfaceDoubleFunction1D
- Parameters:
a
- the divisor- Returns:
- the polynomial
-
multiply
public DoubleFunction1D multiply(DoubleFunction1D f)
Multiplies the polynomial by a function. If the function is not aRealPolynomialFunction1D
then the multiplication takes place as inDoubleFunction1D
, otherwise the result will also be a polynomial.- Specified by:
multiply
in interfaceDoubleFunction1D
- Parameters:
f
- the function by which to multiply- Returns:
- $P \dot f$
-
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 interfaceDoubleFunction1D
- Parameters:
a
- the multiplicator- Returns:
- the polynomial
-
subtract
public DoubleFunction1D subtract(DoubleFunction1D f)
Subtracts a function from the polynomial.If the function is not a
RealPolynomialFunction1D
then the subtract takes place as inDoubleFunction1D
, otherwise the result will also be a polynomial.- Specified by:
subtract
in interfaceDoubleFunction1D
- Parameters:
f
- the function to subtract- Returns:
- $P-f$
-
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 interfaceDoubleFunction1D
- 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
-
-