Scilab


Scilab (pronounced [ s a d l a b ] [citation needed]. Contraction Scientific Laboratory in English) is a free software for numerical computation multi-platform providing a computing environment for scientific applications. It has a programming language oriented numerically of high level . It can be used for signal processing , the statistical analysis , the image processing , simulations of fluid dynamics , the optimization digital,

It is available for Windows , Mac OS X , GNU / Linux and BSD .

The syntax and possibilities offered by Scilab are similar to those of Matlab , but the two programs are not compatible although a translator from Matlab to Scilab exists.

History

The project was born at Inria in 1982 under the name Blaise , from Matlab 1 , 2 . It is thus initially an overlay of Fortran allowing structured programming , the syntax being close to the Pascal . In 1984, Inria founded a young sprout, Simulog, to market the product under the name of Basile .

In the 1990s, Simulog stopped distributing Basile and the project, then called Meta2 , became the fruit of a collaboration of researchers from Inria and ENPC . The first version of Scilab, then called Ψlab 3 ( Psilab , same pronunciation), was released in 1994. The development of Scicos began at the same time as a graphic toolbox.

In 1998, a former PhD student of the Meta2 project, Habib Jreige, founded the young Saphir-Control shoot to provide assistance to private companies using Scilab.

The Metalau team was founded in 2000 to develop a Matlab / Scilab translator and to integrate object-oriented graphics libraries, in particular a graphical interface in Java.

At the beginning of 2003, Inria decided to create the Scilab Consortium with the support of companies and academic organizations to cope with the increasing number of people downloading and using Scilab and to ensure its future and development. In 2005, the Scilab Consortium decided to turn to Java development; The Metalau team decides to stay on Gtk technology and thus creates a split (fork) called ScilabGtk based on Scilab 4; This project will be renamed ScicosLab .

In line with industrial development, the Scilab Consortium joined the Digiteo Scientific Cooperation Foundation in July 2008 to provide an environment conducive to the sustained growth of the operation and to prepare for its gradual transfer to a private structure.

In June 2010, Scilab Enterprises was created on the classic open source business model to develop the free Scilab software based on open code and offer professional services for a fee. Since July 2012, Scilab has been developed by Scilab Enterprises .

In 2015, Inria and OCamlPro set up a joint interpreter project in OCaml named Scilint . This gives rise to Sciweb , an interpreter accessible by an Internet browser , although incomplete and slower 4 .

License

Distributed freely and with its source code via the Internet since 1994 , it is available precompiled for a large number of architectures . Nevertheless, it was neither open source software according to the Open Source Initiative nor Free Software . Indeed, the old Scilab 5 license does not allow the commercial distribution of a modified version. According to the classification of the FSF , it was therefore rather a semi-free software 6 . Scilab has therefore become free software during the license change: it is distributed under the CeCILL v2 license since version 5.0,

Brief description of the use

Scilab can execute command -line commands, as well as command files (scripts) containing instructions (text format). You can run Fortran or C programs from Scilab. It is also possible to use the Scilab engine from an external application thanks to the call_scilab API. Scilab is complemented by an Xcos graphical environment (based on Scicos ) comparable to the Simulink graphical environment provided with Matlab.

Elementary command-line syntax

The command prompt ( prompt ) consists of an “arrow”: two dashes and an upper sign -->. The instruction is typed and validated with the carriage return key ( Enter , Return ). The result is displayed as a result, unless the line ends with a semicolon, in which case the result is hidden. For example :

-> a = 1 ;
-> A = 2 ;
-> a + A
 ans =
 3.

The first command associates the value “1” with the variable “a” (hidden result), the second command associates the value “2” with the variable “A” (the syntax is case sensitive), the third command calculates the Sum of the two ( ans is the abbreviation for answer which means “answer” in English).

You can write several statements on the same line separating them from a comma , or a semicolon if you do not want to display the result. You can also put an instruction on several lines (for example for presentation purposes) by putting three points ” ... ” before pressing the carriage return key.

