gospline

package module
v0.0.0-...-842a72f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 2 Imported by: 21

README

gospline

Golang cubic spline library

This library generates a cubic spline for given points.

Usage

Create a cubic spline
s := gospline.NewCubicSpline([]float64{0, 1, 2, 3}, []float64{0, 0.5, 2, 1.5})
Get an interpolated value
s.At(3.5)
Get an array of interpolated values
s.Range(0, 3, 0.25)
Supported boundaries

First derivation boundary: gospline.NewClampedCubicSpline

Second derivation boundary: gospline.NewNaturalCubicSpline

Installation

Just go get github.com/cnkei/gospline

Documentation

Index

Constants

View Source
const (
	CubicFirstDeriv boundary = iota
	CubicSecondDeriv
	CubicThirdDeriv
	CubicPeriodic
)

bounday types

Variables

This section is empty.

Functions

This section is empty.

Types

type Spline

type Spline interface {
	// At returns interpolated value at x
	// 0 <= x <= 1
	At(x float64) float64

	// Range returns interpolated values in [start, end] with step
	Range(start, end, step float64) []float64
}

Spline interface for interpolation functions

func NewClampedCubicSpline

func NewClampedCubicSpline(x, y []float64, f0, fn float64) Spline

NewClampedCubicSpline returns cubic spline with natural boundary the boundaries are:

f0: f'(x[0])
fn: f'(x[len(x)-1])

func NewCubicSpline

func NewCubicSpline(x, y []float64) Spline

NewCubicSpline returns cubic spline with natural boundary the whole array must be in ascending order

func NewMonotoneSpline

func NewMonotoneSpline(x, y []float64) Spline

NewMonotoneSpline returns cubic monotone hermite spline the whole array must be in ascending order

func NewNaturalCubicSpline

func NewNaturalCubicSpline(x, y []float64, f0, fn float64) Spline

NewNaturalCubicSpline returns cubic spline with natural boundary the boundaries are:

f0: f''(x[0])
fn: f''(x[len(x)-1])

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL