1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
functions Scilab Group Scilab Data type functions
NAME
functions - Scilab procedures and Scilab objects
DESCRIPTION
Functions are Scilab procedures ("macro", "function" and "procedure" have
the save meaning).
FUNCTION DEFINITION
Usually, they are defined in files with an editor and loaded into Scilab
by getf or through a library (see lib or genlib). But They can also be
defined on-line (see deff or function o. A function is defined by two
components:
- a "syntax definition" part as follows:
[y1,...,yn]=foo(x1,...,xm)
[y1,...,yn,varargout]=foo(x1,...,xm,varargin)
- a sequence of scilab instructions.
The "syntax definition" line gives the "full" calling syntax of this
function. The yi are output variables calculated as functions of input
variables xi and variables existing in Scilab when the function is
executed.
CALLING FUNCTION
Usually function calling syntax is [y1,...,yn]=foo(x1,...,xm). Shorter
input or output argument list than definition ones may be used. In such
cases, only the first variables from the left are used of set. The argn
function may be used to get the actual number of calling arguments.
It is also possible to use "named argument" to specify input arguments:
suppose function fun1 defined as y1=fun1(x1,x2,x3) then it call be called
with a syntax like y=fun1(x1=33,x3=[1 2 3]) within fun1 x2 will be
undefined. It is possible to check for defined variables with the exists
function
When a function has no left hand side argument and is called only with
character string arguments, the callling syntax may be simplified
fun('a','toto','a string') can be replaced by fun a toto 'a string'
MISCELLANEOUS
Functions are Scilab objects (with type numbers 13 or 11). They and can
be manipulated (built, saved, loaded, passed as arguments,..) as other
variable types.
Collections of functions can be collected in libraries. Functions which
begin with % sign (e.g. %foo) are often used to overload (see
overloading) operations or functions for new data type.
EXAMPLE
//inline definition (see function)
function [x,y]=myfct(a,b)
x=a+b
y=a-b
endfunction
[x,y]=myfct(3,2)
//inline definition (see deff)
deff('[x,y]=myfct(a,b)',['x=a+b';
'y=a-b'])
// definition in an ascii file (see exec)
exec SCI/macros/elem/asin.sci;
// definition in an ascii file (see getf)
getf SCI/macros/elem/asin.sci;
SEE ALSO
function, deff, getf, comp, lib, getd, genlib, exists, varargin,
varargout
|