The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

  Math::Brent - Single Dimensional Function Minimisation

SYNOPSIS

    use Math::Brent qw(FindMinima BracketMinimum Brent Minimise1D);
    my ($x,$y)=Minimise1D($guess,$scale,\&func,$tol,$itmax);
    my ($ax,$bx,$cx,$fa,$fb,$fc)=BracketMinimum($ax,$bx,$cx,\&func);
    my ($x,$y)=Brent($ax,$bx,$cx,\&func,$tol,$itmax);

DESCRIPTION

This is an implementation of Brents method for One-Dimensional minimisation of a function without using derivatives. This algorithm cleverly uses both the Golden Section Search and parabolic interpolation.

The main function Brent, given a function reference \&func and a bracketing triplet of abcissas $ax, $bx, $cx (such that $bx is between $ax and $cx and func($bx) is less than both func($ax) and func($cx)), isolates the minimum to a fractional precision of about $tol using Brents method. A maximum number of iterations $itmax may be specified for this search - it defaults to 100. Returned is an array consisting of the abcissa of the minum and the function value there.

The function BracketMinimum, given a function \&func and distinct initial points $ax and $bx searches in the downhill direction (defined by the function as evaluated at the initial points) and returns an array of the three points $ax, $bx, $cx which bracket the minimum of the function and the function values at those points.

The function Minimise1D provides a simple interface to the above two routines. Given a function \&func, an initial guess for its minimum, and its scaling ($guess,$scale) this routine isolates the minimum to a fractional precision of about $tol using Brents method. A maximum number of iterations $itmax may be specified for this search - it defaults to 100. It returns an array consisting of the abcissa of the minum and the function value there.

EXAMPLE

    use Math::Brent qw(Minimise1D);
    sub func {
      my $x=shift ;
      return $x ? sin($x)/$x: 1;
    }
   my ($x,$y)=Minimise1D(1,1,\&func,1e-7);
   print "Minimum is func($x)=$y\n";

produces the output

    Minimum is func(5.236068)=-.165388470697432
    

HISTORY

$Log: Brent.pm,v $ Revision 1.1 1995/12/26 10:06:36 willijar Initial revision

BUGS

Let me know of any problems.

AUTHOR

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

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.