Optimization Toolbox    

Additional Arguments: Avoiding Global Variables

You can pass parameters that would otherwise have to be declared as global directly to M-file functions using additional arguments at the end of the calling sequence.

For example, entering a number of variables at the end of the call to fsolve

passes the arguments directly to the function objfun when it is called from inside fsolve:

Consider, for example, finding zeros of the function ellipj(u,m). The function needs parameter m as well as input u. To look for a zero near u = 3, for m = 0.5,

returns

Then, solve for the function ellipj:

The call to optimset to get the default options for fsolve implies that default tolerances are used and that analytic gradients are not provided.


  Maximization Nonlinear Equations with Analytic Jacobian