# Difference between revisions of "Fminnewton.m"

Finds a local minimum (or maximum) of a function of several variables, based on fminlbfgs.m code from D. Kroon, University of Twente (Nov 2010).

where the spin_system is that created from Spinach, the cost_function is a function handle to that which produces as cost, gradient, and\or Hessian as a function of an initial guess, x_init. optim is an optional argument containing the optimisation options as a pair-wise cell structure.

## Syntax

    [x,fx,grad,hess,data]=fminnewton(cost_function,x_0,optim,hess_init)


## Description

This function looks at the edges of the spectrum and subtracts anything that it finds there from the entire spectrum. The assumption is that anything that's reached as far as the edge must be a streak artefact that should be removed. This is often the case in 2D and 3D NMR spectra.

## Arguments

    cost_function  - Function handle, e.g. @cost_function,

x_0            - Initial guess for the waveform.

optim          - Structure providing the options for the numerical optimisation algorithm.
See optim_tols.m for all options.

hess_init      - (optional) an initial Hessian to use for quasi-newton methods.
If not provided, the identity is used as a default.


## Returns

    x              - Output waveform at the end of the optimisation.
Should be the waveform at a local minimum (or maximum) cost.

fx             - Output cost at the end of the optimisation.

hess           - Output Hessian matrix at the end of the optimisation.
Has meaning from 'bfgs', 'sr1', or 'newton', returns the identity otherwise.

data           - data structure containing diagnostics of the optimisation algorithm.


## Notes

This function is coded both for minimisation (default) and maximisation. This option is defined in the optim structure from optim_tols.m.