brentMin: Brent's local minimisation

View source: R/brent.R

brentMinR Documentation

Brent's local minimisation

Description

Brent's local minimisation

Usage

brentMin(
  f,
  interval,
  lower = NA_real_,
  upper = NA_real_,
  tol = 1e-08,
  maxiter = 200L,
  trace = 0L
)

Arguments

f

A function to be minimised on an interval.

interval

A length-2 vector containing the end-points of the search interval.

lower

Scalar: the lower end point of the search interval. Not necessary if interval is provided.

upper

Scalar: the upper end point of the search interval. Not necessary if interval is provided.

tol

Small positive scalar: stopping criterion. The search stops when the distance between the current candidate and the midpoint of the bracket is smaller than the dynamic threshold 2 * (sqrt(DBL_EPSILON) * abs(x) + tol)

maxiter

Positive integer: the maximum number of iterations.

trace

Integer: 0, 1, or 2. Amount of tracing information on the optimisation progress printed. trace = 0 produces no output, trace = 1 reports the starting and final results, and trace = 2 provides detailed iteration-level output.

Details

This is an adaptation of the implementation by John Burkardt (currently available at [https://people.math.sc.edu/Burkardt/m_src/brent/brent.html](https://people.math.sc.edu/Burkardt/m_src/brent/brent.html)).

This function is similar to local_min or R_zeroin2-style logic, but with the following additions: the number of iterations is tracked, and the algorithm stops when the standard Brent criterion is met or if the maximum iteration count is reached. The code stores the approximate final bracket width in estim.prec, like in [uniroot()]. If the minimiser is pinned to an end point, estim.prec = NA.

There are no preliminary iterations, unlike [brentZero()].

TODO: add preliminary iterations.

Value

A list with the following elements:

root

Location of the minimum.

f.root

Function value at the minimuim location.

iter

Total iteration count used.

estim.prec

Estimate of the final bracket size.

Examples

f <- function (x) (x - 1/3)^2
brentMin(f, c(0, 1), tol = 0.0001)
brentMin(function(x) x^2*(x-1), lower = 0, upper = 10, trace = 1)

smoothemplik documentation built on Aug. 22, 2025, 1:11 a.m.