示例#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))
		}
	}
}
示例#2
0
文件: central_test.go 项目: Arrow/nm
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)
		}
	}
}
示例#3
0
文件: newton.go 项目: 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
}