~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to man/functions/functions.cat

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

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