Пример #1
0
Файл: dual.go Проект: shogg/math
func hermite(f F, df DF, v0, v1 Vec3) [2]Vec3 {

	lambda := func(t float64) float64 {
		return f(v0.Mul(1.0 - t).Add(v1.Mul(t)))
	}

	t0 := root.Brent(lambda, 0.0, 1.0)
	x0 := v0.Mul(1.0 - t0).Add(v1.Mul(t0))

	return [2]Vec3{x0, df(x0)}
}
Пример #2
0
func TestBrent(t *testing.T) {

	// f(x) = e^-x * log(x)
	f := func(x float64) float64 {
		return math.Pow(math.E, -x) * math.Log(x)
	}

	x0 := root.Brent(f, 0.05, 1.7)

	if x0 != 1.0 {
		t.Errorf("Root at 1.0 expected, was: %f", x0)
	}
}