chickadee » math » fpbracketed-root

fpbracketed-root f a bprocedure
f
(flonum -> flonum)
a
flonum
b
flonum

Uses the Brent-Dekker method to find a floating-point root of f (a flonum x for which (f x) is very near a zero crossing) between a and b. The values (f a) and (f b) must have opposite signs, but a and b may be in any order.

Examples:

> (define (f x) (+ 1.0 (* (+ x 3.0) (sqr (- x 1.0)))))
> (define x0 (fpbracketed-root f -4.0 2.0))
> (f (fpprev x0))
-7.105427357601002e-15
> (f x0)
6.661338147750939e-16
> (fpbracketed-root f -1.0 2.0)
+nan.0

Caveats:

  • There is no guarantee that fpbracketed-root will find any particular root. Moreover, future updates to its implementation could make it find different ones.
  • There is currently no guarantee that it will find the closest x to an exact root.
  • It currently runs for at most 5000 iterations.

It usually requires far fewer iterations, especially if the initial bounds a and b are tight.