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

public Class PolynomialFunctionNewtonForm

extends Object
implements UnivariateDifferentiableFunction
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction, org.apache.commons.math3.analysis.UnivariateFunction
Imports
org.apache.commons.math3.analysis.differentiation.DerivativeStructure, .UnivariateDifferentiableFunction, org.apache.commons.math3.exception.DimensionMismatchException, .NoDataException, .NullArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.MathUtils

Implements the representation of a real polynomial function in Newton Form. For reference, see Elementary Numerical Analysis, ISBN 0070124477, chapter 2.

The formula of polynomial in Newton form is p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... + a[n](x-c[0])(x-c[1])...(x-c[n-1]) Note that the length of a[] is one more than the length of c[]

Since
1.2

Field Summary

Modifier and TypeField and Description
private final double[]
a

When all c[i] = 0, a[] becomes normal polynomial coefficients, i.e. a[i] = coefficients[i].

private final double[]
c

Centers of the Newton polynomial.

private 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 boolean
coefficientsComputed

Whether the polynomial coefficients are available.

Constructor Summary

AccessConstructor and Description
public
PolynomialFunctionNewtonForm(double[]
Coefficients in Newton form formula.
a
,
double[]
Centers.
c
)

Construct a Newton polynomial with the given a[] and c[].

Method Summary

Modifier and TypeMethod and Description
protected void
computeCoefficients()

Calculate the normal polynomial coefficients given the Newton form.

public int

Returns:

the degree of the polynomial
degree
()

Returns the degree of the polynomial.

public static double

Returns:

the function value.
evaluate
(double[]
Coefficients in Newton form formula.
a
,
double[]
Centers.
c
,
double
Point at which the function value is to be computed.
z
)

Evaluate the Newton polynomial using nested multiplication.

public double[]

Returns:

a fresh copy of the centers array.
getCenters
()

Returns a copy of the centers array.

public double[]

Returns:

a fresh copy of the coefficients array.
getCoefficients
()

Returns a copy of the coefficients array.

public double[]

Returns:

a fresh copy of coefficients in Newton form formula
getNewtonCoefficients
()

Returns a copy of coefficients in Newton form formula.

public double

Returns:

the function value.
value
(double
Point at which the function value is to be computed.
z
)

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

Calculate the function value at the given point.

public DerivativeStructure
protected static void
verifyInputArray(double[]
the coefficients in Newton form formula
a
,
double[]
the centers
c
)

Verifies that the input arrays are valid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final double[] a

When all c[i] = 0, a[] becomes normal polynomial coefficients, i.e. a[i] = coefficients[i].

cback to summary
private final double[] c

Centers of the Newton polynomial.

coefficientsback to summary
private 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.

coefficientsComputedback to summary
private boolean coefficientsComputed

Whether the polynomial coefficients are available.

Constructor Detail

PolynomialFunctionNewtonFormback to summary
public PolynomialFunctionNewtonForm(double[] a, double[] c) throws NullArgumentException, NoDataException, DimensionMismatchException

Construct a Newton polynomial with the given a[] and c[]. The order of centers are important in that if c[] shuffle, then values of a[] would completely change, not just a permutation of old a[].

The constructor makes copy of the input arrays and assigns them.

Parameters
a:double[]

Coefficients in Newton form formula.

c:double[]

Centers.

Exceptions
NullArgumentException:
if any argument is null.
NoDataException:
if any array has zero length.
DimensionMismatchException:
if the size difference between a and c is not equal to 1.

Method Detail

computeCoefficientsback to summary
protected void computeCoefficients()

Calculate the normal polynomial coefficients given the Newton form. It also uses nested multiplication but takes O(N^2) time.

degreeback to summary
public int degree()

Returns the degree of the polynomial.

Returns:int

the degree of the polynomial

evaluateback to summary
public static double evaluate(double[] a, double[] c, double z) throws NullArgumentException, DimensionMismatchException, NoDataException

Evaluate the Newton polynomial using nested multiplication. It is also called Horner's Rule and takes O(N) time.

Parameters
a:double[]

Coefficients in Newton form formula.

c:double[]

Centers.

z:double

Point at which the function value is to be computed.

Returns:double

the function value.

Exceptions
NullArgumentException:
if any argument is null.
DimensionMismatchException:
if the size difference between a and c is not equal to 1.
NoDataException:
if any array has zero length.
getCentersback to summary
public double[] getCenters()

Returns a copy of the centers array.

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

Returns:double[]

a fresh copy of the centers array.

getCoefficientsback to summary
public double[] getCoefficients()

Returns a copy of the coefficients array.

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

Returns:double[]

a fresh copy of the coefficients array.

getNewtonCoefficientsback to summary
public double[] getNewtonCoefficients()

Returns a copy of coefficients in Newton form formula.

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

Returns:double[]

a fresh copy of coefficients in Newton form formula

valueback to summary
public double value(double z)

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

Calculate the function value at the given point.

Parameters
z:double

Point at which the function value is to be computed.

Returns:double

the function value.

valueback to summary
public DerivativeStructure value(final DerivativeStructure t)

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

Since
3.1
verifyInputArrayback to summary
protected static void verifyInputArray(double[] a, double[] c) throws NullArgumentException, NoDataException, DimensionMismatchException

Verifies that the input arrays are valid.

The centers must be distinct for interpolation purposes, but not for general use. Thus it is not verified here.

Parameters
a:double[]

the coefficients in Newton form formula

c:double[]

the centers

Exceptions
NullArgumentException:
if any argument is null.
NoDataException:
if any array has zero length.
DimensionMismatchException:
if the size difference between a and c is not equal to 1.
See Also
org.apache.commons.math3.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[], double[])