Scilab uses the functions and classical operators ( +, -, *, /, ^or **, sqrt()for square root , cos()for the cosine , int()for the whole part , round()for rounding to nearest, abs()to the absolute value …) and others (eg randfor A random number between 0 and 1). The function whodisplays the declared variables. The variable anscontains the last result.

The decimal separator is the point. To enter the imaginary i , one must use %i ; It simply appears as “i” in the results. To enter the infinite ∞, use %inf ; It simply appears as “inf” in the results. The value of π is obtained by %pi, and the Neper constant e by %e.

Booleans

When you assign a value Boolean is used %Tto “true” ( true ) and %Fto ‘false’ ( false ). The result of the displayed operation is respectively Tor F.

The operator Ou is denoted «| “( Tube ), and is noted” & “( ampersand ), No is denoted” ~ “( tilde ). Example

-> ( % T & % F ) | % F
years =
F .

A boolean can be obtained by comparing two values with the relations of equality == and difference <>or ~=, and order relations < , <=, >and >=.

Polynomials and rational fractions

These are not polynomial functions that allow only their numerical evaluation, but of formal polynomials .

Declaring a polynomial is done with two functions. The first function, x = poly(0, "x")which defines “x” as the indeterminate of a polynomial, then the utterance of the polynomial using this indeterminate. Example

-> x = poly ( 0 , "x" ); P = x ^ 2 + 2 * x + 1
p =
 2
1 + 2 x + x

The function roots(p)gives the roots of the polynomial p , the function coeff(p)gives a matrix whose coefficients are the coefficients of the polynomial p . The function varn(p)returns the name of the indeterminate of p (here, x ).

In fact, the control x = poly(0, "x")defines that x is the simplest polynomial whose indeterminate is the character “x” and whose root is 0, that is to say the monomial x . The control also x = poly(2, "x")defines the simplest polynomial with root 2, ie x – 2.

This function defines a polynomial with several roots, using a row matrix instead of a simple number. For example, x=poly([1 2], "x")define the simplest polynomial with roots 1 and 2, or the polynomial x 2 – 3 x + 2.

One can also use this function to generate a polynomial whose coefficients are contained in a line matrix, adding the character 'c'at the end of the arguments. For example, define the polynomial a0 + a1 · x + … + year · x n .x = poly([a0, a1, …, an], "x", "c")

Scilab manages the rational fractions in the same way . It is poly()sufficient to declare a monomial with and then define the rational fraction. Example

-> x = poly ( 0 , "x" ); F = ( 1 + x ) / ( 1 - x )
f =
1 + x
-----
1 - x
-> 1 / f
ans =
1 - x
-----
1 + x

To have the numerator of ƒ, just type f.num ; The denominator of ƒ is obtained with f.den.

The function gives the formal derivation of the polynomial or of a rational fraction p . The function simplifies the rational fraction q .derivat(p)simp(q)

The use of the polynomial or of a rational fraction as a function is done by the function horner : horner(p,2)computes p (2).

Character

Single characters or strings are written in single quotation marks, or in double quotation marks: 'abc'or "abc".

The apostrophe indicates the end of a string; To put an apostrophe in a string, you have to write two matches '', and to put a double quotation mark, you must also write two adjacent ones "".

The addition +on strings produces the concatenation . A character string can be evaluated, that is, transformed into a Scilab command, by the function evstr().

Matrices

Scilab was designed for matrix computation . All functions apply to matrices ; for example, if M is a matrix, then log(M)will be the matrix whose entries are the logarithms of Mr. matrices elements coefficients can be of any type ( real number , complex number , boolean , polynomial , rational , string … ).

To define a matrix from its coefficients, we place them between two square brackets […]. The elements of a line are separated from a space or a comma, the lines are separated from a semicolon. In the display, the matrix is ​​represented as a table without framing (except the string matrices that are framed by exclamation points). For example :

-> [ 1 , 2 , 3 ; 0 , 1 , 0 ; 0 , 0 , 1 ]
years =
 1. 2. 3.
 0. 1. 0.
 0. 0. 1.

The empty matrix is ​​denoted by []. The expression M(i,j)denotes the element ( i , j ) of the matrix M. The :( colon ) character means “all the indices”, for example M(1, :)is the first row of the matrix (it is a line vector ). The character $( dollar ) refers to the last index (row or column) of a matrix.

