Example #1
0
func Forward(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_forward((*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))
}
Example #2
0
// Diff computes the derivative of ff, returns derivative and an error
func Diff(dir DerivType, ff gslgo.F, x, h float64) (gslgo.Result, error) {
	var y, err C.double
	var ret C.int
	var gf C.gsl_function

	data := gslgo.GSLFuncWrapper{ff}
	gf = C.mkderivCB(unsafe.Pointer(&data))
	switch dir {
	case Central:
		ret = C.gsl_deriv_central(&gf, C.double(x), C.double(h), &y, &err)
	case Forward:
		ret = C.gsl_deriv_forward(&gf, C.double(x), C.double(h), &y, &err)
	case Backward:
		ret = C.gsl_deriv_backward(&gf, C.double(x), C.double(h), &y, &err)
	default:
		panic(errors.New("Unknown direction"))
	}
	if ret != 0 {
		return gslgo.Result{float64(y), float64(err)}, gslgo.Errno(ret)
	}
	return gslgo.Result{float64(y), float64(err)}, nil
}