Example #1
0
func TestThreePoint(t *testing.T) {
	test_cases := diff_test[0].XYs()
	for i, c := range test_cases {
		if !util.Tolerance(ThreePoint(diff_test[0].f, c.X), c.Y, tol) {
			t.Errorf("Three point out of tolerance. i = %v, diff = %.6f",
				i, math.Abs(c.Y-c.X))
		}
	}
}
Example #2
0
func TestCentral9(t *testing.T) {
	test_cases := diff_test[8].XYs()
	algo := NewCentral(diff_test[8].f)
	for i, c := range test_cases {
		if !util.Tolerance(algo.Compute(c.X), c.Y, tol) {
			t.Errorf("Central out of tolerance. Function 9: i = %v, diff = %.6f, error = %.6f",
				i, math.Abs(c.Y-algo.Compute(c.X)), algo.er)
		}
	}
}
Example #3
0
File: newton.go Project: Arrow/nm
func (n *Newton) Compute(x0 float64) (x float64) {
	f := n.fn.Function()
	fp := n.fn.Diff()
	p0 := x0
	p := p0
	for i := 0; i < n.Max_Iter; i++ {
		p = p0 - f(p0)/fp(p0)
		if util.Tolerance(p, p0, n.Tol) {
			return p
		}
	}
	p0 = p
	return p
}