The expression N1:N'makes it possible to generate a line matrix whose first coefficient is N1, the last one is less than or equal to N ‘, and the step between the coefficients is 1. The expression makes it possible to generate a matrix-line by choosing the step . for exampleN1:pas:N2

-> 1.1 : 5.2
years =
! 1.1 2.1 3.1 4.1 5.1 !
-> 1 : 2 : 5
years =
! 1 3 5 !
& Nbsp ;
-> "a" : "d"
ans =
Abcd

The function creates a matrix m × n filled with 0; The function creates a matrix m × n filled with 1. The function creates a unit matrix n × n . It is also possible to pass a matrix M as a parameter of these functions; They then create a matrix of the same dimension as the matrix M. For example, sets all the coefficients of M to zero.zeros(m,n)ones(m,n)eye(n,n) M = zeros(M)

If ƒ is an external function (that is, defined by deffor by function, see below), and x and y are vectors, then the function fevalmakes it possible to construct a matrix z = ƒ ( x , y )

z = feval(x, y, f) : Was z ( i , j ) = ƒ ( x ( i ), y ( j ))

The function size(M)returns the size of the matrix as a 2 × 1 matrix containing the number of rows and then the number of columns.

The operations specific to the classical matrices are:

  • The transposition: it is enough to put a point followed by an apostrophe .’after the matrix; using the single apostrophe 'is the transposition of the matrix conjugate ( adjoint operator );
  • Product of matrices * ;
  • Product and ratio element by element: .*and ./ ;
  • The tensor product .*. ;
  • The determinant of a square matrix M: det(M)( determ()for a matrix of polynomials and detr()for a matrix of rational fraction);
  • the traces of a square matrix M: trace(M) ;
  • Unlike an invertible matrix M: inv(M).

A vector is a row or column matrix (matrix 1 × n or n × 1); The expression V(i)denotes the component i of the vector V. If V1 and V2 are column vectors , then the scalar product is V1.' * V2 ; If they are line vectors , the scalar product is V1 * V2.'.

Numerical calculation

Scilab can perform numerical calculations.

It can be used as a calculator simply by entering the operations to be performed.

The function deffallows to define new functions (called “external functions”) that can be expressed with the already predefined operators (the “primitive functions”). Two strings of characters are passed as parameter; The first indicates the name of the function and the variables used for input and output, and the second indicates the formula. For example, the function

Ƒ ( x ) = 2 · x

Can be defined by

Deff ( "[y] = f (x)" , "y = 2 * x" )

(See also Programming section ).

Integration
integrate("expression", "x", x0, x1)Numerically calculates the integral of the function described by expression (it is a string of characters interpretable by Scilab, as "sin(x)"), x being the integration variable, between the values x 0 and x 1.
Solving equations
Scilab has several primitives allowing the solving of equations (see Solver of equations ), among others:

  • linsolve : Resolution of a system of linear equations,
    syntax: [x0, kerA] = linsolve(A, b)
    where A is the real matrix of the coefficients of the system of equations, and b a vector of constants; The solutions of A × x + b = 0 are of the form x 0 + w × kerA, w being an arbitrary real;
  • solve : Symbolic resolution of a linear system,
    syntax: w = solve(A, b)
    where A is an upper triangular matrix of characters (the coefficients of the system of equation), b is a character vector (the right-hand side of the equals), and w is the Matrix result of A × w = b ;
  • ode : Resolution of an ordinary differential equation ( ordinary differential equation ) ; If the differential equation is d y / d t = ƒ ( t ), then ƒ having been defined (external function), the syntax to determine y ( t ) is
    y = ode(y0, t0, t, f)
    where y 0 and t 0 are initial values ​​of the system, t Is a vector of values ​​for which the solutions are calculated, and y is the vector of solutions ( plot(t, y)makes it possible to plot the solution graph);
    The primitive odehas arguments to solve specific situations:"roots""discrete"
There are other primitives for specific systems.

Function plot

Trace 2D

