Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.math.analysis.polynomials
Class PolynomialFunctionNewtonForm

    java.lang.Object
      org.apache.commons.math.analysis.polynomials.PolynomialFunctionNewtonForm

All Implemented Interfaces:
  UnivariateRealFunction

    public class PolynomialFunctionNewtonForm

extends Object
implements UnivariateRealFunction

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
Version:
  $Revision: 1073498 $ $Date: 2011-02-22 21:57:26 +0100 (mar. 22 févr. 2011) $

Field Summary
`private double[]` | `a` When all c[i] = 0, a[] becomes normal polynomial coefficients, i.e.
`private double[]` | `c` Centers of the Newton polynomial.
`private double[]` | `coefficients` The coefficients of the polynomial, ordered by degree -- i.e.
`private boolean` | `coefficientsComputed` Whether the polynomial coefficients are available.

Constructor Summary
`PolynomialFunctionNewtonForm(double[] a, double[] c)` Construct a Newton polynomial with the given a[] and c[].

Method Summary
`protected void` | `computeCoefficients()` Calculate the normal polynomial coefficients given the Newton form.
`int` | `degree()` Returns the degree of the polynomial.
`static double` | `evaluate(double[] a, double[] c, double z)` Evaluate the Newton polynomial using nested multiplication.
`double[]` | `getCenters()` Returns a copy of the centers array.
`double[]` | `getCoefficients()` Returns a copy of the coefficients array.
`double[]` | `getNewtonCoefficients()` Returns a copy of coefficients in Newton form formula.
`double` | `value(double z)` Calculate the function value at the given point.
`protected static void` | `verifyInputArray(double[] a, double[] c)` Verifies that the input arrays are valid.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### coefficients

    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.

### c

    private final double[] c

  Centers of the Newton polynomial.

### a

    private final double[] a

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

### coefficientsComputed

    private boolean coefficientsComputed

  Whether the polynomial coefficients are available.

Constructor Detail

### PolynomialFunctionNewtonForm

    public PolynomialFunctionNewtonForm(double[] a,
                                        double[] c)
                                 throws IllegalArgumentException

  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` - the coefficients in Newton form formula
    `c` - the centers
  Throws:
    `IllegalArgumentException` - if input arrays are not valid

Method Detail

### value

    public double value(double z)
                 throws FunctionEvaluationException

  Calculate the function value at the given point.

  Specified by:
    `value` in interface `UnivariateRealFunction`
  Parameters:
    `z` - the point at which the function value is to be computed
  Returns:
    the function value
  Throws:
    `FunctionEvaluationException` - if a runtime error occurs
  See Also:
    `UnivariateRealFunction.value(double)`

### degree

    public int degree()

  Returns the degree of the polynomial.

  Returns:
    the degree of the polynomial

### getNewtonCoefficients

    public double[] getNewtonCoefficients()

  Returns a copy of coefficients in Newton form formula.

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

  Returns:
    a fresh copy of coefficients in Newton form formula

### getCenters

    public double[] getCenters()

  Returns a copy of the centers array.

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

  Returns:
    a fresh copy of the centers array

### getCoefficients

    public double[] getCoefficients()

  Returns a copy of the coefficients array.

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

  Returns:
    a fresh copy of the coefficients array

### evaluate

    public static double evaluate(double[] a,
                                  double[] c,
                                  double z)
                           throws FunctionEvaluationException,
                                  IllegalArgumentException

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

  Parameters:
    `a` - the coefficients in Newton form formula
    `c` - the centers
    `z` - the point at which the function value is to be computed
  Returns:
    the function value
  Throws:
    `FunctionEvaluationException` - if a runtime error occurs
    `IllegalArgumentException` - if inputs are not valid

### computeCoefficients

    protected void computeCoefficients()

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

### verifyInputArray

    protected static void verifyInputArray(double[] a,
                                           double[] c)
                                    throws IllegalArgumentException

  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` - the coefficients in Newton form formula
    `c` - the centers
  Throws:
    `IllegalArgumentException` - if not valid
  See Also:
    `DividedDifferenceInterpolator.computeDividedDifference(double[], double[])`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 2003-2013 Apache Software Foundation