Attached is a simple program to implement Brent's method of finding a root
of a non-linear equation. It uses a combination of the bisection and secant
methods, and inverse quadratic interpolation, to provide
guaranteedconvergence to a root, using the best possible method at
each step. My
program is just a Maxima translation of the C program given in "Numerical
Recipes", which can be found at http://www.nrbook.com/b/bookcpdf/c9-3.pdf.
Here's how you use it:
fpprec:20;
float2bf:true;
bzero(lambda([x],log(x)-1/x,0.1,1.0,10^-18);
bzero(lambda([x],x^2-cos(x),0.1,2.0,10^-18);
The general call is bzero(f,x1,x2,tol), where f is the function to be
"solved", x1 and x2 are two values which bracket the root (so their function
values must have opposite sign), and tol is the tolerance, or accuracy, of
the required solution.
Your constructive criticism is welcome.
cheers,
Alasdair
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bzero.mac
Type: application/octet-stream
Size: 1317 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20070507/736820cc/attachment.obj