The plot of a function is done in two steps

  1. Define the range of the abscissa variable and the pitch, for example, in the form of a column vector ;x = [début:pas:fin]'
  2. Plot the function with the command plot(x, f(x))if ƒ is the function.

One can trace several functions simultaneously by putting them in a matrix, for example plot(x, [f1(x) f2(x) f3(x)]).

We note in fact that ƒ ( x ) is itself a vector. A vector of the values ​​of x and a vector of the values ​​of y canplot(x, y) generally be defined and the function will plot the cloud of points.

If ƒ is an external function (eg defined with deff, see above, or function, see below), then the function can be plotted directly with fplot2d(x, f). You can also define y by y = feval(x, f), then draw with plot(x,y).

The function xgridallows to display a grid corresponding to the graduations.

The functions , used in place of , make it possible to vary the general appearance of the layout:plot2diplot

  • plot2d : “Normal” feature; Identical to plot, but allows the use of markers;
  • plot2d2 : Staircase;
  • plot2d3 : Drawn in bars;
  • plot2d4 : Plotted in “arrows” (for a vector field);

These functions accept arguments that modify the path, in the form . The arguments are of the form , and are separated by commas.plot2diplot2di(x, y, arguments)mot-clef = valeur

To place markers, use the argument where n is a positive or negative integer (for example ); A negative number replaces the points with markers (a star for -10, circles for -9, …, small points for 0, the list is obtained by typing the command ) and a positive number indicates a solid line but (According to the color map defined, see below).style=nplot2d(x, y, style=1)getsymbol

If the plot has more than one curve (thus put in a Y-line matrix), the argument styleis a matrix, the value of each element indicating the style of each curve, for example

Y = [ cos ( x ), sin ( x )]; Plot2d ( x , y , style = [ - 2 , - 1 ])

You can use the command legend()to write captions, for example

Legend ( "cosine" , "sinus" )

For a logarithmic scale , use the argument where type is a string of two characters, “n” (for normal) or “l” (for logarithmic), the first character corresponding to the x- axis and the second to the axis of there . for examplelogflag = type

  • plot2d(x, y, logflag = "nl")For a linear x- axis and a logarithmic y- axis ;
  • plot2d(x, y, logflag = "ll") To have two logarithmic scales.

We can choose the type of axis with the argument where n is a positive integer: 0 for not having an axis, 1 for “classic” axes intersecting the bottom right, 4 for “classical” axes Cutting at center, 5 for axes intersecting at (0, 0) …axesflag = n

We can define the number of graduations and sub-graduations of the axes with the argument where N x is the number of graduations of the x- axis , nx the number of sub-graduations …nax = [nx, Nx, ny, Ny]

The argument is used to limit the path to the area within the rectangle defined by the values ​​in the matrix.rect = [xmin, ymin, xmax, ymax]

The function plotspolarplot in polar coordinates . The function r ( theta ) is traced by the command:

polarplot(theta,r)

Where r and theta are two matrices of the same dimension.

Map of a field

If x is a column vector of m elements, y is a column vector of n elements and z is a matrix m × n , then the function

Grayplot ( x , y , z )

Will associate a color with each value of z and plot a color map, each point ( x ( i ), y ( j )) having the color associated with the coefficient z ( i , j ).

The color levels are indicated by the function

Xset ( 'colormap' , cmap )

Where cmap is a matrix of three columns, each row of which contains the color associated with a level, in the RGB form (matrix elements from 0 to 1). The first row of the matrix corresponds to the lowest level, the last line to the highest. This matrix can be generated automatically by functions …colormap, for example ( n gray levels between black and white), degraded between blue and red) or (gradient between red and yellow).graycolormap(n)jetcolormap(n)hotcolormap(n)

For example, one can use xset("colormap", graycolormap(32))to have 32 levels of gray. You can make a gradient from black to red with

Cmap = graycolormap ( 32 ); Cmap (:, 2 : 3 ) = 0

or with

R = linspace ( 0 , 32 , 32 ) ' ; Cmap = [ r zeros ( 32 , 2 )]

And a gradient from blue to white with

Cmap = graycolormap ( 32 ); Cmap (:, 2 : 3 ) = 1

or with

