Popularity
1.6
Growing
Activity
3.5
Growing
11
2
1

Programming language: Go
Latest version: v2.0.5

piecewiselinear alternatives and similar packages

Based on the "Science and Data Analysis" category

Do you think we are missing an alternative of piecewiselinear or a related project?

Add another 'Science and Data Analysis' Package

README

piecewiselinear

coverage Build Status

A tiny library for linear interpolation. O(log(N)) per evaluation for N control points.

import "github.com/sgreben/piecewiselinear"

Get it

go get -u "github.com/sgreben/piecewiselinear"

Use it

import "github.com/sgreben/piecewiselinear"

func main() {
    f := piecewiselinear.Function{Y:[]float64{0,1,0}} // range: "hat" function
    f.X = piecewiselinear.Span(0, 1, len(f.Y)) // domain: equidistant points along X axis
    fmt.Println(
        f.At(0), // f.At(x) evaluates f at x
        f.At(0.25),
        f.At(0.5),
        f.At(0.75),
        f.At(1.0),
        f.At(123.0),  // outside its domain X the function is constant 0
        f.At(-123.0), //
    )
    // Output:
    // 0 0.5 1 0.5 0 0 0
}