Пример #1
0
Файл: psi.go Проект: swook/gogsl
func Psi_n_xg0(n int, x float64, result *Result) error {
	if n == 0 {
		return Psi_e(x, result)
	}

	/* Abramowitz + Stegun 6.4.10 */
	ln_nf, hzeta := new(Result), new(Result)
	stat_hz := Hzeta_e(float64(n+1), x, hzeta)
	stat_nf := Lnfact_e(n, ln_nf)
	stat_e := Exp_mult_err_e(ln_nf.val, ln_nf.err, hzeta.val, hzeta.err, result)
	if gsl.IsEven(n) {
		result.val = -result.val
	}
	return err.Select(stat_e, stat_nf, stat_hz)
}
Пример #2
0
Файл: psi.go Проект: swook/gogsl
func Psi_n_e(n int, x float64, result *Result) error {
	if n == 0 {
		return Psi_e(x, result)
	} else if n == 1 {
		return Psi_1_e(x, result)
	} else if n < 0 || x <= 0.0 {
		return DomainError(result)
	}

	ln_nf, hzeta := new(Result), new(Result)
	stat_hz := Hzeta_e(float64(n+1), x, hzeta)
	stat_nf := Lnfact_e(n, ln_nf)
	stat_e := Exp_mult_err_e(ln_nf.val, ln_nf.err, hzeta.val, hzeta.err, result)
	if gsl.IsEven(n) {
		result.val = -result.val
	}
	return err.Select(stat_e, stat_nf, stat_hz)
}
Пример #3
0
func Hazard_e(x float64, result *Result) error {
	if x < 25.0 {
		result_ln_erfc := new(Result)
		stat_l := Log_erfc_e(x/gsl.M_SQRT2, result_ln_erfc)
		lnc := -0.22579135264472743236 /* ln(sqrt(2/pi)) */
		arg := lnc - 0.5*x*x - result_ln_erfc.val
		stat_e := Exp_e(arg, result)
		result.err += 3.0 * (1.0 + math.Abs(x)) * gsl.DBL_EPSILON * math.Abs(result.val)
		result.err += math.Abs(result_ln_erfc.err * result.val)
		return err.Select(stat_l, stat_e)
	} else {
		ix2 := 1.0 / (x * x)
		corrB := 1.0 - 9.0*ix2*(1.0-11.0*ix2)
		corrM := 1.0 - 5.0*ix2*(1.0-7.0*ix2*corrB)
		corrT := 1.0 - ix2*(1.0-3.0*ix2*corrM)
		result.val = x / corrT
		result.err = 2.0 * gsl.DBL_EPSILON * math.Abs(result.val)
		return err.SUCCESS
	}
	return err.FAILURE
}