## nr/

# bracket.pro

## topbracket

Numerical Recipes

`bracket, func, a, b, ax, bx, cx, fa, fb, fc [, _extra=_extra] [, verbose=verbose]`

This procedure attempts to bracket the minimum of a one dimensional function. A minimum is bracketed by three points ax, bx, cx, if: 1) bx is between ax and cx 2) f(b) < f(a) and f(b) < f(c) In this situation, provided the function is continuous, there is guaranteed to be a local minimum in between a and c.

The procedure is fairly robust in finding _some_ minimum, provided one exists. However, there is no guarantee that it will find the minimum closest to the starting location.

The algorithm is lifted from Numerical Recipes, with some attempt to make the base cases a bit clearer

The procedure is adapted from Numerical Recipes, 3rd ed., page 491. It always keeps track of three x values (abc). It repeatedly steps downhill. At each iteration, it approximates the 3 most recent points as a parabola, and extrapolates to the parabola's min (if it exists). If parabolic extrapolation doesn't work (because the points are nearly co-linear or concave down), it just takes a moderately larger step than last time. It stops when the function starts increasing again.

### Parameters

- func in required
A string giving the name of the 1D function to bracket. The function must have the following calling sequence: function func, x, _extra = extra it may declare extra keywords, which can be supplied to bracket and passed along to the function

- a in required
The first trial abscissa

- b in required
The second trial abscissa. The search for the minimum starts at a and b, and proceeds downhill. Note that (a-b) should be scaled, if possible, to match the scale of the wiggles in the function. This will help in finding the nearest minimum

- ax required
Named variable to hold the first abscissa of the bracket

- bx required
Named variable to hold the second abscissa of the bracket

- cx required
Named variable to hold the final abscissa of the bracket

- fa required
Named variable to hold f(ax)

- fb required
Named variable to hold f(bx)

- fc required
Named variable to hold f(cx)

### Keywords

- _extra in optional
Any extra keywords will be passed to FUNC

- verbose in optional
Set to an integer to control the amount of textual output to produce (see VERBIAGE procedure for details)

### Author information

- History:
June 2009: Written by Chris Beaumont August 2010: Added struct keyword. cnb.

## File attributes

Modifcation date: | Mon Aug 9 18:35:14 2010 |

Lines: | 260 |