# Difference between revisions of "Linesearch.m"

This function finds an appropriate step length from a given search direction at a current iterate. The bracket-section line search based on fminlbfgs.m code from D. Kroon, University of Twente (Nov 2010).

## Syntax

    [alpha,fx_1,gfx_1,exitflag,data]=linesearch(cost_function, d_0, x_0, fx_0, gfx_0, data, optim)


## Description

Performs a line search to find an appropriate step length called from within a given optimisation algorithm, i.e. fminnewton.m. This function generally assumes cheap gradients. There are currently three line-search methods from which to chose: a Newton-step (step length = 1, equivalent to no line-search); backtracking line-search; bracketing and sectioning with a cubic interpolation.

## Arguments

    cost_function     - function handle to the objective function.

d_0               - current search direction

x_0               - current objective (waveform)

fx_0              - current objective function value at x_0

gfx_0             - current gradient at x_0

data              - data structure inherited from fminnewton.m

optim             - optim structure inherited from fminnewton.m,
contains tolerances and line-search options.


## Returns

    alpha             - step length

fx_1              - new objective function value (if alpha is not the Newton-step)

gfx_1             - new gradient (if alpha is not the Newton-step)

exitflag          - exit flag that is empty if no errors were encountered.
If an error was encountered, the codes produced are:
-2 - Line search cannot find an acceptable point along the current search
2 - Change in x was smaller than the specified tolerance, optim.tol_x.
3 - Change in gradient norm less than specified tolerance, optim.tol_gfx.

data              - data structure with diagnostics from the line-search.


## Notes

The bracket-section line-search is the default. It is also the most accurate and the most expensive - this generally assumes cheap gradient calculation (e.g. from GRAPE. The newton-step is effectively no line-search, and should only be used with a stable Newton-Raphson method. The backtracking line-search is useful and quite effective for a Newton-Raphson optimisation.