public class PolynomialFunction extends Object implements UnivariateDifferentiableFunction, Serializable
Horner's Method is used to evaluate the function.
Modifier and Type | Class and Description |
---|---|
static class |
PolynomialFunction.Parametric
Dedicated parametric polynomial class.
|
Constructor and Description |
---|
PolynomialFunction(double[] c)
Construct a polynomial with the given coefficients.
|
Modifier and Type | Method and Description |
---|---|
PolynomialFunction |
add(PolynomialFunction p)
Add a polynomial to the instance.
|
int |
degree()
Returns the degree of the polynomial.
|
UnivariateFunction |
derivative()
Returns the derivative as a
UnivariateFunction . |
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() |
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.
|
DerivativeStructure |
value(DerivativeStructure t)
Simple mathematical function.
|
double |
value(double x)
Compute the value of the function for the given argument.
|
public PolynomialFunction(double[] c)
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
.NoDataException
- 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)
coefficients
- Coefficients of the polynomial to evaluate.argument
- Input value.NoDataException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.public DerivativeStructure value(DerivativeStructure t)
UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.
value
in interface UnivariateDifferentiableFunction
t
- function input valueNoDataException
- 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.protected static double[] differentiate(double[] coefficients)
coefficients
- Coefficients of the polynomial to differentiate.null
if coefficients has length 1.NoDataException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.public PolynomialFunction polynomialDerivative()
PolynomialFunction
.public UnivariateFunction derivative()
UnivariateFunction
.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 © 2019 CNES. All rights reserved.