From 56a4d632c590ac56f34e245daafdaf146810d5e5 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Thu, 16 Jul 2009 15:09:02 +0000 Subject: [PATCH] Changed the return type of the various interpolation algorithms to the specific implementation of UnivariateRealFunction each one uses (thanks to Gilles for reporting the problem and providing the patch) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@794709 13f79535-47bb-0310-9956-ffa450edef68 --- .../interpolation/DividedDifferenceInterpolator.java | 8 +++----- .../analysis/interpolation/LoessInterpolator.java | 8 ++++---- .../analysis/interpolation/NevilleInterpolator.java | 11 ++++------- .../analysis/interpolation/SplineInterpolator.java | 3 +-- src/site/xdoc/changes.xml | 4 ++++ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolator.java b/src/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolator.java index 870daeb7b..2384e2671 100644 --- a/src/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolator.java +++ b/src/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolator.java @@ -19,7 +19,6 @@ package org.apache.commons.math.analysis.interpolation; import java.io.Serializable; import org.apache.commons.math.DuplicateSampleAbscissaException; -import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; import org.apache.commons.math.analysis.polynomials.PolynomialFunctionNewtonForm; @@ -50,7 +49,7 @@ public class DividedDifferenceInterpolator implements UnivariateRealInterpolator * @return a function which interpolates the data set * @throws DuplicateSampleAbscissaException if arguments are invalid */ - public UnivariateRealFunction interpolate(double x[], double y[]) throws + public PolynomialFunctionNewtonForm interpolate(double x[], double y[]) throws DuplicateSampleAbscissaException { /** @@ -76,9 +75,8 @@ public class DividedDifferenceInterpolator implements UnivariateRealInterpolator } a = computeDividedDifference(x, y); - PolynomialFunctionNewtonForm p; - p = new PolynomialFunctionNewtonForm(a, c); - return p; + return new PolynomialFunctionNewtonForm(a, c); + } /** diff --git a/src/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java b/src/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java index 0767cbe81..5032a037a 100644 --- a/src/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java +++ b/src/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java @@ -16,12 +16,12 @@ */ package org.apache.commons.math.analysis.interpolation; -import org.apache.commons.math.analysis.UnivariateRealFunction; -import org.apache.commons.math.MathException; - import java.io.Serializable; import java.util.Arrays; +import org.apache.commons.math.MathException; +import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; + /** * Implements the * Local Regression Algorithm (also Loess, Lowess) for interpolation of @@ -132,7 +132,7 @@ public class LoessInterpolator *
  • All arguments and values are finite real numbers
  • * */ - public final UnivariateRealFunction interpolate( + public final PolynomialSplineFunction interpolate( final double[] xval, final double[] yval) throws MathException { return new SplineInterpolator().interpolate(xval, smooth(xval, yval)); } diff --git a/src/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java b/src/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java index e7d6e5397..4e06bde17 100644 --- a/src/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java +++ b/src/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math.analysis.interpolation; import java.io.Serializable; + import org.apache.commons.math.MathException; -import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; /** @@ -47,11 +47,8 @@ public class NevilleInterpolator implements UnivariateRealInterpolator, * @return a function which interpolates the data set * @throws MathException if arguments are invalid */ - public UnivariateRealFunction interpolate(double x[], double y[]) throws - MathException { - - PolynomialFunctionLagrangeForm p; - p = new PolynomialFunctionLagrangeForm(x, y); - return p; + public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) + throws MathException { + return new PolynomialFunctionLagrangeForm(x, y); } } diff --git a/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java b/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java index fdcfa19aa..0c97628d5 100644 --- a/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java +++ b/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java @@ -17,7 +17,6 @@ package org.apache.commons.math.analysis.interpolation; import org.apache.commons.math.MathRuntimeException; -import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialFunction; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; @@ -56,7 +55,7 @@ public class SplineInterpolator implements UnivariateRealInterpolator { * @param y the values for the interpolation points * @return a function which interpolates the data set */ - public UnivariateRealFunction interpolate(double x[], double y[]) { + public PolynomialSplineFunction interpolate(double x[], double y[]) { if (x.length != y.length) { throw MathRuntimeException.createIllegalArgumentException( "dimension mismatch {0} != {1}", x.length, y.length); diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 92263e0bb..5f59a3ead 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,10 @@ The type attribute can be add,update,fix,remove. + + Changed the return type of the various interpolation algorithms to the + specific implementation of UnivariateRealFunction each one uses + The behavior of the bracket method in UnivariateRealSolverUtils has been changed to return successfully when a tentative bracketing interval has a root exactly at one of its end points. Previously, such intervals