x = lsqnonlin(fun, x0)
[x, resnorm, residual, exitflag, output, lambda, jacobian] = lsqnonlin(fun, x0, lb, ub, options)
[x, resnorm, residual, exitflag, output, lambda, jacobian] = lsqnonlin(fun, x0, lb, ub, A, b, Aeq, beq, nonlcon, options)
x = lsqnonlin(problem)
| Parameter | Description |
|---|---|
| fun | function returning a residual array. |
| x0 | initial point. |
| lb, ub | bounds, optionally empty. |
| A, b, Aeq, beq | linear inequality and equality constraints, optionally empty. |
| nonlcon | nonlinear constraint function returning [c, ceq], optionally empty. |
| options | solver options. |
| Parameter | Description |
|---|---|
| x | estimated solution, with the shape of x0. |
| resnorm | squared residual norm sum(fun(x).^2). |
| residual | residual at x, with the shape returned by fun. |
| exitflag | reason the solver stopped: 1 (gradient below tolerance), 2 (step below StepTolerance), 3 (residual change below FunctionTolerance), 4 (search direction below StepTolerance), 0 (iteration or evaluation limit), -1 (stopped by output function), -2 (inconsistent bounds). |
| output | structure with firstorderopt, iterations, funcCount, cgiterations, algorithm, stepsize, message, bestfeasible and constrviolation fields. |
| lambda | Lagrange multipliers structure with lower, upper, eqlin, ineqlin, eqnonlin and ineqnonlin fields. |
| jacobian | final finite-difference or user-provided Jacobian. |
lsqnonlin solves nonlinear least-squares problems min sum(fun(x).^2), optionally subject to bounds and constraints.
The Algorithm option selects the engine: 'trust-region-reflective' (default), 'levenberg-marquardt' (also accepts bounds) or 'interior-point'. Linear or nonlinear constraints automatically use the interior-point algorithm.
The default MaxFunctionEvaluations is 100*numberOfVariables, MaxIterations is 400 and FunctionTolerance and StepTolerance are 1e-6. The Display option supports 'off', 'none', 'final', 'final-detailed', 'notify', 'notify-detailed', 'iter' and 'iter-detailed'.
If Jacobian is 'on' or SpecifyObjectiveGradient is true, fun must also return the Jacobian of the residuals.
fun = @(x) [x(1) - 2; x(2) + 1];
[x, resnorm] = lsqnonlin(fun, [0; 0])
| Version | Description |
|---|---|
| 2.0.0 | initial version |