numerics

package
v0.0.0-...-fe39cb5 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2015 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

The Tideland Go Library numerics package contains some functions to support statistical analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PackageVersion

func PackageVersion() version.Version

PackageVersion returns the version of the version package.

Types

type CubicSplineFunction

type CubicSplineFunction struct {
	// contains filtered or unexported fields
}

CubicSplineFunction is a function based on polynamial functions and a set of points it is going through.

func NewCubicSplineFunction

func NewCubicSplineFunction(points Points) *CubicSplineFunction

NewCubicSplineFunction creates a cubic spline function based on a set of points.

func (*CubicSplineFunction) Eval

func (csf *CubicSplineFunction) Eval(x float64) float64

Eval evaluates the function for a given X value and returns the Y value.

func (*CubicSplineFunction) EvalPoint

func (csf *CubicSplineFunction) EvalPoint(x float64) *Point

EvalPoint evaluates the function for a given X value and returns the result as a point.

func (*CubicSplineFunction) EvalPoints

func (csf *CubicSplineFunction) EvalPoints(fromX, toX float64, count int) Points

EvalPoints evaluates the function for a range of X values and returns the result as a set of points.

type Function

type Function interface {
	// Eval evaluates a function for the value x.
	Eval(x float64) float64

	// EvalPoint evaluates a function for the value
	// x and returns the result as point.
	EvalPoint(x float64) *Point

	// EvalPoints evaluates the function count times
	// with values between fromX and toX. The result is
	// returned as a set of pints.
	EvalPoints(fromX, toX float64, count int) Points
}

Function is the standard interface the nmerical functions have to implement.

type LeastSquaresFunction

type LeastSquaresFunction struct {
	// contains filtered or unexported fields
}

LeastSquaresFunction is a function for approximation.

func NewLeastSquaresFunction

func NewLeastSquaresFunction(points Points) *LeastSquaresFunction

NewLeastSquaresFunction creates a new least squares function based on a set of points.

func (*LeastSquaresFunction) AppendPoint

func (lsf *LeastSquaresFunction) AppendPoint(x, y float64)

AppendPoint appends one point to the function.

func (*LeastSquaresFunction) AppendPoints

func (lsf *LeastSquaresFunction) AppendPoints(points Points)

AppendPoints appends a set of points to the function.

func (*LeastSquaresFunction) Eval

func (lsf *LeastSquaresFunction) Eval(x float64) float64

Eval evaluates the function for a given X value and returns the Y value.

func (*LeastSquaresFunction) EvalPoint

func (lsf *LeastSquaresFunction) EvalPoint(x float64) *Point

EvalPoint evaluates the function for a given X value and returns the result as a point.

func (*LeastSquaresFunction) EvalPoints

func (lsf *LeastSquaresFunction) EvalPoints(fromX, toX float64, count int) Points

EvalPoints evaluates the function for a range of X values and returns the result as a set of points.

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point is just one point in a 2D coordinate system. The values for x or x are read-only.

func MiddlePoint

func MiddlePoint(a, b *Point) *Point

MiddlePoint returns the middle point between two points.

func NewPoint

func NewPoint(x, y float64) *Point

NewPoint creates a new point.

func (Point) DistanceTo

func (p Point) DistanceTo(op *Point) float64

DistanceTo takes another point and calculates the geometric distance.

func (Point) IsInf

func (p Point) IsInf() bool

IsInf checks if x or y is infinite.

func (Point) IsNaN

func (p Point) IsNaN() bool

IsNaN checks if x or y is not a number.

func (Point) String

func (p Point) String() string

String returns the string representation of the coordinates.

func (Point) VectorTo

func (p Point) VectorTo(op *Point) *Vector

VectorTo returns the vector to another point.

func (Point) X

func (p Point) X() float64

X returns the x value of the point.

func (Point) Y

func (p Point) Y() float64

Y returns the y value of the point.

type Points

type Points []*Point

Points is just a set of points.

