lsqnonlin
Solve nonlinear least-squares (nonlinear data-fitting) problems
Syntax
x = lsqnonlin(fun,x0)
x = lsqnonlin(fun,x0,lb,ub)
x = lsqnonlin(fun,x0,lb,ub,options)
x = lsqnonlin(problem)
[x,resnorm] = lsqnonlin(...)
[x,resnorm,residual] = lsqnonlin(...)
[x,resnorm,residual,exitflag] = lsqnonlin(...)
[x,resnorm,residual,exitflag,output] = lsqnonlin(...)
[x,resnorm,residual,exitflag,output,lambda] = lsqnonlin(...)
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(...)
Description
lsqnonlin solves nonlinear least-squares problems, including nonlinear data-fitting problems.
Rather than compute the value (the sum of squares), lsqnonlin requires the user-defined function to compute the vector-valued function
Then, in vector terms, you can restate this optimization problem as
where x is a vector and f(x) is a function that returns a vector value.
x = lsqnonlin(fun,x0) starts at the point x0 and finds a minimum of the sum of squares of the functions described in fun. fun should return a vector of values and not the sum of squares of the values. (The algorithm implicitly sums and squares fun(x).)
-
Note: Passing Extra Parameters explains how to pass extra parameters to the vector function f, if necessary.
x = lsqnonlin(fun,x0,lb,ub) defines a set of lower and upper bounds on the design variables inx, so that the solution is always in the range lb ≤ x ≤ ub.
x = lsqnonlin(fun,x0,lb,ub,options) minimizes with the optimization options specified in the structure options. Use optimset to set these options. Pass empty matrices for lb and ub if no bounds exist.
x = lsqnonlin(problem) finds the minimum for problem, where problem is a structure described inInput Arguments.
Create the structure problem by exporting a problem from Optimization Tool, as described inExporting Your Work.
[x,resnorm] = lsqnonlin(...) returns the value of the squared 2-norm of the residual at x:sum(fun(x).^2).
[x,resnorm,residual] = lsqnonlin(...) returns the value of the residual fun(x) at the solution x.
[x,resnorm,residual,exitflag] = lsqnonlin(...) returns a value exitflag that describes the exit condition.
[x,resnorm,residual,exitflag,output] = lsqnonlin(...) returns a structure output that contains information about the optimization.
[x,resnorm,residual,exitflag,output,lambda] = lsqnonlin(...) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x.
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(...) returns the Jacobian offun at the solution x.
Input Arguments
Function Arguments contains general descriptions of arguments passed into lsqnonlin. This section provides function-specific details for fun, options, and problem:
The function whose sum of squares is minimized. fun is a function that accepts a vector x and returns a vector F, the objective functions evaluated at x. The function fun can be specified as a function handle to a file: x = lsqnonlin(@myfun,x0) where myfun is a MATLAB function such as function F = myfun(x) F = ... % Compute function values at x fun can also be a function handle for an anonymous function. x = lsqnonlin(@(x)sin(x.*x),x0); If the user-defined values for x and F are matrices, they are converted to a vector using linear indexing.
If the Jacobian can also be computed and the Jacobian option is 'on', set by options = optimset('Jacobian','on') the function fun must return, in a second output argument, the Jacobian value J, a matrix, at x. By checking the value of nargout, the function can avoid computing J when fun is called with only one output argument (in the case where the optimization algorithm only needs the value of F but not J). function [F,J] = myfun(x) F = ... % Objective function values at x if nargout > 1 % Two output arguments J = ... % Jacobian of the function evaluated at x end If fun returns a vector (matrix) of m components and x has length n, where nis the length of x0, the Jacobian J is an m-by-n matrix where J(i,j) is the partial derivative of F(i) with respect to x(j). (The Jacobian J is the transpose of the gradient of F.) | |||
options | Options provides the function-specific details for the options values. | ||
problem | objective | Objective function | |
x0 | Initial point for x | ||
lb | Vector of lower bounds | ||
ub | Vector of upper bounds | ||
solver | 'lsqnonlin' | ||
options | Options structure created with optimset |