peakml.math.function
Class CubicSplineFunction

java.lang.Object
  extended by peakml.math.function.CubicSplineFunction
All Implemented Interfaces:
Function

public class CubicSplineFunction
extends java.lang.Object
implements Function

This class calculates the natural cubic spline for a given set of input values. In mathematics a spline is a special function defined piecewise by polynomials (see PolynomialFunction). The approach attempts to solve the following equation by using row operations to convert the matrix to upper triangular and then back substitution. The D[i] are the derivatives at the knots.

   gamma        D        delta
  [2 1       ] [D[0]]   [3(x[1] - x[0])  ]
  |1 4 1     | |D[1]|   |3(x[2] - x[0])  |
  |  1 4 1   | | .  | = |      .         |
  |     ...  | | .  |   |      .         |
  |     1 4 1| | .  |   |3(x[n] - x[n-2])|
  [       1 2] [D[n]]   [3(x[n] - x[n-1])]
 
http://en.wikipedia.org/wiki/Cubic_spline http://www.cse.unsw.edu.au/~lambert/splines/source.html


Constructor Summary
CubicSplineFunction(double[] xvals, double[] yvals)
          Constructs (i.e.
 
Method Summary
static CubicSplineFunction fit(double[] xvals, double[] yvals)
          Constructs (i.e.
 double getY(double x)
          Calculates the y-value for the given x-value with the function defined here.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CubicSplineFunction

public CubicSplineFunction(double[] xvals,
                           double[] yvals)
Constructs (i.e. fits) the polynomial functions to the given input data. This constructor is provided as a convenience mechanism.

Parameters:
xvals - The x-values.
yvals - The y-values.
Method Detail

getY

public double getY(double x)
Description copied from interface: Function
Calculates the y-value for the given x-value with the function defined here.

Specified by:
getY in interface Function
Parameters:
x - The x-value.
Returns:
The y-value.

fit

public static CubicSplineFunction fit(double[] xvals,
                                      double[] yvals)
Constructs (i.e. fits) the polynomial functions to the given input data. This function is provided as a convenience mechanism.

Parameters:
xvals - The x-values.
yvals - The y-values.
Returns:
The cubic spline function.