R = linspace ( 0 , 32 , 32 ) ' ; Cmap = [ r ones ( 32 , 2 )]

Color levels are also used when drawing several curves on the same graph. In this case, gradients do not provide a contrast that makes it easy to distinguish neighboring curves; You can get the default color levels with get(sdf(), "color_map").

You can draw a level curve with the function

Contour2d ( x , y , z , n )

Where n is the number of levels to be displayed; The values ​​of the levels z 1 , z 2 ,…, Z n can also be given by a vector

Contour2d ( x , y , z , [ z1 , z2 , ... , zn ])

It is also possible to plot a vector field. To do this, we need a matrix vx with the components according to x of the vector field, a matrix vy having the components according to y of this field, and using the function

Field ( x , y , vx , vy )

With the function champ1, the traced vectors all have the same length, the norm of the field is indicated by the color of the vector, according to the principle explained for grayplot.

3D plot

Scilab also allows the drawing of three-dimensional surfaces ( x , y , z ). If x is a matrix column of m elements, y is a matrix column of n elements, and z is an matrix m × n , then the function

Plot3d ( x , y , z )

Will plot the surface of points ( x ( i ), y ( j ), z ( i , j )). If it is a surface representative of a function ƒ, we have

Z ( i , j ) = f ( x ( i ), y ( j )).

If ƒ is an “external” function (for example, defined by deffor function), we can define z with the function feval(see above), or use fplot3d(x, y, f).

The function param3d(fx(t), fy(t), fz(t))plots the parametric curve; T is a vector containing successive values ​​of the parameter.

The functions plot3d1, fplot3d1and param3d1allow the use of color levels to indicate the value of z . The use is identical to that of plot3d, but the color levels are indicated by the function

xset("colormap", cmap)

(see above).

The view of the 3D surface is defined by two angles in degrees, θ, rotation about the Z axis, and α, rotation about the Y axis (see also Euler Angles ): , …;plot3d(x, y, z, theta, alpha)param3d(x, y, z, theta, alpha)

  • plot3d(x, y, z, 0, 0) Gives a view from above, similar to the 2D maps, projection of the surface on the XY plane along the Z axis;
  • plot3d(x, y, z, 90, 0) Gives a front view, projection of the surface on the XZ plane along the Y axis;
  • plot3d(x, y, z, 0, 90) Gives a side view, showing the surface on the plane YZ along the axis X;
  • plot3d(x, y, z, 45, 45)Is the default view, of isometric perspective type .

You can also define the limits of the axes with the keyword ebox :

  • plot3d(x, y, z, ebox=[xmin, xmax, ymin, ymax, zmin, zmax])
  • plot3d(x, y, z, theta, alpha, ebox=[xmin, xmax, ymin, ymax, zmin, zmax])

Representation of statistical data

If x is a vector, the function , n being an integer, will divide the interval of values ​​taken by the coefficients of x into n equal-width tranches and plot the distribution histogram of these values. If n is a vector whose coefficients are strictly increasing, the values ​​of the coefficients of n serve to determine the slices.histplot(n, x)

If x is a matrix, draw a 3D histogram such that the parallelepiped at ( i , j ) has the height x ( i , j ). As with all three-dimensional plotting functions, the angle of view can be defined with θ and α.hist3d(x)

Drawing

It is possible to draw geometric figures directly on the graph.

The function xpoly(x, y, "lines", 1)makes it possible to plot a closed polygon , xbeing the list of the abscissas of the vertices (in the form of a vector or a matrix) and ybeing the list of the ordinates of the vertices (it is a matrix of the same dimension x). The function xfpoly(x, y, "lines", 1)plots a filled polygon.

The function xrect(x, y, l, h)traces a rectangle whose top left point is ( x , y ), of width l and of height h . The function xfrect(x, y, l, h)draws a filled rectangle.

The function writes the string character string on the graphic, the point at the bottom left of the text being at the point ( x , y ).xstring(x, y, "chaîne")

The function xarc(x, y, l, h, a1, a2)traces an ellipse arc comprised in the rectangle whose point at the top left is ( x , y ), of width l and of height h . Each degree of angle is divided into 64 sectors, the arc starts from the trigonometric angle to 1 × 64 ° and goes up to the angle ( a 1 + a 2) × 64 °. The function xfarc(x, y, l, h)traces an ellipse arc filled.

