NAME

Math::Brent - Brent's single dimensional function minimisation, and Brent's zero finder.

SYNOPSIS

    use Math::Brent qw(Minimise1D);

    my $tolerance = 1e-7;
    my $itmax = 80;

    sub sinc {
      my $x = shift ;
      return $x ? sin($x)/$x: 1;
    }

    my($x, $y) = Minimise1D(1, 1, \&sinc, $tolerance, $itmax);

    print "Minimum is at sinc($x) = $y\n";

or

    use Math::Brent qw(BracketMinimum Brent);

    my $tolerance = 1e-7;
    my $itmax = 80;

    #
    # If you want to use the separate functions
    # instead of a single call to Minimise1D().
    #
    my($ax, $bx, $cx, $fa, $fb, $fc) = BracketMinimum($ax, $bx, \&sinc);
    my($x, $y) = Brent($ax, $bx, $cx, \&sinc, $tolerance, $itmax);

    print "Minimum is at sinc($x) = $y\n";

In either case the output will be Minimum is at sinc(4.4934094397196) = -.217233628211222

This module has implementations of Brent's method for one-dimensional minimisation of a function without using derivatives. This algorithm cleverly uses both the Golden Section Search and parabolic interpolation.

Anonymous subroutines may also be used as the function reference:

    my $cubic_ref = sub {my($x) = @_; return 6.25 + $x*$x*(-24 + $x*8));};

    my($x, $y) = Minimise1D(3, 1, $cubic_ref);
    print "Minimum of the cubic at $x = $y\n";

In addition to finding the minimum, there is also an implementation of the Van Wijngaarden-Dekker-Brent Method, used to find a function's root without using derivatives.

    use Math::Brent qw(Brentzero);

    my $tolerance = 1e-7;
    my $itmax = 80;

    sub wobble
    {
        my($t) = @_;
        return $t - cos($t);
    }

    #
    # Find the zero somewhere between .5 and 1.
    #
    $r = Brentzero(0.5, 1.0, \&wobble, $tolerance, $itmax);

EXPORT

Each function can be exported by name, or all may be exported by using the tag 'all'.

FUNCTIONS

The functions may be imported by name, or by using the export tag "all".

Minimise1D()

Provides a simple interface to the "BracketMinimum()" and "Brent()" routines.

Given a function, an initial guess for the function's minimum, and its scaling, this routine converges to the function's minimum using Brent's method.

    ($x, $y) = Minimise1D($guess, $scale, \&func);

The minimum is reached within a certain tolerance (defaulting 1e-7), and attempts to do so within a maximum number of iterations (defaulting to 100). You may override them by providing alternate values:

    ($x, $y) = Minimise1D($guess, $scale, \&func, 1.5e-8, 120);

BracketMinimum()

    ($ax, $bx, $cx, $fa, $fb, $fc) = BracketMinimum($ax, $bx);

Given a function reference \&func and distinct initial points $ax and $bx, this routine searches in the downhill direction and returns a list of the three points $ax, $bx, $cx which bracket the minimum of the function, along with the function values at those three points, $fa, $fb, $fc.

The points $ax, $bx, $cx may then be used in the function Brent().

Brent()

Given a function and a triplet of abcissas $ax, $bx, $cx, such that

1. $bx is between $ax and $cx, and
2. func($bx) is less than both func($ax) and func($cx)),

Brent() isolates the minimum to a fractional precision of about $tol using Brent's method.

A maximum number of iterations $itmax may be specified for this search - it defaults to 100. Returned is a list consisting of the abcissa of the minum and the function value there.

BUGS

Please report any bugs or feature requests via Github's issues link

AUTHOR

John A.R. Williams J.A.R.Williams@aston.ac.uk

John M. Gamble jgamble@cpan.org (current maintainer)

SEE ALSO

"Numerical Recipies: The Art of Scientific Computing" W.H. Press, B.P. Flannery, S.A. Teukolsky, W.T. Vetterling. Cambridge University Press. ISBN 0 521 30811 9.

Richard P. Brent, Algorithms for Minimization Without Derivatives

Professor (Emeritus) Richard Brent has a web page at http://maths-people.anu.edu.au/~brent/