- Function File:
*[*`p`,`resid`,`cvg`,`outp`] =**nonlin_residmin***(*`f`,`pin`) - Function File:
*[*`p`,`resid`,`cvg`,`outp`] =**nonlin_residmin***(*`f`,`pin`,`settings`) Frontend for nonlinear minimization of residuals returned by a model function.

The functions supplied by the user have a minimal interface; any additionally needed constants (e.g. observed values) can be supplied by wrapping the user functions into anonymous functions.

The following description applies to usage with vector-based parameter handling. Differences in usage for structure-based parameter handling will be explained separately.

`f`: function returning the array of residuals. It gets a column vector of real parameters as argument. In gradient determination, this function may be called with an informational second argument, whose content depends on the function for gradient determination.`pin`: real column vector of initial parameters.`settings`: structure whose fields stand for optional settings referred to below. The fields can be set by`optimset()`

.The returned values are the column vector of final parameters

`p`, the final array of residuals`resid`, an integer`cvg`indicating if and how optimization succeeded or failed, and a structure`outp`with additional information, curently with the fields:`niter`

, the number of iterations and`user_interaction`

, information on user stops (see settings). The backend may define additional fields. If the backend supports it,`outp`has a field`lambda`

with determined Lagrange multipliers of any constraints, seperated into subfields`lower`

and`upper`

for bounds,`eqlin`

and`ineqlin`

for linear equality and inequality constraints (except bounds), respectively, and`eqnonlin`

and`ineqnonlin`

for general equality and inequality constraints, respectively.`cvg`is greater than zero for success and less than or equal to zero for failure; its possible values depend on the used backend and currently can be`0`

(maximum number of iterations exceeded),`2`

(parameter change less than specified precision in two consecutive iterations), or`3`

(improvement in objective function – e.g. sum of squares – less than specified), or`-1`

(algorithm aborted by a user function).For settings, type

`optim_doc ("nonlin_residmin")`

.For desription of structure-based parameter handling, type

`optim_doc ("parameter structures")`

.For description of individual backends (currently only one), type

`optim_doc ("residual optimization")`

and choose the backend in the menu.**See also:**nonlin_curvefit.

The following code

## Example for linear inequality constraints ## (see also the same example in 'demo nonlin_curvefit') ## independents indep = 1:5; ## residual function: f = @ (p) p(1) * exp (p(2) * indep) - [1, 2, 4, 7, 14]; ## initial values: init = [.25; .25]; ## linear constraints, A.' * parametervector + B >= 0 A = [1; -1]; B = 0; # p(1) >= p(2); settings = optimset ("inequc", {A, B}); ## start optimization [p, residuals, cvg, outp] = nonlin_residmin (f, init, settings)

Produces the following output

p = 0.62034 0.62034 residuals = 0.153573 0.145149 -0.010949 0.417915 -0.205878 cvg = 3 outp = scalar structure containing the fields: user_interaction = scalar structure containing the fields: stop = [](0x1) info = {}(0x1) niter = 7 lambda = scalar structure containing the fields: lower = 0 0 upper = 0 0 eqlin = [](0x0) ineqlin = 269.24 eqnonlin = [](1x0) ineqnonlin = [](1x0)

Package: optim