edu.nrao.sss.math
Class NewtonDividedDifference

java.lang.Object
  extended by edu.nrao.sss.math.NewtonDividedDifference
All Implemented Interfaces:
Interpolator

public class NewtonDividedDifference
extends Object

An interpolated value calculator that uses Newton's divided-difference formula.

Under certain conditions this interpolator can have trouble with the first and last few intervals. The CubicSpline may be a better interpolator for most situations.

Version Info:

$Revision$
$Date$
$Author$

Since:
2007-04-27
Author:
David M. Harland

Constructor Summary
NewtonDividedDifference()
          Creates a new instance.
 
Method Summary
 Point2D addPoint(Point2D newPoint)
          Adds a copy of newPoint to this interpolator.
 void clear()
          Clears all points from this interpolator.
 NumberInterval getDomain()
          Returns an interval whose endpoints are the smallest and largest independent ("x") values of the points held by this interpolator.
 List<Point2D> getPoints()
          Returns a list containing a copy of each point held by this interpolator.
 double getValueFor(double x)
          Returns a value, f(x), for the given value.
 Point2D removePoint(double xValue)
          Removes from this interpolator the point, if any, with an independent variable equal to xValue.
 void setPoints(List<? extends Point2D> points)
          Adds a copy of each of the points in the list to this interpolator.
 int size()
          Returns the number of points held by this interpolator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NewtonDividedDifference

public NewtonDividedDifference()
Creates a new instance.

Method Detail

getValueFor

public double getValueFor(double x)
Description copied from interface: Interpolator
Returns a value, f(x), for the given value. The returned value is calculated based on an interpolation algorithm provided by concrete implementations of this interface. Some examples of such algorithms are linear, cubic spline, and polynomial.

If the value x is outside the domain of this interpolator, and IllegalArgumentException is thrown.

Specified by:
getValueFor in interface Interpolator
Parameters:
x - the independent variable for which a dependent variable, f(x) is sought.
Returns:
an interpolated value for f(x).

setPoints

public void setPoints(List<? extends Point2D> points)
Description copied from interface: Interpolator
Adds a copy of each of the points in the list to this interpolator.

If any of the new points holds an x-value equal to that of a point already held by this interpolator, the already-held point is first removed, and then the new point is added.

Specified by:
setPoints in interface Interpolator
Parameters:
points - a list of new points to be added to this interpolator.

addPoint

public Point2D addPoint(Point2D newPoint)
Description copied from interface: Interpolator
Adds a copy of newPoint to this interpolator.

If this interpolator already contains a point with the same x-value as newPoint, that point is first removed and is also the value returned.

Specified by:
addPoint in interface Interpolator
Parameters:
newPoint - a point to be added to this interpolator.
Returns:
the previously held point that has the same x-value as newPoint, or null if this interpolator held no such point.

removePoint

public Point2D removePoint(double xValue)
Description copied from interface: Interpolator
Removes from this interpolator the point, if any, with an independent variable equal to xValue.

Specified by:
removePoint in interface Interpolator
Parameters:
xValue - the independent variable of the point to be removed.
Returns:
a point formerly contained by this interpolator having an independent variable equal to xValue. If this interpolator holds no such point, null is returned.

clear

public void clear()
Description copied from interface: Interpolator
Clears all points from this interpolator. Implementations of this interface may choose to reset other properties as well.

Specified by:
clear in interface Interpolator

size

public int size()
Description copied from interface: Interpolator
Returns the number of points held by this interpolator.

Specified by:
size in interface Interpolator
Returns:
the number of points held by this interpolator.

getPoints

public List<Point2D> getPoints()
Description copied from interface: Interpolator
Returns a list containing a copy of each point held by this interpolator. The copies in the returned list will be in the same order as the actual points held by this interpolator.

Specified by:
getPoints in interface Interpolator
Returns:
a list containing a copy of each point held by this interpolator.

getDomain

public NumberInterval getDomain()
Description copied from interface: Interpolator
Returns an interval whose endpoints are the smallest and largest independent ("x") values of the points held by this interpolator.

Specified by:
getDomain in interface Interpolator
Returns:
the domain of the function represented by the points of this interpolator.


Copyright © 2009. All Rights Reserved.