Serializable
, UnivariateDifferentiableFunction
, FieldUnivariateFunction
, UnivariateFunction
public class PolynomialFunction extends Object implements UnivariateDifferentiableFunction, FieldUnivariateFunction, Serializable
Horner's Method is used to evaluate the function.
Modifier and Type | Class | Description |
---|---|---|
static class |
PolynomialFunction.Parametric |
Dedicated parametric polynomial class.
|
Constructor | Description |
---|---|
PolynomialFunction(double[] c) |
Construct a polynomial with the given coefficients.
|
Modifier and Type | Method | Description |
---|---|---|
PolynomialFunction |
add(PolynomialFunction p) |
Add a polynomial to the instance.
|
PolynomialFunction |
antiDerivative() |
Returns an anti-derivative of this polynomial, with 0 constant term.
|
int |
degree() |
Returns the degree of the polynomial.
|
protected static double[] |
differentiate(double[] coefficients) |
Returns the coefficients of the derivative of the polynomial with the given coefficients.
|
boolean |
equals(Object obj) |
|
protected static double |
evaluate(double[] coefficients,
double argument) |
Uses Horner's Method to evaluate the polynomial with the given coefficients at
the argument.
|
double[] |
getCoefficients() |
Returns a copy of the coefficients array.
|
int |
hashCode() |
|
double |
integrate(double lower,
double upper) |
Returns the definite integral of this polymomial over the given interval.
|
PolynomialFunction |
multiply(PolynomialFunction p) |
Multiply the instance by a polynomial.
|
PolynomialFunction |
negate() |
Negate the instance.
|
PolynomialFunction |
polynomialDerivative() |
Returns the derivative as a
PolynomialFunction . |
PolynomialFunction |
subtract(PolynomialFunction p) |
Subtract a polynomial from the instance.
|
String |
toString() |
Returns a string representation of the polynomial.
|
double |
value(double x) |
Compute the value of the function for the given argument.
|
DerivativeStructure |
value(DerivativeStructure t) |
Simple mathematical function.
|
<T extends RealFieldElement<T>> |
value(T t) |
Compute the value of the function.
|
toRealFieldUnivariateFunction
public PolynomialFunction(double[] c) throws MathIllegalArgumentException, NullArgumentException
The constructor makes a copy of the input array and assigns the copy to the coefficients property.
c
- Polynomial coefficients.NullArgumentException
- if c
is null
.MathIllegalArgumentException
- if c
is empty.public double value(double x)
The value returned is
coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]
value
in interface UnivariateFunction
x
- Argument for which the function value should be computed.UnivariateFunction.value(double)
public int degree()
public double[] getCoefficients()
Changes made to the returned copy will not affect the coefficients of the polynomial.
protected static double evaluate(double[] coefficients, double argument) throws MathIllegalArgumentException, NullArgumentException
coefficients
- Coefficients of the polynomial to evaluate.argument
- Input value.MathIllegalArgumentException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.public DerivativeStructure value(DerivativeStructure t) throws MathIllegalArgumentException, NullArgumentException
UnivariateDifferentiableFunction
classes compute both the
value and the first derivative of the function.
value
in interface UnivariateDifferentiableFunction
t
- function input valueMathIllegalArgumentException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.public <T extends RealFieldElement<T>> T value(T t) throws MathIllegalArgumentException, NullArgumentException
value
in interface FieldUnivariateFunction
T
- the type of the field elementst
- Point at which the function value should be computed.MathIllegalArgumentException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.public PolynomialFunction add(PolynomialFunction p)
p
- Polynomial to add.p
.public PolynomialFunction subtract(PolynomialFunction p)
p
- Polynomial to subtract.p
.public PolynomialFunction negate()
public PolynomialFunction multiply(PolynomialFunction p)
p
- Polynomial to multiply by.p
protected static double[] differentiate(double[] coefficients) throws MathIllegalArgumentException, NullArgumentException
coefficients
- Coefficients of the polynomial to differentiate.null
if coefficients has length 1.MathIllegalArgumentException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.public PolynomialFunction antiDerivative()
public double integrate(double lower, double upper)
[lower, upper] must describe a finite interval (neither can be infinite and lower must be less than or equal to upper).
lower
- lower bound for the integrationupper
- upper bound for the integrationMathIllegalArgumentException
- if the bounds do not describe a finite intervalpublic PolynomialFunction polynomialDerivative()
PolynomialFunction
.public String toString()
The representation is user oriented. Terms are displayed lowest
degrees first. The multiplications signs, coefficients equals to
one and null terms are not displayed (except if the polynomial is 0,
in which case the 0 constant term is displayed). Addition of terms
with negative coefficients are replaced by subtraction of terms
with positive coefficients except for the first displayed term
(i.e. we display -3
for a constant negative polynomial,
but 1 - 3 x + x^2
if the negative coefficient is not
the first one displayed).
Copyright © 2016–2018 Hipparchus.org. All rights reserved.