e04bb searches for a minimum, in a given finite interval, of a continuous function of a single variable, using function and first derivative values. The method (based on cubic interpolation) is intended for functions which have a continuous first derivative (although it will usually work if the derivative has occasional discontinuities).

# Syntax

C# |
---|

public static void e04bb( E04..::..E04BB_FUNCT funct, ref double e1, ref double e2, ref double a, ref double b, ref int maxcal, out double x, out double f, out double g, out int ifail ) |

Visual Basic |
---|

Public Shared Sub e04bb ( _ funct As E04..::..E04BB_FUNCT, _ ByRef e1 As Double, _ ByRef e2 As Double, _ ByRef a As Double, _ ByRef b As Double, _ ByRef maxcal As Integer, _ <OutAttribute> ByRef x As Double, _ <OutAttribute> ByRef f As Double, _ <OutAttribute> ByRef g As Double, _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void e04bb( E04..::..E04BB_FUNCT^ funct, double% e1, double% e2, double% a, double% b, int% maxcal, [OutAttribute] double% x, [OutAttribute] double% f, [OutAttribute] double% g, [OutAttribute] int% ifail ) |

F# |
---|

static member e04bb : funct : E04..::..E04BB_FUNCT * e1 : float byref * e2 : float byref * a : float byref * b : float byref * maxcal : int byref * x : float byref * f : float byref * g : float byref * ifail : int byref -> unit |

#### Parameters

- funct
- Type: NagLibrary..::..E04..::..E04BB_FUNCTYou must supply this method to calculate the values of $F\left(x\right)$ and $\frac{dF}{dx}$ at any point $x$ in $\left[a,b\right]$.It should be tested separately before being used in conjunction with e04bb.
A delegate of type E04BB_FUNCT.

- e1
- Type: System..::..Double%
*On entry*: the relative accuracy to which the position of a minimum is required. (Note that, since e1 is a relative tolerance, the scaling of $x$ is automatically taken into account.)e1 should be no smaller than $2\epsilon $, and preferably not much less than $\sqrt{\epsilon}$, where $\epsilon $ is the machine precision.

- e2
- Type: System..::..Double%
*On entry*: the absolute accuracy to which the position of a minimum is required. e2 should be no smaller than $2\epsilon $.

- a
- Type: System..::..Double%
*On entry*: the lower bound $a$ of the interval containing a minimum.*On exit*: an improved lower bound on the position of the minimum.

- b
- Type: System..::..Double%
*On entry*: the upper bound $b$ of the interval containing a minimum.*On exit*: an improved upper bound on the position of the minimum.

- maxcal
- Type: System..::..Int32%
*On entry*: the maximum number of calls of funct to be allowed.*Constraint*: ${\mathbf{maxcal}}\ge 2$. (Few problems will require more than $20$.)*On exit*: the total number of times that funct was actually called.

- x
- Type: System..::..Double%
*On exit*: the estimated position of the minimum.

- f
- Type: System..::..Double%
*On exit*: the function value at the final point given in x.

- g
- Type: System..::..Double%
*On exit*: the value of the first derivative at the final point in x.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

e04bb is applicable to problems of the form:

when the first derivative $\frac{dF}{dx}$ can be calculated. The method normally computes a sequence of $x$ values which tend in the limit to a minimum of $F\left(x\right)$ subject to the given bounds. It also progressively reduces the interval $\left[a,b\right]$ in which the minimum is known to lie. It uses the safeguarded cubic-interpolation method described in Gill and Murray (1973).

$$\mathrm{Minimize}\u200aF\left(x\right)\text{\hspace{1em} subject to \hspace{1em}}a\le x\le b$$ |

You must supply a funct to evaluate $F\left(x\right)$ and $\frac{dF}{dx}$. The parameters e1 and e2 together specify the accuracy

to which the position of the minimum is required. Note that funct is never called at a point which is closer than $\mathit{Tol}\left(x\right)$ to a previous point.

$$\mathit{Tol}\left(x\right)={\mathbf{e1}}\times \left|x\right|+{\mathbf{e2}}$$ |

If the original interval $\left[a,b\right]$ contains more than one minimum, e04bb will normally find one of the minima.

# References

Gill P E and Murray W (1973) Safeguarded steplength algorithms for optimization using descent methods

*NPL Report NAC 37*National Physical Laboratory# Error Indicators and Warnings

**Note:**e04bb may return useful information for one or more of the following detected errors or warnings.

Errors or warnings detected by the method:

- ${\mathbf{ifail}}=1$
On entry, $\left({\mathbf{a}}+{\mathbf{e2}}\right)\ge {\mathbf{b}}$, or ${\mathbf{maxcal}}<2$.

- ${\mathbf{ifail}}=2$
- The number of calls of funct has exceeded maxcal. This may have happened simply because maxcal was set too small for a particular problem, or may be due to a mistake in funct. If no mistake can be found in funct, restart e04bb (preferably with the values of a and b given on exit from the previous call of e04bb).

# Accuracy

If $F\left(x\right)$ is $\delta $-unimodal for some $\delta <\mathit{Tol}\left(x\right)$, where $\mathit{Tol}\left(x\right)={\mathbf{e1}}\times \left|x\right|+{\mathbf{e2}}$, then, on exit, $x$ approximates the minimum of $F\left(x\right)$ in the original interval $\left[a,b\right]$ with an error less than $3\times \mathit{Tol}\left(x\right)$.

# Parallelism and Performance

None.

# Further Comments

Timing depends on the behaviour of $F\left(x\right)$, the accuracy demanded and the length of the interval $\left[a,b\right]$. Unless $F\left(x\right)$ and $\frac{dF}{dx}$ can be evaluated very quickly, the run time will usually be dominated by the time spent in funct.

If $F\left(x\right)$ has more than one minimum in the original interval $\left[a,b\right]$, e04bb will determine an approximation $x$ (and improved bounds $a$ and $b$) for one of the minima.

If e04bb finds an $x$ such that $F\left(x-{\delta}_{1}\right)>F\left(x\right)<F\left(x+{\delta}_{2}\right)$ for some ${\delta}_{1},{\delta}_{2}\ge \mathit{Tol}\left(x\right)$, the interval $\left[x-{\delta}_{1},x+{\delta}_{2}\right]$ will be regarded as containing a minimum, even if $F\left(x\right)$ is less than $F\left(x-{\delta}_{1}\right)$ and $F\left(x+{\delta}_{2}\right)$ only due to rounding errors in the method. Therefore funct should be programmed to calculate $F\left(x\right)$ as accurately as possible, so that e04bb will not be liable to find a spurious minimum. (For similar reasons, $\frac{dF}{dx}$ should be evaluated as accurately as possible.)

# Example

A sketch of the function

shows that it has a minimum somewhere in the range $\left[3.5,5.0\right]$. The following program shows how e04bb can be used to obtain a good approximation to the position of a minimum.

$$F\left(x\right)=\frac{\mathrm{sin}\u200ax}{x}$$ |