solve

package
v0.0.0-...-99b389f Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2016 License: MIT Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Brent

func Brent(fn Diffable, x_lo, x_hi, epsAbs, epsRel float64) (float64, error)

func DebugReport

func DebugReport(on bool)

if true, print solution progress

func Derivative

func Derivative(fn vec.FnDim0, v vec.Vector, i int, h, epsabs float64) (float64, error)

Numerical central derivative of fn(v) with respect to v_i within tolerance epsabs. h is the initial step size.

func Gradient

func Gradient(fn vec.FnDim0, v vec.Vector, h, epsabs float64) (vec.Vector, error)

Gradient of fn at v within tolerance epsabs. h is the initial step size.

func Iterative

func Iterative(stages []DiffSystem, start []vec.Vector, epsAbs, epsRel []float64, accept func([]vec.Vector)) ([]vec.Vector, error)

Solve each system in `stages` iteratively, starting with stages[0] and proceeding upward. After solving each stage, check if all previous stages are still solved. If they are not, return to stages[0]. `accept` should take a []Vector representing the current state of each stage and store it; this allows the stages to be coupled.

func MatrixToGSL

func MatrixToGSL(m []vec.Vector, target *C.gsl_matrix)

Convert m to GSL format.

func MultiDim

func MultiDim(fn DiffSystem, start vec.Vector, epsAbs, epsRel float64) (vec.Vector, error)

Multidimensional root-finder. Implemented by providing an interface to GSL implementation of Powell's Hybrid method (gsl_multiroot_fdfsolver_hybridsj). Callback passing through cgo follows the model at: http://stackoverflow.com/questions/6125683/call-go-functions-from-c/6147097#6147097

func OneDimDerivative

func OneDimDerivative(fn Func1D, x, h, epsAbs float64) (float64, error)

Derivative of `fn` at `x` to precision `espAbs`; use initial step size `h`

func OneDimDiffRoot

func OneDimDiffRoot(f Func1D, start, epsAbs, epsRel float64) (float64, error)

Find a root for `f` near `start` using a first-derivative based solver (the derivative is found automatically).

func Simple2ndDiff

func Simple2ndDiff(f Func1D, x0, h float64) (float64, error)

Three-point algorithm for second derivative of f(x) at x0. Error ~ h^2.

func SimpleFdf

func SimpleFdf(F vec.FnDim0, Df vec.FnDim1) vec.FnDim0_1

Create a function which returns the combined result of F(v) and Df(v).

func SimpleMixed2ndDiff

func SimpleMixed2ndDiff(f func(x, y float64) (float64, error), x0, y0, hx, hy float64) (float64, error)

Four-point algorithm for mixed partial second derivative. Error ~ hf^2*hg^2.

func VecFromGSL

func VecFromGSL(v *C.gsl_vector) vec.Vector

Convert v back to Go format.

func VecToGSL

func VecToGSL(v vec.Vector, target *C.gsl_vector)

Convert v to GSL format.

Types

type DiffSystem

type DiffSystem struct {
	F         vec.FnDim1
	Df        func(vec.Vector) ([]vec.Vector, error)
	Fdf       func(vec.Vector) (vec.Vector, []vec.Vector, error)
	NumFuncs  int // length of F output vector and Df slice
	Dimension int // length of input vectors and Df output vector
}

System of functions plus first derivatives.

func Combine

func Combine(fns []Diffable) DiffSystem

Combine fns into one function, suitable for passing to MultiDim. All funcs passed in must have the same dimension.

type Diffable

type Diffable struct {
	F         vec.FnDim0
	Df        vec.FnDim1
	Fdf       vec.FnDim0_1
	Dimension int // length of vectors
}

Function plus first derivatives.

func SimpleDiffable

func SimpleDiffable(F vec.FnDim0, dimension int, h, epsabs float64) Diffable

Create a diffable from F using numerical differentiation. h gives the initial differentiation step size and epsabs gives the error tolerance.

type Func1D

type Func1D func(float64) (float64, error)

Jump to

Keyboard shortcuts

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