View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.math4.legacy.analysis.interpolation;
18  
19  import org.apache.commons.math4.legacy.analysis.polynomials.PolynomialFunctionLagrangeForm;
20  import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
21  import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
22  import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
23  
24  /**
25   * Implements the <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
26   * Neville's Algorithm</a> for interpolation of real univariate functions. For
27   * reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
28   * chapter 2.
29   * <p>
30   * The actual code of Neville's algorithm is in PolynomialFunctionLagrangeForm,
31   * this class provides an easy-to-use interface to it.</p>
32   *
33   * @since 1.2
34   */
35  public class NevilleInterpolator implements UnivariateInterpolator {
36      /**
37       * Computes an interpolating function for the data set.
38       *
39       * @param x Interpolating points.
40       * @param y Interpolating values.
41       * @return a function which interpolates the data set
42       * @throws DimensionMismatchException if the array lengths are different.
43       * @throws NumberIsTooSmallException if the number of points is less than 2.
44       * @throws NonMonotonicSequenceException if two abscissae have the same
45       * value.
46       */
47      @Override
48      public PolynomialFunctionLagrangeForm interpolate(double[] x, double[] y)
49          throws DimensionMismatchException,
50                 NumberIsTooSmallException,
51                 NonMonotonicSequenceException {
52          return new PolynomialFunctionLagrangeForm(x, y);
53      }
54  }