Optimization Toolbox    

New Calling Sequences

Version 2 of the toolbox makes these changes in the calling sequences:

Algorithm terminating conditions have been fine tuned. The stopping conditions relating to TolX and TolFun for the large-scale and medium-scale code are joined using OR instead of AND for these functions: fgoalattain, fmincon, fminimax, fminunc, fseminf, fsolve, and lsqnonlin. As a result, you might need to specify stricter tolerances; the defaults reflect this change.

Each function now has an output structure that contains information about the problem solution relevant to that function.

The lambda is now a structure where each field is the Lagrange multipliers for a type of constraint. For more information, see the individual functions in Function Reference.

The following sections describe how to convert from the old function names and calling sequences to the new ones. The calls shown are the most general cases, involving all possible input and output arguments. Note that many of these arguments are optional; see the online help for these functions for more information.

Converting from attgoal to fgoalattain

In Version 1.5, you used this call to attgoal:

with [F] = FUN(X,P1,...) and [DF] = GRADFUN(X,P1,...).

In Version 2, you call fgoalattain like this

with [F,DF] = FUN(X,P1,P2,...) and NONLCON = [].

The fgoalattain function allows nonlinear constraints, so you can now define

Converting from conls to lsqlin

In Version 1.5, you used this call to conls:

In Version 2, convert the input arguments to the correct form for lsqlin by separating the equality and inequality constraints.

Now call lsqlin like this:

Converting from constr to fmincon

In Version 1.5, you used this call to constr:

with [F,C] = FUN(X,P1,...) and [G,DC] = GRADFUN(X,P1,...).

In Version 2, replace FUN and GRADFUN with two new functions:

Now call fmincon like this:

See Example of Converting from constr to fmincon for a detailed example.

Converting from curvefit to lsqcurvefit

In Version 1.5, you used this call to curvefit:

with F = FUN(X,P1,...) and G = GRADFUN(X,P1,...).

In Version 2, replace FUN and GRADFUN with a single function that returns both F and J, the objective function and the Jacobian. (The Jacobian is the transpose of the gradient.):

Now call lsqcurvefit like this:

Converting from fmin to fminbnd

In Version 1.5, you used this call to fmin:

In Version 2, you call fminbnd like this:

Converting from fmins to fminsearch

In Version 1.5, you used this call to fmins:

In Version 2, you call fminsearch like this:

Converting from fminu to fminunc

In Version 1.5, you used this call to fminu:

with F = FUN(X,P1, ...) and G = GRADFUN(X,P1, ...).

In Version 2, replace FUN and GRADFUN with a single function that returns both F and G (the objective function and the gradient).

(This function can also return the Hessian matrix as a third output argument.)

Now call fminunc like this:

If you have an existing FUN and GRADFUN that you do not want to rewrite, you can pass them both to fminunc by placing them in a cell array.

Converting to the New Form of fsolve

In Version 1.5, you used this call to fsolve:

with F = FUN(X,P1,...) and G = GRADFUN(X,P1,...).

In Version 2, replace FUN and GRADFUN with a single function that returns both F and G (the objective function and the gradient).

Now call fsolve like this:

If you have an existing FUN and GRADFUN that you do not want to rewrite, you can pass them both to fsolve by placing them in a cell array.

Converting to the New Form of fzero

In Version 1.5, you used this call to fzero:

In Version 2, replace the TRACE and TOL arguments with

Now call fzero like this:

Converting from leastsq to lsqnonlin

In Version 1.5, you used this call to leastsq:

with F = FUN(X,P1,...) and G = GRADFUN(X,P1, ...).

In Version 2, replace FUN and GRADFUN with a single function that returns both F and J, the objective function and the Jacobian. (The Jacobian is the transpose of the gradient.):

Now call lsqnonlin like this:

Converting from lp to linprog

In Version 1.5, you used this call to lp:

In Version 2, convert the input arguments to the correct form for linprog by separating the equality and inequality constraints.

Now call linprog like this:

Converting from minimax to fminimax

In Version 1.5, you used this call to minimax:

with F = FUN(X,P1,...) and G = GRADFUN(X,P1,...).

In Version 2, you call fminimax like this:

with [F,DF] = OBJFUN(X,P1,...) and [Cineq,Ceq,DCineq,DCeq] = NONLCON(X,P1,...).

Converting from nnls to lsqnonneg

In Version 1.5, you used this call to nnls:

In Version 2, replace the tol argument with

Now call lsqnonneg like this:

Converting from qp to quadprog

In Version 1.5, you used this call to qp:

In Version 2, convert the input arguments to the correct form for quadprog by separating the equality and inequality constraints.

Now call quadprog like this:

Converting from seminf to fseminf

In Version 1.5, you used this call to seminf:

with [F,C,PHI1,PHI2,...,PHIN,S] = FUN(X,S,P1,P2,...).

In Version 2, call fseminf like this:

with F = OBJFUN(X,P1,...) and [Cineq,Ceq,PHI1,PHI2,...,PHIN,S] = NONLCON(X,S,P1,...).


  Using optimset and optimget Example of Converting from constr to fmincon