Syntax:
FunctionName(argument1, argument2, ...)
Example:
Factorial(5)
cos(2*pi)
gcd(921,317)
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.
Υπάρχουν πολλές ενσωματωμένες συναρτήσεις, όπως οι sin
, cos
και tan
. Μπορείτε να χρησιμοποιήσετε την ενσωματωμένη εντολή help
για να πάρετε έναν κατάλογο διαθέσιμων συναρτήσεων, ή δείτε Chapter 11, Κατάλογος συναρτήσεων της GEL για έναν πλήρη κατάλογο.
Μπορείτε να χρησιμοποιήσετε την συμπλήρωση καρτέλας για να βάλετε την Genius να συμπληρώσει τα ονόματα των συναρτήσεων για σας. Δοκιμάστε την πληκτρολόγηση των πρώτων λίγων γραμμάτων του ονόματος και πατήστε Καρτέλα
.
Τα ονόματα των συναρτήσεων είναι με διάκριση πεζών/κεφαλαίων. Αυτό σημαίνει ότι οι συναρτήσεις με όνομα dosomething
, DOSOMETHING
και DoSomething
είναι όλες διαφορετικές συναρτήσεις.
Syntax:
function <identifier>(<comma separated arguments>) = <function body>
<identifier> = (`() = <function body>)
The `
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 that Genius can load in order to make them available. Example:
function addup(a,b,c) = a+b+c
then addup(1,4,9)
yields 14
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:
function f(a,b...) = b
Then f(1,2,3)
yields [2,3]
, while f(1)
yields a null
.
Στο Genius, είναι δυνατό να περάσετε μια συνάρτηση ως ένα όρισμα σε μια άλλη συνάρτηση. Αυτό μπορεί να γίνει χρησιμοποιώντας είτε ‘κόμβους συνάρτησης’ ή ανώνυμες συναρτήσεις.
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. Example:
function f(a,b) = a(b)+1;
function b(x) = x*x;
f(b,2)
To pass functions that are not defined, you can use an anonymous function (see the section called “Ορισμός συναρτήσεων”). That is, you want to pass a function without giving it a name. Syntax:
function(<comma separated arguments>) = <function body>
`(<comma separated arguments>) = <function body>
Example:
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,
exp(sin*cos+4)
will return a function that takes x
and returns exp(sin(x)*cos(x)+4)
. It is functionally equivalent
to typing
`(x) = exp(sin(x)*cos(x)+4)
This operation can be useful when quickly defining functions. For example to create a function called f
to perform the above operation, you can just type:
f = exp(sin*cos+4)
It can also be used in plotting. For example, to plot sin squared you can enter:
LinePlot(sin^2)
Δεν μπορούν όλες οι συναρτήσεις να χρησιμοποιηθούν κατ' αυτόν τον τρόπο. Για παράδειγμα, όταν χρησιμοποιείτε μια δυαδική πράξη οι συναρτήσεις πρέπει να παίρνουν τον ίδιο αριθμό ορισμάτων.