Status: last sync with master - 12/19/2019
The license follows GPLv3 (As per the source).
The method names have been stripped off of 'gsl_xxxxx_' (e.g. gsl_sf_poch_e() will become Poch_e(), gsl_integration_fixed() will become Fixed()) as it should be known already (not only was it handful to type) that it is GSL.
Machine and Math constants have been renamed to match that of what Golang's naming convention in math package looks like.
ggsl.Function is an interface that implements:
type Function interface {
Evaluate(x float64) float64
}
This is the most basic type, as all packages would use this as much as possible, instead of func(float64) float64 (we'd love to have the freedom to use struct fields, embedding, etc.).
- Qag(f ggsl.Function, a, b, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64, q integration.QKFunction) err.GSLError
- Qags(f ggsl.Function, a, b, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64) err.GSLError
- Qagi(f ggsl.Function, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64) err.GSLError
- Qagil(f ggsl.Function, b, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64) err.GSLError
- Qagiu(f ggsl.Function, a, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64) err.GSLError
- Qagp(f ggsl.Function, pts []float64, npts int, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64, q integration.QKFunction) err.GSLError
- Qawc(f ggsl.Function, a, b, c, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64) err.GSLError
- Qaws(f ggsl.Function, a, b float64, t *QAWSTable, epsabs, epsrel float64, limit int, workspace *Workspace, result, abserr *float64) err.GSLError
- Qawo(f ggsl.Function, a, epsabs, epsrel float64, limit int, workspace *Workspace, wf *QAWOTable, result, abserr *float64) err.GSLError
- Qawf(f ggsl.Function, a, epsabs float64, limit int, workspace, cycle_workspace *Workspace, wf *QAWOTable, result, abserr *float64) err.GSLError
The low-level integration rules in ggsl are implementing:
type QKFunction func(f gsl.Function, a, b float64, result, abserr, defabs, resabs *float64)
And has the following (abscissae of the N-point kronrod rule):
- Qk15
- Qk21
- Qk31
- Qk41
- Qk51
- Qk61
import (
integ "github.com/jtejido/ggsl/integration"
"math"
)
type f1 struct {
alpha float64
}
func (f f1) Evaluate(x float64) float64 {
return math.Pow(x, f.alpha) * math.Log(1.0/x)
}
func main() {
alpha := 2.6
f := &f1{alpha}
workspace, _ := integ.NewWorkspace(1000)
var result, abserr float64
err := Qag(fc, 0.0, 1.0, 0.0, 1e-10, w.limit, w, &result, &abserr, integ.Qk15)
fmt.Println(err)
}
- Romberg(f gsl.Function, a, b, epsabs, epsrel float64, result *float64, neval *int, w *RombergWorkspace) err.GSLError
type f_sin struct {}
func (f f_sin) Evaluate(x float64) float64 {
return math.Sin(x)
}
func main() {
var result float64
var neval int
w, _ := integ.NewRombergWorkspace(20)
f := f_sin{}
err := integ.Romberg(&f, 0.0, gsl.PiOver2, 0.0, 1e-10, &result, &neval, w)
fmt.Println(err)
}
- GLFixed(f ggsl.Function, a, b float64, t *GLFixedTable) float64
- GLFixedPoint(a, b float64, i int, xi, wi *float64, t *GLFixedTable) err.GSLError
type f_sin struct {}
func (f f_sin) Evaluate(x float64) float64 {
return math.Sin(x)
}
func main() {
f := &f_sin{}
a := 0.0
b := gsl.Pi
var result float64
tbl, _ := integ.NewGLFixedTable(n)
result = integ.GLFixed(f, a, b, tbl)
}
- Fixed(f gsl.Function, result *float64, w *FixedWorkspace) err.GSLError
The table below lists the weighting functions currently supported. They implement:
type FixedType interface {
check(n int, params *fixedParams) err.GSLError
init(n int, diag, subdiag []float64, params *fixedParams) err.GSLError
}
which is used internally by the integration method.
- Legendre
- ChebyshevType1
- Gegenbauer
- Jacobi
- Laguerre
- Hermite
- Exponential
- Rational
- ChebyshevType2
type myfn1 struct {}
func (f myfn1) Evaluate(x float64) float64 {
return math.Exp(-x - x*x)
}
func main() {
var t integ.ChebyshevType2
n := 200
f := &myfn1{}
w, _ := integ.NewFixedWorkspace(t, n, 1.2, 2.6, 0.0, 0.0)
var result float64
err := integ.Fixed(f2, &result, w)
fmt.Println(err)
}
All Special Functions are implemented except LegendreP (requires total reimplementation) and Mathieu functions (requires implementation of GSL's linear algebra).
Similarly to GSL, you can set your own error handler to prevent programs from terminating (see err package):
func initTesting() {
// If you'd like to know where it catches flu.
err.SetErrorHandler(myErrorHandler)
// or just disable it
err.SetErrorHandlerOff()
os.Setenv("GSL_TEST_VERBOSE", "1") // this is used for printing verbose test results
}
func myErrorHandler(reason, file string, line, gsl_errno int) {
fmt.Printf("(error expected [%s:%d: %s (%d)])\n", file, line, reason, gsl_errno)
}