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    *      https://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  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.analysis.interpolation;
23  
24  import java.io.Serializable;
25  
26  import org.hipparchus.analysis.polynomials.PolynomialFunctionLagrangeForm;
27  import org.hipparchus.exception.MathIllegalArgumentException;
28  
29  /**
30   * Implements the <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
31   * Neville's Algorithm</a> for interpolation of real univariate functions. For
32   * reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
33   * chapter 2.
34   * <p>
35   * The actual code of Neville's algorithm is in PolynomialFunctionLagrangeForm,
36   * this class provides an easy-to-use interface to it.</p>
37   *
38   */
39  public class NevilleInterpolator implements UnivariateInterpolator,
40      Serializable {
41  
42      /** serializable version identifier */
43      static final long serialVersionUID = 3003707660147873733L;
44  
45      /** Empty constructor.
46       * <p>
47       * This constructor is not strictly necessary, but it prevents spurious
48       * javadoc warnings with JDK 18 and later.
49       * </p>
50       * @since 3.0
51       */
52      public NevilleInterpolator() { // NOPMD - unnecessary constructor added intentionally to make javadoc happy
53          // nothing to do
54      }
55  
56      /**
57       * Computes an interpolating function for the data set.
58       *
59       * @param x Interpolating points.
60       * @param y Interpolating values.
61       * @return a function which interpolates the data set
62       * @throws MathIllegalArgumentException if the array lengths are different.
63       * @throws MathIllegalArgumentException if the number of points is less than 2.
64       * @throws MathIllegalArgumentException if two abscissae have the same
65       * value.
66       */
67      @Override
68      public PolynomialFunctionLagrangeForm interpolate(double[] x, double[] y)
69          throws MathIllegalArgumentException {
70          return new PolynomialFunctionLagrangeForm(x, y);
71      }
72  
73  }