FunctionName(argument1, argument2, ...)
To evaluate a function, enter the name of the function, followed by the arguments (if any) to the function in parentheses. This will return the result of applying the function to its arguments. The number of arguments to the function is, of course, different for each function.
There are many built-in functions, such as sin, cos and tan. You can use the help built-in function to get a list of available functions, or see the Chapter called List of GEL functions for a full listing.
|Using Tab completion|
You can use Tab completion to get Genius to complete function names for you. Try typing the first few letters of the name and pressing Tab.
|Function names are case sensitive|
The names of functions are case sensitive. That means that functions named dosomething, DOSOMETHING and DoSomething are all different functions.
function <identifier>(<comma separated arguments>) = <function body>
<identifier> = (`() = <function body>)
is the backquote character, and signifies an anonymous function. By setting it to a variable name you effectively define a function.
A function takes zero or more comma separated arguments, and returns the result of the function body. Defining your own functions is primarily a matter of convenience; one possible use is to have sets of functions defined in GEL files which Genius can load in order to make available.
function addup(a,b,c) = a+b+c
If you include ... after the last argument name in the function declaration, then Genius will allow any number of arguments to be passed in place of that argument. If no arguments were passed then that argument will be set to
null. Otherwise, it will be a horizontal vector containing all the arguments. For example:
, while f(1)
In Genius, it is possible to pass a function as an argument to another function. This can be done using either ‘function nodes’ or anonymous functions.
If you do not enter the parentheses after a function name, instead of being evaluated, the function will instead be returned as a ‘function node’. The function node can then be passed to another function.
function f(a,b) = a(b)+1;
function b(x) = x*x;
To pass functions which are not defined,
you can use an anonymous function (see the Section called Defining Functions). That is, you want to pass a function without giving it a name.
function(<comma separated arguments>) = <function body>
`(<comma separated arguments>) = <function body>
function f(a,b) = a(b)+1;
f(`(x) = x*x,2)
This will return 5.
Some functions allow arithmetic operations, and some single argument functions such as exp or ln, to operate on the function. For example,
will return a function that takes
and returns exp(sin(x)*cos(x)+4)
. It is functionally equivalent
`(x) = exp(sin(x)*cos(x)+4)
This operation can be useful when quickly defining functions. For example to create a function called
to perform the above operation, you can just type:
It can also be used in plotting. For example, to plot sin squared you can enter:
Not all functions can be used in this way. For example, when you use a binary operation the functions must take the same number of arguments.