예제 #1
0
파일: map_test.go 프로젝트: danieldk/par
func expensive(v float64) float64 {
	for i := 0; i < 100; i++ {
		v = math.J0(v)
	}

	return v
}
예제 #2
0
/*
Test evaluation of interpolation at x

EDGE CASES:
- test for linear extrapolation outside data bounds
*/
func TestSplineOuts(t *testing.T) {
	//Data represents Bessel function of 1st kind
	xs := Arange(0, 20, 500)
	ys := Arange(0, 20, 500)
	PPmap(math.J1, ys)

	bvd := MakeBiVariateData(xs, ys)
	spl := CubicSpline(bvd)

	for i, _ := range xs {
		yi := ys[i]
		xi := xs[i]
		if !areSimilar(yi, spl.F(xi)) {
			t.Error("Spline does not conform to yi = f(xi) rule")
		}
		if !areSimilar(spl.coeffs[i], spl.DF(xi)*(20.0/500.0)) {
			t.Error("Spline does not conform to Di*h = df(xi) rule")
		}
	}

	//Check integration over (0, 20) with closed-form answer
	relError := relativeError(1.0-math.J0(20.0), spl.Integral(0.0, 20.0))
	if relError > 1E-5 {
		t.Error("Spline did not integrate accurately enough. Error:", relError)
	}

}
예제 #3
0
func TestFindRoot1(t *testing.T) {
	out, conv := FindRoot(math.J0, 0.0, 4.0)
	if !conv {
		t.Error("FindRoot failed to converge.")
	} else {
		if math.Abs(out-2.4048255576957727) > 1E-14 {
			t.Error("FindRoot didn't compute the right value.")
			t.Error("Expected:", 2.4048255576957727)
			t.Error("Got:", out)
			t.Error("Evaluates to:", math.J0(out))
		}
	}
}
예제 #4
0
파일: j0f.go 프로젝트: barnex/fmath
// float32 version of math.J0
func J0(x float32) float32 {
	return float32(math.J0(float64(x)))
}