Documentation
¶
Overview ¶
Package piecewiselinear is a tiny library for linear interpolation.
Example ¶
f := Function{Y: []float64{0, 1, 0}} // range: "hat" function f.X = 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
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Function ¶
Function is a piecewise-linear 1-dimensional function
func (Function) Area ¶
Area returns the definite integral of the function on its domain X.
Time complexity: O(N), where N is the number of points. Space complexity: O(1)
func (Function) AreaUpTo ¶
AreaUpTo returns the definite integral of the function on its domain X intersected with [-Inf, x].
Time complexity: O(N), where N is the number of points. Space complexity: O(1)
func (Function) At ¶
At returns the function's value at the given point. Outside its domain X, the function is constant at 0.
The function's X and Y slices are expected to be the same legnth. The length property is _not_ verified. The function's X slice is expected to be sorted in ascending order. The sortedness property is _not_ verified.
Time complexity: O(log(N)), where N is the number of points. Space complexity: O(1)
func (Function) IsInterpolatedAt ¶
IsInterpolatedAt returns true if x is within the given range of points, false if outside of that range