To change the properties of drawing lines, use the command . The main properties of an object are:set("propriété", valeur)

  • line_style : Type of stroke; It is an integer, 0 for a solid line, 2 for long dashes, three for short dots, 4 for a center line (alternation trait-point) …
  • thickness : Line thickness, in the form of a positive integer;
  • mark_size : In the case of a tracing by markers, size of the markers.

You can also associate a variable with the drawn element; This is done with the function
variable = get("hdl")
hdlmeaning handle (literally “handle”, intermediate action). To set the property of this element,

variable.propriété = valeur

These two methods are valid whatever the object (curve, polygon, arc of ellipse …).

for example

Xarc (0, 1, 0.5, 0.5, 0, 360 * 64) // ellipse
Set ("line_style", 2) // dotted

or

Xarc (0, 1, 0.5, 0.5, 0, 360 * 64) // ellipse
A = get ("hdl")
A.line_style=2 / dotted

Formatting, Axes and Windowing

The function is xsetused to define the appearance:

  • Police graduations and titles: where xset("font", type, taille)
    • Size is a number designating the size of the characters, in arbitrary units;
    • Type is a number designating the type of font: 1 for Greek letters (Symbol font), 2-5 for font with Times type serifs (2 for romance letters, 3 italic, 4 bold, 5 italic bold) ; 6-9 for a sans serif font type Arial (6 for Roman letters, 7 in italics, 8 in bold, 9 italic bold);
  • Thickness of the lines of axis and of the trace: where e is a number designating the thickness in arbitrary unit;xset("thickness", e)
  • Size of the markers (if applicable, see below) with .xset("mark size", taille)

As with all graphic objects, you can change the properties of the axes by assigning them to a variable by the command var = get("current_axes"). The main properties are:

  • x_locationAnd y_location : take the values "top", "middle"or "bottom"according to whether one wants the axis to be at the top, passes through the origin, or is at the bottom;
  • isoview : 'on'Applies "off"if the scales are to be identical on the axes, if the scale is free;
  • sub_ticks : Matrix where nx and ny is the number of sub-graduations (it takes 4 sub-graduations for the main graduation to be divided into 5);[nx, ny]

Example:

A = get ("current_axes")
A.x_location = "middle"
A.y_location = "middle"
A.isoview = "on"
A.sub_ticks = [4,4]

Several tracings can be placed side by side with the instruction subplot :

subplot(m, n, i)Places the trace following the instruction in the i- th box (in the European reading order) of an array m × n ; the route can have multiple instructions plot, xset, xtitle.

The function puts a title on the chart and on the axes. The function places a title in the middle of the chart. The function clears the graphics window.xtitle("nom du graphique", "axe des x", "axe des y")titlepage("titre")clf

Example

Example of a graph obtained with Scilab

Here is the graphic obtained with the instructions below.

