Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: interpolate1d - Constructor Up: mathematics - Module Previous: fftservertest - Function


interpolate1d - Tool



Package utility
Module mathematics


Postscript file available

Various sorts of 1-dimensional interpolation

include "interpolate1d.g"

Constructors
interpolate1d Construct an interpolate1d tool
Functions
done Delete the interpolate1d tool
initialize Set the data and the interpolation function
interpolate Perform an interpolation
setfunction Change the interpolation function
type Return the type of this tool



Description

This tool does one-dimensional interpolation on a user supplied set of (x, y) values. The computation is performed in a pre-compiled executable. It is not interpreted by Glish.

interpolate1d is used to interpolate between values using any of the following algorithms:

nearest neighbor
This simply returns the y-value for the data point that has the nearest x-value to the requested x-value. You could argue that this is not interpolation at all. But it is fast.
linear
Linear interpolation is the simplest useful interpolation scheme. It fits a line between the two data points whose x-value straddle the requested x-value. It is quite a robust interpolation scheme.
cubic polynomial
This fits a cubic polynomial to the four points whose x-value straddle the requested x-value.
spline
This fits a natural cubic spline to the entire data set and then interpolates on this function. A natural cubic spline is a curve that is smooth in its first derivative, continious in its second and has a zero second second derivative at the end points. This interpolation scheme uses the entire data set to compute the interpolating function unlike all the others described above which only use nearby points.

Demo and test functions are available: interpolate1ddemo() and interpolate1dtest().



Example

To use the functions in this tool we have to firstly (1) load the definition of the interpolate1d tool and (2) construct a tool that will actually perform the computations.

    include "interpolate1d.g"     # 1
    interp := interpolate1d()     # 2

OK, lets create some fake data to interpolate: y = 3x2 + 5

    x := 1:10        # 1,2,3,4,5,6,7,8,9,10
    y := 3*x*x + 5   # 8, ..., 305

Next we need to initialize the interpolation tool -- provide it with the x,y data and tell it what interpolation function we want:

    interp.initialize(x,y,'linear')   # Returns F if it fails

We actually did not have to specify linear, because that is the default interpolation function. After the interpolator is initialized, we can use it to interpolate the value at some new values of x:

    interp.interpolate([1.5, 2.5])
    # [12.5 24.5]

Obviously our linear interpolation isn't doing the best possible job with a second order polynomial, so instead we could try a cubic polynomial:

    interp.setfunction('cubic')      
    interp.interpolate([1.5, 2.5])
    # [11.75 23.75]
This is exact of course.



See Also
interpolate1ddemo interpolate1dtest




next up previous contents index
Next: interpolate1d - Constructor Up: mathematics - Module Previous: fftservertest - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15