User function (simple form)


Purpose
In many cases, a user function takes one or more parameters and returns a single value. Such a function does not need the full power of the user function structure as described in User function (general form) (below), and it is possible to simplify the function definition.
Synopsis
function fName (aName:array(aRange:range) of real, nName:integer) :real
Arguments
aName 
an array of type real containing the actual values of the parameters to the function
nName 
an integer containing the actual number of parameters
Return value
The calculated value of the function
Example
The following example of a user function calculates the product of an array of values:
function Product(Values:array(vRange:range) of real,
                 nValue:integer) :real
  declarations
    Value: real
  end-declarations
  Value := 1
  forall (i in 1..nValue) do
    Value := Value * Values(vRange(i))
  end-do
  returned := Value
end-function
Notice that the function uses nValue rather than vRange to step through the array. This is because not all the values in the array will necessarily be set or used on each function call.
Related topics
User function (general form), Func


If you have any comments or suggestions about these pages, please send mail to docs@dashoptimization.com.