Exemplo n.º 1
0
func ExampleFullPrecision_diverging() {
	// Example 5.c, p. 49.
	betterRoot := func() iterate.BetterFunc {
		return func(x float64) float64 {
			return (8 - math.Pow(x, 5)) / 3
		}
	}
	x, err := iterate.FullPrecision(betterRoot(), 0, 20)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%.9f\n", x)
	fmt.Println(x, "(full precision)")
	// Output:
	// Maximum iterations reached
}
Exemplo n.º 2
0
func ExampleFullPrecision_converging() {
	// Example 5.d, p.49.
	betterRoot := func() iterate.BetterFunc {
		return func(x float64) float64 {
			return math.Pow(8-3*x, .2)
		}
	}
	x, err := iterate.FullPrecision(betterRoot(), 0, 30)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%.9f\n", x)
	fmt.Println(x, "(full precision)")
	// Output:
	// 1.321785627
	// 1.321785627117658 (full precision)
}
Exemplo n.º 3
0
func ExampleFullPrecision() {
	// Example 5.b, p. 48.
	betterRoot := func() iterate.BetterFunc {
		return func(x float64) float64 {
			return (8 - math.Pow(x, 5)) / 17
		}
	}
	x, err := iterate.FullPrecision(betterRoot(), 0, 20)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%.9f\n", x)
	fmt.Println(x, "(full precision)")
	// Output:
	// 0.469249878
	// 0.4692498784547387 (full precision)
}