Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Package | utility | |
Module | mathematics |
include "interpolate1d.g"
interpolate1d | Construct an interpolate1d tool |
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 |
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:
Demo and test functions are available: interpolate1ddemo() and interpolate1dtest().
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.