Top Description Inners Fields Constructors Methods
org.apache.commons.math3.analysis.polynomials

public Class PolynomialFunction

extends Object
implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.analysis.DifferentiableUnivariateFunction, org.apache.commons.math3.analysis.UnivariateFunction, org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction
Imports
java.io.Serializable, java.util.Arrays, org.apache.commons.math3.analysis.DifferentiableUnivariateFunction, .ParametricUnivariateFunction, .UnivariateFunction, org.apache.commons.math3.analysis.differentiation.DerivativeStructure, .UnivariateDifferentiableFunction, org.apache.commons.math3.exception.NoDataException, .NullArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.FastMath, .MathUtils

Deprecated

as a consequence of DifferentiableUnivariateFunction being deprecated. See corresponding docs for further information.

Immutable representation of a real polynomial function with real coefficients.

Horner's Method is used to evaluate the function.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PolynomialFunction.Parametric

Dedicated parametric polynomial class.

Field Summary

Modifier and TypeField and Description
private final double[]
coefficients

The coefficients of the polynomial, ordered by degree -- i.e., coefficients[0] is the constant term and coefficients[n] is the coefficient of x^n where n is the degree of the polynomial.

private static final long
serialVersionUID

Serialization identifier

Constructor Summary

AccessConstructor and Description
public
PolynomialFunction(double[]
Polynomial coefficients.
c
)

Construct a polynomial with the given coefficients.

Method Summary

Modifier and TypeMethod and Description
public PolynomialFunction

Returns:

a new polynomial which is the sum of the instance and p.
add
(final PolynomialFunction
Polynomial to add.
p
)
Deprecated as a consequence of PolynomialFunction being deprecated.

Add a polynomial to the instance.

public int

Returns:

the degree of the polynomial.
degree
()

Returns the degree of the polynomial.

public UnivariateFunction

Returns:

the derivative function.
derivative
()

Implements org.apache.commons.math3.analysis.DifferentiableUnivariateFunction.derivative.

Returns the derivative as a UnivariateFunction.

protected static double[]

Returns:

the coefficients of the derivative or null if coefficients has length 1.
differentiate
(double[]
Coefficients of the polynomial to differentiate.
coefficients
)

Returns the coefficients of the derivative of the polynomial with the given coefficients.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

protected static double

Returns:

the value of the polynomial.
evaluate
(double[]
Coefficients of the polynomial to evaluate.
coefficients
,
double
Input value.
argument
)

Uses Horner's Method to evaluate the polynomial with the given coefficients at the argument.

public double[]

Returns:

a fresh copy of the coefficients array.
getCoefficients
()

Returns a copy of the coefficients array.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public PolynomialFunction

Returns:

a new polynomial equal to this times p
multiply
(final PolynomialFunction
Polynomial to multiply by.
p
)
Deprecated as a consequence of PolynomialFunction being deprecated.

Multiply the instance by a polynomial.

public PolynomialFunction

Returns:

a new polynomial with all coefficients negated
negate
()
Deprecated as a consequence of PolynomialFunction being deprecated.

Negate the instance.

public PolynomialFunction

Returns:

the derivative polynomial.
polynomialDerivative
()
Deprecated as a consequence of PolynomialFunction being deprecated.

Returns the derivative as a PolynomialFunction.

public PolynomialFunction

Returns:

a new polynomial which is the instance minus p.
subtract
(final PolynomialFunction
Polynomial to subtract.
p
)
Deprecated as a consequence of PolynomialFunction being deprecated.

Subtract a polynomial from the instance.

public String

Returns:

a string representation of the polynomial.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the polynomial.

private static String

Returns:

a string representation of coeff.
toString
(double
Coefficient.
coeff
)

Creates a string representing a coefficient, removing ".0" endings.

public double

Returns:

the value of the polynomial at the given point.
value
(double
Argument for which the function value should be computed.
x
)

Implements org.apache.commons.math3.analysis.UnivariateFunction.value.

Compute the value of the function for the given argument.

public DerivativeStructure
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

coefficientsback to summary
private final double[] coefficients

The coefficients of the polynomial, ordered by degree -- i.e., coefficients[0] is the constant term and coefficients[n] is the coefficient of x^n where n is the degree of the polynomial.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization identifier

Constructor Detail

PolynomialFunctionback to summary
public PolynomialFunction(double[] c) throws NullArgumentException, NoDataException

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:double[]

Polynomial coefficients.

Exceptions
NullArgumentException:
if c is null.
NoDataException:
if c is empty.

Method Detail

addback to summary
public PolynomialFunction add(final PolynomialFunction p)

Deprecated

as a consequence of PolynomialFunction being deprecated. See corresponding docs for further information.

Add a polynomial to the instance.

Parameters
p:PolynomialFunction

Polynomial to add.

Returns:PolynomialFunction

a new polynomial which is the sum of the instance and p.

degreeback to summary
public int degree()

Returns the degree of the polynomial.

Returns:int

the degree of the polynomial.

derivativeback to summary
public UnivariateFunction derivative()

Implements org.apache.commons.math3.analysis.DifferentiableUnivariateFunction.derivative.