Clear ; Clf ;
Deff ( "[z] = f (x, y)" , "z = sin (x )
Xset ( "colormap" , jetcolormap ( 32 ))
X = % pi * [ - 1 : 0.05 : 1 ] ' ;
Y = x ;
Z = feval ( x , y , f );
Subplot ( 2 , 2 , 1 )
grayplot ( x , y , z )
Subplot ( 2 , 2 , 2 )
contour2d ( x , y , z , 5 )
Subplot ( 2 , 2 , 3 )
plot3d1 ( x , y , z , 0 , 90 )
Subplot ( 2 , 2 , 4 )
plot3d1 ( x , y , z , 70 , 70 )

Programming

Scilab instructions can be put in a text file with the file name extension .sce. This is called Scilab script .

Scilab accepts a number of instructions:

  • Conditional execution if condition then, …, else, …, end
  • Loop iterative orfor variable = début : fin, …, endfor variable = début : pas : fin, …, end
  • Anteriorated iterative loop: orwhile condition do, …, endwhile condition do, …, else, …, end

It is possible to define functions with parameter passing. The function is a subroutine with its own variables, which can contain loops, conditional branches … For example, to define a function f (x):

Function [y] = f ( x ) ...
 endfunction

The parameter x is passed to the function ƒ; The value returned by ƒ will be the value that is assigned to y in the function.

If a file contains only function definitions, it is given the extension .sci. This makes it possible to create libraries of functions common to several scripts, which facilitates software maintenance (the improvements benefit all the scripts, an error will appear in all the scripts and will therefore be detected more quickly and corrected). This file .sciis then loaded by the script with the command exec("chemin/nomdefichier").

The environment, that is to say the set of variables, including functions, can be recorded with the command . This creates a binary file (Scilab does not add any extension). This environment can be reloaded with the function .save("fichier")load("fichier")

You can also write the instructions in a text file, then copy / paste from the text editor to the Scilab command line. The source code can contain comments entered by two fraction bars //.

Environment

In Scilab, the environment is the set of variables (including functions) that have been defined; The environment contains a number of predefined variables. The set of variables is given by the command who.

When a function is used, the function is executed in a new environment, a copy of the initial environment. The variables that are modified here are not in the initial environment (only working in local variables), only the result of the function is returned.

One can deliberately open an environment, with function pause ; The prompt then becomes -1->, indicating that you are in the first sub-environment level. It is also in such a configuration when interrupting the execution of a function (for example with the key combination CTRL + C). To return to the previous environment, use the command return.

If returnno argument is used , variables are not passed to the parent environment. It is possible to transmit the variables has one, a 2, …, an in the parent environment, with the syntax , where x 1, x 2, …, xn are the names of variables in the parent environment.(x1, x2, …, xn) = return(a1, a2, …, an)

The command clearallows to “clean” an environment, that is to say to delete all the variables.

Interface with other languages

Scilab interfaces easily with the Tcl-Tk scripting language and allows to display graphical interfaces. The function evaluates Tcl-TkTCL_EvalFile() scripts that can use Scilab functions by passing parameters via .ScilabEval

Example: Calculation of a distance whose x, y or z values ​​can be varied by moving a cursor in the graphical interface written in Tcl-Tk .

We create three files ( lancement.sce, distance.sci, gui.tcl).

The two Scilab files:

// launch.sce - start the application
Exec distance . Sci ;
TCL_EvalFile ( "gui.tcl" );
// distance.sci - Scilab function
Function dist = distance ( x, y, z ) dist = sqrt ( x * x + y * y + z * z ) endfunction

And the Tcl-Tk code:

# Gui.tcl - graphical interface
Global xyz dist
Set x 10 ; Set y 10 ; Set z 10 ; Set dist ""
toplevel .w
 scale .w.scx - from 0 - to 200 - length 200 - Resolution 1 - label "X" \
 -orient horiz - bd 1 - showvalue true - variable x \
 -command CalculDistance
 scale .w.scy - from 0 - to 200 - length 200 - resolution 1 - label "Y" \
 -orient Horiz - bd 1 - showvalue true - variable y \
 -command CalculDistance
 scale .w.scz - from 0 - to 200 - length 200 - Resolution 1 - label "Z" \
 -orient horiz - bd 1 - showvalue true - Variable z \
 -command CalculDistance\ -orient horiz - bd 1 - showvalue true - variable z \ -command CalculDistance
label .w.lt - text Distance
 label .w.ldist - textvariable dist - bg lightblue
 eval pack [ winfo children .w ]
Proc DistDistance w {
 global xyz dist
 ScilabEval "dist = distance ($ x, $ y, $ z); TK_SetVar ('dist', string (dist)
}

Notes and references

  1. ↑ http://www.scicos.org/history.html  [ archive ]
  2. ↑ http://www.scilab.org/scilab/history  [ archive ]
  3. ↑ http://raweb.inria.fr/rapportsactivite/RA94/meta2/META2.3.1.1.html  [ archive ]
  4. ↑ ” Sciweb [ archive ] (accessed February 9, 2016 )
  5. ↑ Scilab license  [ archive ]
  6. ↑ Definition of semi-free software  [ archive ]
  7. ↑ Change of license announcement  [ archive ]