F
F |
Purpose
Synopsis
function F(UF:userfunc, arg:linctr):nlctr
function F(UF:userfunc, arg:nlctr):nlctr
function F(UF:userfunc, arg:list of nlctr):nlctr
function F(UF:userfunc, arg:array(any sets) of nlctr):nlctr
function F(UF:userfunc, arg:list of nlctr, returnarg:integer):nlctr
function F(UF:userfunc, arg:array(any sets) of nlctr, returnarg:integer):nlctr
Arguments
UF
|
A user function of type
userfunc
|
arg
|
Argument to be passed to the user function
|
returnarg
|
Return argument to be substituted into the formula for multivalued user functions
|
Return value
A nonlinear expression which may form part of any
nlctr.
Example
The following example shows how to implement a negative cosine function.
model "SimpleUF" uses "mmxnlp" declarations obj: nlctr x: mpvar MinusSine: userfunc end-declarations ! Creation and assignment of the user function MinusSine := userfuncMosel("MinusSineImplementation") ! which can then be embedded into any nonlinear expression obj := F(MinusSine,x) minimize(obj) function MinusSineImplementation (x:real): real returned := -sin(x) end-function end-model
Further information
User functions allow extremely complex, recursive or non-algebraic expressions to be included in nonlinear formulae. As such they may make use of simulators or other black box evaluators. The actual parameters to a user function depend upon the way it is bound to the model by the
F function. Please see the chapter on user functions for more details. Each user function instance defined by the means of the
F function must share the same argument syntax structure, however the actual formula content may differ:
e.g. if a function takes an array of nonlinear expressions as input arguments, each instance of the function corresponding to the same definition based on the same F instance must have the same underlying array structure, although the expressions stored in them may differ. If a separate
F instance is used using the same function implementation, this rule does not apply. Also note, that for Mosel to be able to correctly cross reference the sets used in the definition of an array, the sets must be named.
Related topics
Module