Class FieldPolynomialFunction<T extends CalculusFieldElement<T>>

java.lang.Object
org.hipparchus.analysis.polynomials.FieldPolynomialFunction<T>
Type Parameters:
T - the type of the field elements
All Implemented Interfaces:
CalculusFieldUnivariateFunction<T>
Direct Known Subclasses:
SmoothStepFactory.FieldSmoothStepFunction

public class FieldPolynomialFunction<T extends CalculusFieldElement<T>> extends Object implements CalculusFieldUnivariateFunction<T>
Immutable representation of a real polynomial function with real coefficients.

Horner's Method is used to evaluate the function.

Since:
1.5
• Constructor Summary

Constructors
Constructor
Description
FieldPolynomialFunction(T[] c)
Construct a polynomial with the given coefficients.
• Method Summary

Modifier and Type
Method
Description
FieldPolynomialFunction<T>
add(FieldPolynomialFunction<T> p)
Add a polynomial to the instance.
FieldPolynomialFunction<T>
antiDerivative()
Returns an anti-derivative of this polynomial, with 0 constant term.
int
degree()
Returns the degree of the polynomial.
protected static <T extends CalculusFieldElement<T>>T[]
differentiate(T[] coefficients)
Returns the coefficients of the derivative of the polynomial with the given coefficients.
protected static <T extends CalculusFieldElement<T>>T
evaluate(T[] coefficients, T argument)
Uses Horner's Method to evaluate the polynomial with the given coefficients at the argument.
T[]
getCoefficients()
Returns a copy of the coefficients array.
Field<T>
getField()
Get the Field to which the instance belongs.
T
integrate(double lower, double upper)
Returns the definite integral of this polymomial over the given interval.
T
integrate(T lower, T upper)
Returns the definite integral of this polymomial over the given interval.
FieldPolynomialFunction<T>
multiply(FieldPolynomialFunction<T> p)
Multiply the instance by a polynomial.
FieldPolynomialFunction<T>
negate()
Negate the instance.
FieldPolynomialFunction<T>
polynomialDerivative()
Returns the derivative as a FieldPolynomialFunction.
FieldPolynomialFunction<T>
subtract(FieldPolynomialFunction<T> p)
Subtract a polynomial from the instance.
T
value(double x)
Compute the value of the function for the given argument.
T
value(T x)
Compute the value of the function for the given argument.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Constructor Details

• FieldPolynomialFunction

public FieldPolynomialFunction(T[] c) throws
Construct a polynomial with the given coefficients. The first element of the coefficients array is the constant term. Higher degree coefficients follow in sequence. The degree of the resulting polynomial is the index of the last non-null element of the array, or 0 if all elements are null.

The constructor makes a copy of the input array and assigns the copy to the coefficients property.

Parameters:
c - Polynomial coefficients.
Throws:
NullArgumentException - if c is null.
MathIllegalArgumentException - if c is empty.
• Method Details

• value

public T value(double x)
Compute the value of the function for the given argument.

The value returned is

coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]

Parameters:
x - Argument for which the function value should be computed.
Returns:
the value of the polynomial at the given point.
• value

public T value(T x)
Compute the value of the function for the given argument.

The value returned is

coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]

Specified by:
value in interface CalculusFieldUnivariateFunction<T extends CalculusFieldElement<T>>
Parameters:
x - Argument for which the function value should be computed.
Returns:
the value of the polynomial at the given point.
• getField

public Field<T> getField()
Get the Field to which the instance belongs.
Returns:
Field to which the instance belongs
• degree

public int degree()
Returns the degree of the polynomial.
Returns:
the degree of the polynomial.
• getCoefficients

public T[] getCoefficients()
Returns a copy of the coefficients array.

Changes made to the returned copy will not affect the coefficients of the polynomial.

Returns:
a fresh copy of the coefficients array.
• evaluate

protected static <T extends CalculusFieldElement<T>> T evaluate(T[] coefficients, T argument) throws
Uses Horner's Method to evaluate the polynomial with the given coefficients at the argument.
Type Parameters:
T - the type of the field elements
Parameters:
coefficients - Coefficients of the polynomial to evaluate.
argument - Input value.
Returns:
the value of the polynomial.
Throws:
MathIllegalArgumentException - if coefficients is empty.
NullArgumentException - if coefficients is null.

Add a polynomial to the instance.
Parameters:
p - Polynomial to add.
Returns:
a new polynomial which is the sum of the instance and p.
• subtract

public  subtract(FieldPolynomialFunction<T> p)
Subtract a polynomial from the instance.
Parameters:
p - Polynomial to subtract.
Returns:
a new polynomial which is the instance minus p.
• negate

public  negate()
Negate the instance.
Returns:
a new polynomial with all coefficients negated
• multiply

public  multiply(FieldPolynomialFunction<T> p)
Multiply the instance by a polynomial.
Parameters:
p - Polynomial to multiply by.
Returns:
a new polynomial equal to this times p
• differentiate

protected static <T extends CalculusFieldElement<T>> T[] differentiate(T[] coefficients) throws
Returns the coefficients of the derivative of the polynomial with the given coefficients.
Type Parameters:
T - the type of the field elements
Parameters:
coefficients - Coefficients of the polynomial to differentiate.
Returns:
the coefficients of the derivative or null if coefficients has length 1.
Throws:
MathIllegalArgumentException - if coefficients is empty.
NullArgumentException - if coefficients is null.
• antiDerivative

public  antiDerivative()
Returns an anti-derivative of this polynomial, with 0 constant term.
Returns:
a polynomial whose derivative has the same coefficients as this polynomial
• integrate

public T integrate(double lower, double upper)
Returns the definite integral of this polymomial over the given interval.

[lower, upper] must describe a finite interval (neither can be infinite and lower must be less than or equal to upper).

Parameters:
lower - lower bound for the integration
upper - upper bound for the integration
Returns:
the integral of this polymomial over the given interval
Throws:
MathIllegalArgumentException - if the bounds do not describe a finite interval
• integrate

public T integrate(T lower, T upper)
Returns the definite integral of this polymomial over the given interval.

[lower, upper] must describe a finite interval (neither can be infinite and lower must be less than or equal to upper).

Parameters:
lower - lower bound for the integration
upper - upper bound for the integration
Returns:
the integral of this polymomial over the given interval
Throws:
MathIllegalArgumentException - if the bounds do not describe a finite interval
• polynomialDerivative

public  polynomialDerivative()
Returns the derivative as a FieldPolynomialFunction.
Returns:
the derivative polynomial.