<< function Advanced functions getd >>

Scilab Help >> Advanced functions > functions

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 using the exec function or through a library (see lib or genlib). But they can also be defined on-line (see deff or function. A function is defined by two components:

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

Miscellaneous

Functions are Scilab objects (with type numbers 13 or 11). And they 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.

Note that a function name must respect some syntax rules (see names).

Examples

//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/modules/elementary_functions/macros/asinh.sci;

See also


Report an issue
<< function Advanced functions getd >>