| Optimization Toolbox | ![]() |
Additional Arguments: Avoiding Global Variables
Parameters that would otherwise have to be declared as global can be passed 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
[x,fval] = fsolve(@objfun,x0,options,P1,P2,...)
passes the arguments directly to the functions objfun when it is called from inside fsolve.
F = objfun(x,P1,P2, ... )
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
m = 0.5;
options = optimset('Display','off'); % Turn off Display
x = fsolve(@ellipj,3,options,m)
x =
3.7081
Then, solve for the function ellipj.
f = ellipj(x,m)
f =
-2.9925e-008
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 | Multiobjective Examples | ![]() |