Returns the derivative as a UnivariateFunction.

Returns:UnivariateFunction

the derivative function.

differentiateback to summary
protected static double[] differentiate(double[] coefficients) throws NullArgumentException, NoDataException

Returns the coefficients of the derivative of the polynomial with the given coefficients.

Parameters
coefficients:double[]

Coefficients of the polynomial to differentiate.

Returns:double[]

the coefficients of the derivative or null if coefficients has length 1.

Exceptions
NullArgumentException:
if coefficients is null.
NoDataException:
if coefficients is empty.
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
evaluateback to summary
protected static double evaluate(double[] coefficients, double argument) throws NullArgumentException, NoDataException

Uses Horner's Method to evaluate the polynomial with the given coefficients at the argument.

Parameters
coefficients:double[]

Coefficients of the polynomial to evaluate.

argument:double

Input value.

Returns:double

the value of the polynomial.

Exceptions
NullArgumentException:
if coefficients is null.
NoDataException:
if coefficients is empty.
getCoefficientsback to summary
public double[] getCoefficients()

Returns a copy of the coefficients array.

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

Returns:double[]

a fresh copy of the coefficients array.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
multiplyback to summary
public PolynomialFunction multiply(final PolynomialFunction p)

Deprecated

as a consequence of PolynomialFunction being deprecated. See corresponding docs for further information.

Multiply the instance by a polynomial.

Parameters
p:PolynomialFunction

Polynomial to multiply by.

Returns:PolynomialFunction

a new polynomial equal to this times p

negateback to summary
public PolynomialFunction negate()

Deprecated

as a consequence of PolynomialFunction being deprecated. See corresponding docs for further information.

Negate the instance.

Returns:PolynomialFunction

a new polynomial with all coefficients negated

polynomialDerivativeback to summary
public PolynomialFunction polynomialDerivative()

Deprecated

as a consequence of PolynomialFunction being deprecated. See corresponding docs for further information.

Returns the derivative as a PolynomialFunction.

Returns:PolynomialFunction

the derivative polynomial.

subtractback to summary
public PolynomialFunction subtract(final PolynomialFunction p)

Deprecated

as a consequence of PolynomialFunction being deprecated. See corresponding docs for further information.

Subtract a polynomial from the instance.

Parameters
p:PolynomialFunction

Polynomial to subtract.

Returns:PolynomialFunction

a new polynomial which is the instance minus p.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the polynomial.

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).

Returns:String

a string representation of the polynomial.

Annotations
@Override
toStringback to summary
private static String toString(double coeff)

Creates a string representing a coefficient, removing ".0" endings.

Parameters
coeff:double

Coefficient.

Returns:String

a string representation of coeff.

valueback to summary
public double value(double x)

Implements org.apache.commons.math3.analysis.UnivariateFunction.value.

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:double

Argument for which the function value should be computed.

Returns:double

the value of the polynomial at the given point.

See Also
UnivariateFunction#value(double)
valueback to summary
public DerivativeStructure value(final DerivativeStructure t) throws NullArgumentException, NoDataException

Implements org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction.value.

Doc from org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction.value.

Simple mathematical function.

UnivariateDifferentiableFunction classes compute both the value and the first derivative of the function.

Parameters
t:DerivativeStructure

function input value

Returns:DerivativeStructure

function result

Exceptions
NullArgumentException:
if coefficients is null.
NoDataException:
if coefficients is empty.
Since
3.1
org.apache.commons.math3.analysis.polynomials back to summary

public Class PolynomialFunction.Parametric

extends Object
implements ParametricUnivariateFunction
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.analysis.polynomials.PolynomialFunction.Parametric
All Implemented Interfaces
org.apache.commons.math3.analysis.ParametricUnivariateFunction

Dedicated parametric polynomial class.
Since
3.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public double[]
gradient(double
Point for which the function value should be computed.
x
,
double...
Function parameters.
parameters
)

Implements org.apache.commons.math3.analysis.ParametricUnivariateFunction.gradient.

Compute the gradient of the function with respect to its parameters.

public double
value(final double
Point for which the function value should be computed.
x
,
final double...
Function parameters.
parameters
)

Implements org.apache.commons.math3.analysis.ParametricUnivariateFunction.value.

Compute the value of the function.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Parametricback to summary
public Parametric()

Method Detail

gradientback to summary
public double[] gradient(double x, double... parameters)

Implements org.apache.commons.math3.analysis.ParametricUnivariateFunction.gradient.

Doc from org.apache.commons.math3.analysis.ParametricUnivariateFunction.gradient.

Compute the gradient of the function with respect to its parameters.

Parameters
x:double

Point for which the function value should be computed.

parameters:double[]

Function parameters.

Returns:double[]

the value.

valueback to summary
public double value(final double x, final double... parameters) throws NoDataException

Implements org.apache.commons.math3.analysis.ParametricUnivariateFunction.value.

Doc from org.apache.commons.math3.analysis.ParametricUnivariateFunction.value.

Compute the value of the function.

Parameters
x:double

Point for which the function value should be computed.

parameters:double[]

Function parameters.

Returns:double

the value.