Optimization Toolbox
  Go to function:
    Search    Help Desk 
lsqnonlin    Examples   See Also

Solve nonlinear least-squares (nonlinear data-fitting) problems

where L is a constant.

Syntax

Description

lsqnonlin solves nonlinear least-squares problems, including nonlinear data-fitting problems.

Rather than compute the value f(x) (the "sum of squares"), lsqnonlin requires the user-defined function to compute the vector-valued function

Then, in vector terms, this optimization problem may be restated 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 to 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. (fun(x) is summed and squared implicitly in the algorithm.)

x = lsqnonlin(fun,x0,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that the solution is always in the range lb <= x <= ub.

x = lsqnonlin(fun,x0,lb,ub,options) minimizes with the optimization parameters specified in the structure options.

x = lsqnonlin(fun,x0,lb,ub,options,P1,P2,...) passes the problem-dependent parameters P1, P2, etc., directly to the function fun. Pass an empty matrix for options to use the default values for options.

[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 of fun at the solution x.

Arguments

The arguments passed into the function are described in Table 1-1. The arguments returned by the function are described in Table 1-2. Details relevant to lsqnonlin are included below for fun, options, exitflag, lambda, and output.

fun
The function to be minimized. fun takes a vector x and returns a vector F of the objective functions evaluated at x. You can specify fun to be an inline object. For example,

    x = lsqnonlin(inline('sin(x.*x)'),x0)
    
Alternatively, fun can be a string containing the name of a function (an M-file, a built-in function, or a MEX-file). If fun='myfun' then the M-file function myfun.m would have the form

    function F = myfun(x)
    F = ...            % Compute function values at x
    

If the Jacobian can also be computed and options.Jacobian is 'on', set by

    options = optimset('Jacobian','on')
    
then the function fun must return, in a second output argument, the Jacobian value J, a matrix, at x. Note that 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, then 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). (Note that the Jacobian J is the transpose of the gradient of F.)

options
Optimization parameter options. You can set or change the values of these parameters using the optimset function. Some parameters apply to all algorithms, some are only relevant when using the large-scale algorithm, and others are only relevant when using the medium-scale algorithm.

We start by describing the LargeScale option since it states a preference for which algorithm to use. It is only a preference because certain conditions must be met to use the large-scale or medium-scale algorithm. For the large-scale algorithm, the nonlinear system of equations cannot be under-determined; that is, the number of equations (the number of elements of F returned by fun) must be at least as many as the length of x. Furthermore, only the large-scale algorithm handles bound constraints.


Parameters used by both the large-scale and medium-scale algorithms:



Parameters used by the large-scale algorithm only:


Parameters used by the medium-scale algorithm only:

exitflag
Describes the exit condition:

lambda
A structure containing the Lagrange multipliers at the solution x (separated by constraint type):

output
A structure whose fields contain information about the optimization:

Note:
The sum of squares should not be formed explicitly. Instead, your function should return a vector of function values. See the example below.

Examples

Find x that minimizes

starting at the point x = [0.3, 0.4].

Because lsqnonlin assumes that the sum-of-squares is not explicitly formed in the user function, the function passed to lsqnonlin should instead compute the vector valued function

for (that is, F should have k components).

First, write an M-file to compute the k-component vector F:

Next, invoke an optimization routine:

After about 24 function evaluations, this example gives the solution:

Algorithm

Large-scale optimization.    By default lsqnonlin will choose the large-scale algorithm. This algorithm is a subspace trust region method and is based on the interior-reflective Newton method described in [5], [6]. Each iteration involves the approximate solution of a large linear system using the method of preconditioned conjugate gradients (PCG). See the trust-region and preconditioned conjugate gradient method descriptions in the Large-Scale Algorithms chapter.

Medium-scale optimization.    lsqnonlin with options.LargeScale set to 'off' uses the Levenberg-Marquardt method with line-search [1], [2], [3]. Alternatively, a Gauss-Newton method [4] with line-search may be selected. The choice of algorithm is made by setting options.LevenbergMarquardt. Setting options.LevenbergMarquardt to 'off' (and options.LargeScale to 'off') selects the Gauss-Newton method, which is generally faster when the residual is small.

The default line search algorithm, i.e., options.LineSearchType set to 'quadcubic', is a safeguarded mixed quadratic and cubic polynomial interpolation and extrapolation method. A safeguarded cubic polynomial method can be selected by setting options.LineSearchType to 'cubicpoly'. This method generally requires fewer function evaluations but more gradient evaluations. Thus, if gradients are being supplied and can be calculated inexpensively, the cubic polynomial line search method is preferable. The algorithms used are described fully in the Introduction to Algorithms chapter.

Diagnostics

Large-scale optimization.    The large-scale code will not allow equal upper and lower bounds. For example if lb(2)==ub(2) then lsqlin gives the error:

(lsqnonlin does not handle equality constraints, which is another way to formulate equal bounds. If equality constraints are present, use fmincon, fminimax or fgoalattain for alternative formulations where equality constraints can be included.)

Limitations

The function to be minimized must be continuous. lsqnonlin may only give local solutions.

lsqnonlin only handles real variables. When x has complex variables, the variables must be split into real and imaginary parts.

Large-scale optimization.    The large-scale method for lsqnonlin does not solve under-determined systems: it requires that the number of equations (i.e., the number of elements of F) be at least as great as the number of variables. In the under-determined case, the medium-scale algorithm will be used instead. (If bound constraints exist, a warning will be issued and the problem will be solved with the bounds ignored.) See Table 1-4 for more information on what problem formulations are covered and what information must be provided.

The preconditioner computation used in the preconditioned conjugate gradient part of the large-scale method forms JTJ (where J is the Jacobian matrix) before computing the preconditioner; therefore, a row of J with many nonzeros, which results in a nearly dense product JTJ, may lead to a costly solution process for large problems.

If components of x have no upper (or lower) bounds, then lsqnonlin prefers that the corresponding components of ub (or lb) be set to inf (or -inf for lower bounds) as opposed to an arbitrary but very large positive (or negative for lower bounds) number.

Currently, if the analytical Jacobian is provided in fun, the options parameter DerivativeCheck cannot be used with the large-scale method to compare the analytic Jacobian to the finite-difference Jacobian. Instead, use the medium-scale method to check the derivatives with options parameter MaxIter set to 0 iterations. Then run the problem with the large-scale method.

Medium-scale optimization.    The medium-scale algorithm does not handle bound constraints.

Since the large-scale algorithm does not handle under-determined systems and the medium-scale does not handle bound constraints, problems with both these characteristics cannot be solved by lsqnonlin.

See Also

optimset, lsqcurvefit, lsqlin

References

[1] Levenberg, K.,"A Method for the Solution of Certain Problems in Least Squares," Quarterly Applied Math. 2, pp. 164-168, 1944.

[2] Marquardt, D.,"An Algorithm for Least-squares Estimation of Nonlinear Parameters," SIAM J. Applied Math. Vol. 11, pp. 431-441, 1963.

[3] Moré, J.J., "The Levenberg-Marquardt Algorithm: Implementation and Theory," Numerical Analysis, ed. G. A. Watson, Lecture Notes in Mathematics 630, Springer Verlag, pp. 105-116, 1977.

[4] Dennis, J.E., Jr., "Nonlinear Least Squares," State of the Art in Numerical Analysis, ed. D. Jacobs, Academic Press, pp. 269-312, 1977.

[5] Coleman, T.F. and Y. Li, "On the Convergence of Reflective Newton Methods for Large-Scale Nonlinear Minimization Subject to Bounds," Mathematical Programming, Vol. 67, Number 2, pp. 189-224, 1994.

[6] Coleman, T.F. and Y. Li, "An Interior, Trust Region Approach for Nonlinear Minimization Subject to Bounds," SIAM Journal on Optimization, Vol. 6, pp. 418-445, 1996.



[ Previous | Help Desk | Next ]