## Stata 15 help for minbound

```
Title

[R] minbound -- Minimize a scalar function on a range

Syntax

minbound progname, range(#1 #2) [ from(#) arguments(str) tolerance(#)
iterate(#) missing trace ]

Description

minbound minimizes a smooth scalar function on a range using function
values only (Brent 1973).  The function progname should be implemented as
an rclass program; it should accept as the first argument the value x
with respect to which the function is to be evaluated, as well as
optional other arguments transferred with the option arguments(); and it
should return the function value in r(fx).

Options

range(#1 #2) is not optional; it specifies the range over which the
function is to be minimized.  #1 and #2 may be literals or
expressions and should be separated by a comma or space.

from(#) specifies an initial value.  It should satisfy the range
conditions.

arguments(str) specifies optional arguments for progname.  Multiple
arguments are separated by spaces.

tolerance(#) specifies the tolerance for the minimizer x.  The default is
1e-5.

iterate(#) specifies the maximum number of iterations.  The default is
100.

missing specifies that missing values returned by progname be treated as
ordinary values (that is, larger than any nonmissing values).  The
default behavior is that missing function values are an error.

trace displays an iteration trace.

Examples

We want to minimize the quadratic function f(x) = x^2.

return scalar fx = (`1')^2
end

. minbound quadratic, range(-4 4) from(2) trace

Note: We suggest that you code the program quadratic somewhat less
concisely as

version 9
args x
return scalar fx = (`x')^2
end

We can also write a more general function that minimizes a general
quadratic function ax^2+bx+c with respect to x.

version 9
args x a b c
return scalar fx = `a'*(`x')^2 + `b'*`x' + `c'
end

To minimize 2x^2-3x+1 with respect to x on [-100,100], you type

. minbound quadratic2, range(-100 100) arg(2 -3 1)

We can also minimize the inverted U-shaped parabola -2x^2+3x+1 with
respect to x on [-1,1] -- the minimizer is at the boundary of the range,

. minbound quadratic2, range(-1 1) arg(-2 3 1)

Stored results

minbound stores the following in r():

r(x)   minimizer
r(fx)  function value in x
r(gx)  first-order derivative of f with respect to x
r(hx)  second-order derivative of f with respect to x

References

Brent, R. P. 1973.  Algorithms for Minimization without Derivatives.
Englewood Cliffs, NJ: Prentice Hall.  (Reprinted in paperback by
Dover Publications, Mineola, NY, January 2002.)

Press, W. H., B. P. Flannery, S. A. Teukolsky, and W. T. Vetterling.
1989.  Numerical Recipes in Pascal: The Art of Scientific Computing.
Cambridge: Cambridge University Press.

```