optim_doc: Additional parameters

Next: Function index, Previous: Parameter structures, Up: Top [Index]

## 11 Passing additional parameters to user functions

Optimizers often require the user to supply functions (e.g. objective functions, model functions, constraint functions). The interface of these functions — arguments and returned values — is defined by the optimizer. Often, a user function needs additional arguments, not covered by the defined interface, which are constant throughout the optimization. These can be supplied by wrapping the user function into an anonymous function. See (octave)Anonymous Functions, for further explanation and examples.

There are also some older optimizers in the optim package, written when anonymous functions were not available in Octave. Some of these offer an interface to user functions which is itself able to pass additional constant variables in arbitrary argument positions. Newer optimizers should not be written this way, since this is an unnecessary complication.

Though it is possible to use global variables to pass additional data to user functions, this is not recommended since it introduces the possibility of name conflicts within the pool of global variables.