Exemplo n.º 1
0
func Qawc(f *gogsl.GslFunction, a float64, b float64, c float64, epsabs float64, epsrel float64, limit int, workspace *GslIntegrationWorkspace) (int32, float64, float64) {
	var _outptr_8 C.double
	var _outptr_9 C.double
	gogsl.InitializeGslFunction(f)
	_result := int32(C.gsl_integration_qawc((*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(a), C.double(b), C.double(c), C.double(epsabs), C.double(epsrel), C.size_t(limit), (*C.gsl_integration_workspace)(unsafe.Pointer(workspace.Ptr())), &_outptr_8, &_outptr_9))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_8)), *(*float64)(unsafe.Pointer(&_outptr_9))
}
Exemplo n.º 2
0
func Backward(f *gogsl.GslFunction, x float64, h float64) (int32, float64, float64) {
	var _outptr_3 C.double
	var _outptr_4 C.double
	gogsl.InitializeGslFunction(f)
	_result := int32(C.gsl_deriv_backward((*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(x), C.double(h), &_outptr_3, &_outptr_4))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_3)), *(*float64)(unsafe.Pointer(&_outptr_4))
}
Exemplo n.º 3
0
func Qawf(f *gogsl.GslFunction, a float64, epsabs float64, limit int, workspace *GslIntegrationWorkspace, cycleWorkspace *GslIntegrationWorkspace, wf *GslIntegrationQawoTable) (int32, float64, float64) {
	var _outptr_7 C.double
	var _outptr_8 C.double
	gogsl.InitializeGslFunction(f)
	_result := int32(C.gsl_integration_qawf((*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(a), C.double(epsabs), C.size_t(limit), (*C.gsl_integration_workspace)(unsafe.Pointer(workspace.Ptr())), (*C.gsl_integration_workspace)(unsafe.Pointer(cycleWorkspace.Ptr())), (*C.gsl_integration_qawo_table)(unsafe.Pointer(wf.Ptr())), &_outptr_7, &_outptr_8))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_7)), *(*float64)(unsafe.Pointer(&_outptr_8))
}
Exemplo n.º 4
0
func Qagp(f *gogsl.GslFunction, pts []float64, npts int, epsabs float64, epsrel float64, limit int, workspace *GslIntegrationWorkspace) (int32, float64, float64) {
	var _outptr_7 C.double
	var _outptr_8 C.double
	gogsl.InitializeGslFunction(f)
	_slice_header_1 := (*reflect.SliceHeader)(unsafe.Pointer(&pts))
	_result := int32(C.gsl_integration_qagp((*C.gsl_function)(unsafe.Pointer(f.CPtr())), (*C.double)(unsafe.Pointer(_slice_header_1.Data)), C.size_t(npts), C.double(epsabs), C.double(epsrel), C.size_t(limit), (*C.gsl_integration_workspace)(unsafe.Pointer(workspace.Ptr())), &_outptr_7, &_outptr_8))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_7)), *(*float64)(unsafe.Pointer(&_outptr_8))
}
Exemplo n.º 5
0
func Qng(f *gogsl.GslFunction, a float64, b float64, epsabs float64, epsrel float64) (int32, float64, float64, int) {
	var _outptr_5 C.double
	var _outptr_6 C.double
	var _outptr_7 C.size_t
	gogsl.InitializeGslFunction(f)
	_result := int32(C.gsl_integration_qng((*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(a), C.double(b), C.double(epsabs), C.double(epsrel), &_outptr_5, &_outptr_6, &_outptr_7))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_5)), *(*float64)(unsafe.Pointer(&_outptr_6)), *(*int)(unsafe.Pointer(&_outptr_7))
}
Exemplo n.º 6
0
func Cquad(f *gogsl.GslFunction, a float64, b float64, epsabs float64, epsrel float64, workspace *GslIntegrationCquadWorkspace) (int32, float64, float64, int) {
	var _outptr_6 C.double
	var _outptr_7 C.double
	var _outptr_8 C.size_t
	gogsl.InitializeGslFunction(f)
	_result := int32(C.gsl_integration_cquad((*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(a), C.double(b), C.double(epsabs), C.double(epsrel), (*C.gsl_integration_cquad_workspace)(unsafe.Pointer(workspace.Ptr())), &_outptr_6, &_outptr_7, &_outptr_8))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_6)), *(*float64)(unsafe.Pointer(&_outptr_7)), *(*int)(unsafe.Pointer(&_outptr_8))
}
Exemplo n.º 7
0
func TestDeriv(t *testing.T) {

	f := &gogsl.GslFunction{
		Function: F,
	}
	gogsl.InitializeGslFunction(f)

	fmt.Printf("f(x) = x^(3/2)\n")
	_, res, err := deriv.Central(f, 2.0, 1e-8)
	fmt.Printf("x = 2.0\n")
	fmt.Printf("f'(x) = %.10f +/- %.10f\n", res, err)
	fmt.Printf("exact = %.10f\n\n", 1.5*math.Sqrt(2.0))

	_, res, err = deriv.Forward(f, 0.0, 1e-8)
	fmt.Printf("x = 0.0\n")
	fmt.Printf("f'(x) = %.10f +/- %.10f\n", res, err)
	fmt.Printf("exact = %.10f\n\n", 0.0)
}
Exemplo n.º 8
0
func TestChebyshev(t *testing.T) {

	var n int = 10000

	cs := chebyshev.Alloc(40)

	f := &gogsl.GslFunction{
		Function: F,
	}
	gogsl.InitializeGslFunction(f)
	chebyshev.Init(cs, f, 0.0, 1.0)

	for i := 0; i < n; i++ {
		x := float64(i) / float64(n)
		r10 := chebyshev.EvalN(cs, 10, x)
		r40 := chebyshev.Eval(cs, x)
		fmt.Printf("%g %g %g %g\n", x, f.Eval(x), r10, r40)
	}
}
Exemplo n.º 9
0
func TestMin(t *testing.T) {
	var maxIter int = 100
	var m float64 = 2.0
	var mExpected float64 = math.Pi
	var a float64 = 0.0
	var b float64 = 6.0

	var iter int

	f := &gogsl.GslFunction{
		Function: Fn1,
	}
	gogsl.InitializeGslFunction(f)

	T := min.GSL_MIN_FMINIMIZER_BRENT
	s := min.FminimizerAlloc(T)
	min.FminimizerSet(s, f, m, a, b)

	fmt.Printf("using %s method\n", min.FminimizerName(s))
	fmt.Printf("%5s [%9s, %9s] %9s %10s %9s\n", "iter", "lower", "upper", "min", "err", "err(est)")
	fmt.Printf("%5d [%.7f, %.7f] %.7f %+.7f %.7f\n", iter, a, b, m, m-mExpected, b-a)

	for {

		iter += 1
		min.FminimizerIterate(s)

		m = min.FminimizerXMinimum(s)
		a = min.FminimizerXLower(s)
		b = min.FminimizerXUpper(s)

		status := gogsl.GslError(min.TestInterval(a, b, 0.001, 0.0))
		if status == gogsl.GSL_SUCCESS {
			fmt.Printf("Converged:\n")
		}

		fmt.Printf("%5d [%.7f, %.7f] %.7f %+.7f %.7f\n", iter, a, b, m, m-mExpected, b-a)

		if status != gogsl.GSL_CONTINUE || iter >= maxIter {
			break
		}
	}
}
Exemplo n.º 10
0
func TestRoot(t *testing.T) {
	var maxIter int = 100
	var rExpected float64 = math.Sqrt(5.0)
	var xLo float64 = 0.0
	var xHi float64 = 5.0

	qp := &QuadraticParams{
		A: 1.0,
		B: 0.0,
		C: -5.0,
	}

	f := &gogsl.GslFunction{
		Function: Quadratic,
		Params:   qp,
	}
	gogsl.InitializeGslFunction(f)

	T := root.GSL_ROOT_FSOLVER_BRENT
	s := root.FsolverAlloc(T)
	root.FsolverSet(s, f, xLo, xHi)
	fmt.Printf("using %s method\n", root.FsolverName(s))
	fmt.Printf("%5s [%9s, %9s] %9s %10s %9s\n",
		"iter", "lower", "upper", "root",
		"err", "err(est)")
	iter := 0
	for {
		iter += 1
		root.FsolverIterate(s)
		r := root.FsolverRoot(s)
		xLo = root.FsolverXLower(s)
		xHi = root.FsolverXUpper(s)
		status := gogsl.GslError(root.TestInterval(xLo, xHi, 0, 0.001))
		if status == gogsl.GSL_SUCCESS {
			fmt.Printf("Converged:\n")
		}
		fmt.Printf("%5d [%.7f, %.7f] %.7f %+.7f %.7f\n",
			iter, xLo, xHi, r, r-rExpected, xHi-xLo)
		if status != gogsl.GSL_CONTINUE || iter >= maxIter {
			break
		}
	}
}
Exemplo n.º 11
0
Arquivo: root.go Projeto: dtromb/gogsl
func FsolverSet(s *GslRootFsolver, f *gogsl.GslFunction, xLower float64, xUpper float64) int32 {
	gogsl.InitializeGslFunction(f)
	return int32(C.gsl_root_fsolver_set((*C.gsl_root_fsolver)(unsafe.Pointer(s.Ptr())), (*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(xLower), C.double(xUpper)))
}
Exemplo n.º 12
0
func Init(cs *GslChebSeries, f *gogsl.GslFunction, a float64, b float64) int32 {
	gogsl.InitializeGslFunction(f)
	return int32(C.gsl_cheb_init((*C.gsl_cheb_series)(unsafe.Pointer(cs.Ptr())), (*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(a), C.double(b)))
}
Exemplo n.º 13
0
func Glfixed(f *gogsl.GslFunction, a float64, b float64, t *GslIntegrationGlfixedTable) float64 {
	gogsl.InitializeGslFunction(f)
	return float64(C.gsl_integration_glfixed((*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(a), C.double(b), (*C.gsl_integration_glfixed_table)(unsafe.Pointer(t.Ptr()))))
}
Exemplo n.º 14
0
Arquivo: min.go Projeto: dtromb/gogsl
func FminimizerSetWithValues(s *GslMinFminimizer, f *gogsl.GslFunction, xMinimum float64, fMinimum float64, xLower float64, fLower float64, xUpper float64, fUpper float64) int32 {
	gogsl.InitializeGslFunction(f)
	return int32(C.gsl_min_fminimizer_set_with_values((*C.gsl_min_fminimizer)(unsafe.Pointer(s.Ptr())), (*C.gsl_function)(unsafe.Pointer(f.CPtr())), C.double(xMinimum), C.double(fMinimum), C.double(xLower), C.double(fLower), C.double(xUpper), C.double(fUpper)))
}