Package interpolator
provides univariate data interpolators:
- piecewise-constant interpolator
- piecewise-linear interpolator
- piecewise-linear with threshold: the interpolated value is truncated to the closest in the data range, when the input point is out of the data domain, in order to prevent extrapolation effects
- piecewise-geometric
- piecewise-geometric on square-root factor: the interpolated value depends on the square root of the normalized distance from data points
The input data is specified by means of a nonempty slice of two-dimensional points XYs
. If a single data point is provided, the resulting interpolator treats the input as a constant for all abscissae.
go get -u github.com/edgelaboratories/interpolator
package main
import (
"fmt"
"log"
"github.com/edgelaboratories/interpolator"
)
func main() {
xys := interpolator.XYs{
{
X: 0.0,
Y: 1.2,
},
{
X: 0.5,
Y: 1.0,
},
{
X: 1.0,
Y: 1.4,
},
}
interp, err := interpolator.NewGeometric(xys)
if err != nil {
log.Fatal(err)
}
fmt.Printf("value at 0.75 is %0.2f\n", interp.Value(0.75))
fmt.Printf("gradient at 0.75 is %0.2f\n", interp.Gradient(0.75))
}