org.apache.commons.math3.analysis.interpolation

## Class DividedDifferenceInterpolator

- java.lang.Object
- - org.apache.commons.math3.analysis.interpolation.DividedDifferenceInterpolator

All Implemented Interfaces:
  Serializable, UnivariateInterpolator

    public class DividedDifferenceInterpolator
    extends Object
    implements UnivariateInterpolator, Serializable

Implements the Divided Difference Algorithm for interpolation of real univariate functions. For reference, see Introduction to Numerical Analysis, ISBN 038795452X, chapter 2.

The actual code of Neville's evaluation is in PolynomialFunctionLagrangeForm, this class provides an easy-to-use interface to it.

Since:
  1.2
Version:
  $Id: DividedDifferenceInterpolator.java 1385313 2012-09-16 16:35:23Z tn $
See Also:
  Serialized Form

### Field Summary

Fields
`private static long` `serialVersionUID` serializable version identifier

### Constructor Summary

Constructors
Constructor and Description
`DividedDifferenceInterpolator()`

### Method Summary

Methods
`protected static double[]` `computeDividedDifference(double[] x, double[] y)` Return a copy of the divided difference array.
`PolynomialFunctionNewtonForm` `interpolate(double[] x, double[] y)` Compute an interpolating function for the dataset.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### serialVersionUID

    private static final long serialVersionUID

serializable version identifier

See Also:
  Constant Field Values

### Constructor Detail

#### DividedDifferenceInterpolator

    public DividedDifferenceInterpolator()

### Method Detail

#### interpolate

    public PolynomialFunctionNewtonForm interpolate(double[] x,
                                           double[] y)
                                             throws DimensionMismatchException,
                                                    NumberIsTooSmallException,
                                                    NonMonotonicSequenceException

Compute an interpolating function for the dataset.

Specified by:
  `interpolate` in interface `UnivariateInterpolator`
Parameters:
  `x` - Interpolating points array.
  `y` - Interpolating values array.
Returns:
  a function which interpolates the dataset.
Throws:
  `DimensionMismatchException` - if the array lengths are different.
  `NumberIsTooSmallException` - if the number of points is less than 2.
  `NonMonotonicSequenceException` - if `x` is not sorted in strictly increasing order.

#### computeDividedDifference

    protected static double[] computeDividedDifference(double[] x,
                                    double[] y)
                                                throws DimensionMismatchException,
                                                       NumberIsTooSmallException,
                                                       NonMonotonicSequenceException

Return a copy of the divided difference array.

The divided difference array is defined recursively by

     f[x0] = f(x0)
     f[x0,x1,...,xk] = (f[x1,...,xk] - f[x0,...,x[k-1]]) / (xk - x0)

The computational complexity is O(N^2).

Parameters:
  `x` - Interpolating points array.
  `y` - Interpolating values array.
Returns:
  a fresh copy of the divided difference array.
Throws:
  `DimensionMismatchException` - if the array lengths are different.
  `NumberIsTooSmallException` - if the number of points is less than 2.
  `NonMonotonicSequenceException` - if `x` is not sorted in strictly increasing order.