func NewPoints

func NewPoints(p ...*Point) Points

NewPoints creates a set of points.

func (Points) CubicSplineFunction

func (ps Points) CubicSplineFunction() *CubicSplineFunction

CubicSplineFunction returns a cubic spline function based on the points.

func (Points) LeastSquaresFunction

func (ps Points) LeastSquaresFunction() *LeastSquaresFunction

LeastSquaresFunction returns a least squares function based on the points.

func (Points) Len

func (ps Points) Len() int

Len returns the number of points in the set.

func (Points) Less

func (ps Points) Less(i, j int) bool

Less returns true if the point with index i is less then the one with index j. It first looks for X, then for Y.

func (Points) SearchNextIndex

func (ps Points) SearchNextIndex(x float64) int

SearchNextIndex searches the next index fo a given X value.

func (Points) String

func (ps Points) String() string

String returns the string representation of the set.

func (Points) Swap

func (ps Points) Swap(i, j int)

Swap swaps two points of the set.

func (Points) XAt

func (ps Points) XAt(idx int) float64

XAt returns the X value of the point at a given index.

func (Points) XDifference

func (ps Points) XDifference(idxA, idxB int) float64

XDifference returns the difference between two X values of the set.

func (Points) XInRange

func (ps Points) XInRange(x float64) bool

XInRange tests if an X value is in the range of X values of the set.

func (Points) YAt

func (ps Points) YAt(idx int) float64

YAt returns the Y value of the point at a given index.

func (Points) YDifference

func (ps Points) YDifference(idxA, idxB int) float64

YDifference returns the difference between two Y values of the set.

type PolynomialFunction

type PolynomialFunction struct {
	// contains filtered or unexported fields
}

PolynomialFunction is a polynomial function based on a number of coefficients.

func NewPolynomialFunction

func NewPolynomialFunction(coefficients []float64) *PolynomialFunction

NewPolynomialFunction creates a new polynomial function.

func (PolynomialFunction) Differentiate

func (pf PolynomialFunction) Differentiate() *PolynomialFunction

Differentiate differentiates the polynomial and returns the new polynomial.

func (PolynomialFunction) Eval

func (pf PolynomialFunction) Eval(x float64) float64

Eval evaluates the function for a given X value and returns the Y value.

func (PolynomialFunction) EvalPoint

func (pf PolynomialFunction) EvalPoint(x float64) *Point

EvalPoint evaluates the function for a given X value and returns the result as a point.

func (PolynomialFunction) EvalPoints

func (pf PolynomialFunction) EvalPoints(fromX, toX float64, count int) Points

EvalPoints evaluates the function for a range of X values and returns the result as a set of points.

func (PolynomialFunction) String

func (pf PolynomialFunction) String() string

String returns the string representation of the function as f(x) := 2.9x^3+x^2-3.3x+1.0.

type Vector

type Vector struct {
	// contains filtered or unexported fields
}

Vector represents a vector in a coordinate system. The values are read-only.

func AddVectors

func AddVectors(a, b *Vector) *Vector

AddVectors returns a new vector as addition of two vectors.

func NewVector

func NewVector(x, y float64) *Vector

NewVector creates a new vector.

func PointVector

func PointVector(a, b *Point) *Vector

PointVector returns the vector between two poins.

func ScaleVector

func ScaleVector(v *Vector, s float64) *Vector

ScaleVectors multiplies a vector with a float and returns the new vector.

func SubVectors

func SubVectors(a, b *Vector) *Vector

SubVectors returns a new vector as subtraction of two vectors.

func (Vector) Len

func (v Vector) Len() float64

Len returns the length of the vector.

func (Vector) String

func (v Vector) String() string

String returns the string representation of the vector.

func (Vector) X

func (v Vector) X() float64

X returns the x value of the vector.

func (Vector) Y

func (v Vector) Y() float64

Y returns the y value of the vector.

Jump to

Keyboard shortcuts

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