org.apache.commons.math3.analysis.interpolation

## Class HermiteInterpolator

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

All Implemented Interfaces:
  UnivariateDifferentiableVectorFunction, UnivariateVectorFunction

    public class HermiteInterpolator
    extends java.lang.Object
    implements UnivariateDifferentiableVectorFunction

Polynomial interpolator using both sample values and sample derivatives.

The interpolation polynomials match all sample points, including both values and provided derivatives. There is one polynomial for each component of the values vector. All polynomials have the same degree. The degree of the polynomials depends on the number of points and number of derivatives at each point. For example the interpolation polynomials for n sample points without any derivatives all have degree n-1. The interpolation polynomials for n sample points with the two extreme points having value and first derivative and the remaining points having value only all have degree n+1. The interpolation polynomial for n sample points with value, first and second derivative for all points all have degree 3n-1.

Since:
  3.1
Version:
  $Id: HermiteInterpolator.java 1410460 2012-11-16 16:49:38Z erans $

### Field Summary

Fields
`private java.util.List<java.lang.Double>` `abscissae` Sample abscissae.
`private java.util.List<double[]>` `bottomDiagonal` Bottom diagonal of the divided differences array.
`private java.util.List<double[]>` `topDiagonal` Top diagonal of the divided differences array.

### Constructor Summary

Constructors
Constructor and Description
`HermiteInterpolator()` Create an empty interpolator.

### Method Summary

Methods
`void` `addSamplePoint(double x, double[]... value)` Add a sample point.
`private void` `checkInterpolation()` Check interpolation can be performed.
`PolynomialFunction[]` `getPolynomials()` Compute the interpolation polynomials.
`private PolynomialFunction` `polynomial(double... c)` Create a polynomial from its coefficients.
`DerivativeStructure[]` `value(DerivativeStructure x)` Interpolate value at a specified abscissa.
`double[]` `value(double x)` Interpolate value at a specified abscissa.

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

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

### Field Detail

#### abscissae

    private final java.util.List<java.lang.Double> abscissae

Sample abscissae.

#### topDiagonal

    private final java.util.List<double[]> topDiagonal

Top diagonal of the divided differences array.

#### bottomDiagonal

    private final java.util.List<double[]> bottomDiagonal

Bottom diagonal of the divided differences array.

### Constructor Detail

#### HermiteInterpolator

    public HermiteInterpolator()

Create an empty interpolator.

### Method Detail

#### addSamplePoint

    public void addSamplePoint(double x,
                      double[]... value)
                        throws ZeroException,
                               MathArithmeticException

Add a sample point.

This method must be called once for each sample point. It is allowed to mix some calls with values only with calls with values and first derivatives.

The point abscissae for all calls must be different.

Parameters:
  `x` - abscissa of the sample point
  `value` - value and derivatives of the sample point (if only one row is passed, it is the value, if two rows are passed the first one is the value and the second the derivative and so on)
Throws:
  `ZeroException` - if the abscissa difference between added point and a previous point is zero (i.e. the two points are at same abscissa)
  `MathArithmeticException` - if the number of derivatives is larger than 20, which prevents computation of a factorial

#### getPolynomials

    public PolynomialFunction[] getPolynomials()
                                        throws NoDataException

Compute the interpolation polynomials.

Returns:
  interpolation polynomials array
Throws:
  `NoDataException` - if sample is empty

#### value

    public double[] value(double x)
                   throws NoDataException

Interpolate value at a specified abscissa.

Calling this method is equivalent to call the `value` methods of all polynomials returned by `getPolynomials`, except it does not build the intermediate polynomials, so this method is faster and numerically more stable.

Specified by:
  `value` in interface `UnivariateVectorFunction`
Parameters:
  `x` - interpolation abscissa
Returns:
  interpolated value
Throws:
  `NoDataException` - if sample is empty

#### value

    public DerivativeStructure[] value(DerivativeStructure x)
                                throws NoDataException

Interpolate value at a specified abscissa.

Calling this method is equivalent to call the `value` methods of all polynomials returned by `getPolynomials`, except it does not build the intermediate polynomials, so this method is faster and numerically more stable.

Specified by:
  `value` in interface `UnivariateDifferentiableVectorFunction`
Parameters:
  `x` - interpolation abscissa
Returns:
  interpolated value
Throws:
  `NoDataException` - if sample is empty

#### checkInterpolation

    private void checkInterpolation()
                             throws NoDataException

Check interpolation can be performed.

Throws:
  `NoDataException` - if interpolation cannot be performed because sample is empty

#### polynomial

    private PolynomialFunction polynomial(double... c)

Create a polynomial from its coefficients.

Parameters:
  `c` - polynomials coefficients
Returns:
  polynomial