Introduction Scilab is a numerical calculation program that anyone can download free of charge. It is recommended for university use as a replacement for MATLAB. Available for Windows, Linux and Max OS X. You can download it at t h e following address 2. Scilab software environment Scilab is launched (under Windows) by double-clicking on the icon, usually located on the desktop. This opens a window, but you must wait for the --> arrow to appear before using the software. The main window is made up of 5 sub-windows: 1 File Browser: specifies the current directory (the one you're working in), and lets you browse the file system. 2 Scilab console (also known as the terminal): this is the window in which commands are typed for immediate execution, and in which responses are displayed. 3 Variable browser: contains the name, size and type of variables recognized by the console. 4 Command history: contains all command lines validated in the console. 5 This is the news notification zone, added in version 6. Ferhat Abbas University SETIF 1 Faculty of Science OPM Course 1 Scilab lakhdar.amrani@univ-setif.dz Page 2/7 L. Amrani The Scilab workspace is made up of several windows: • The console for calculations, • The editor for writing programs, • Graphics windows to display graphics, • Help. - The console An instruction typed in the console is immediately executed after validating at using the enter key. Then there are two possibilities: - if the command line ends with the ; symbol, the instruction is executed but the result is not displayed on the screen (which can be useful if the result is an array of 10,000 numerical values). Execution is said to have taken place without echo. - if the command line does not end with the ; symbol (in which case it ends with a space or the , symbol), the instruction is executed and the result displayed. A command line can be modified until it has been validated. Once validated, however, it can no longer be corrected. However, any previously validated command line can be recalled from the console by using the up and down arrows on the keyboard: ↑ and ↓ . If an instruction produces a result and does not include an assignment instruction (i.e. the result is not stored in a variable), then Scilab stores the default result in the variable ans (short for answer). Scilab software features a Help Browser accessible via the ? tab or the F1 key. If you know the name of the function for which you are looking for help, you can also use the help instruction followed by the function name in the console. The help instruction alone provides an alternative to access the help browser. Ferhat Abbas University SETIF 1 Faculty of Science OPM Course 1 Scilab lakhdar.amrani@univ-setif.dz Page 3/7 L. Amrani 3. Number manipulation with Scilab All numbers manipulated are complex numbers of the form x + i y where x and y are two decimal numbers. By default, decimal numbers are given in decimal form with 7 significant digits. The complex number i such that i 2 = -1 is represented in Scilab by the syntax %i. The decimal numbers used in Scilab are between 2.10−38 and 2.1038 , with a precision of 2.22.10−16 . Number operations are performed using the following symbols: + (addition) - (subtraction) * (multiplication) / (division) ^ (power) In a calculation line, the order used by Scilab is the same as that used in mathematics, i.e. in descending order of priority: ^, then * or /, then + or -. To change this order, parentheses are used. Example For example : -->2*3-5 years= 1. -->2-3*5 years = - 13. -->(2-3)*5 years = - 5. The number π is used via the symbol %pi and the number e via %e. These are, of course, only approximations of the numbers. The following functions, already defined in the software, are also available: log (neperian logarithm ln) exp (exponential) floor (integer part) abs (absolute value) sqrt (square root) sin (sine) cos (cosine) Ferhat Abbas University SETIF 1 Faculty of Science OPM Course 1 Scilab lakhdar.amrani@univ-setif.dz Page 4/7 L. Amrani 4. Variables and assignments Variables are "memory boxes" in which a value is stored. This value can be modified throughout the program. A variable is identified by a name (or identifier). This name must not contain spaces, accents or apostrophes, and must begin with a letter. Scilab is case-sensitive, i.e. upper and lower case. When you modify the value of a variable, you assign it a value. To assign a value to a variable, use the following syntax: -->Name=Value or -->Name=Value; (without echo) If there is no variable called Name, this instruction creates a variable Name and assigns to it Value. If a Name variable already exists, this instruction deletes the previous assignment and replaces it with Value. When a variable is created, its name appears in the Variable Browser with an icon indicating the nature of its contents. - The syntax must be respected: what is to the left of the = symbol is modified/created by what is to the right of the =. - If you use a variable name not previously defined in Scilab to the right of = you cause an error. Example Assignment with echo : -->x=2*3 x = and without echo: -->x=2*3; - The value of a variable is modified throughout the program. For example, what is the value of x at the end of the following instructions ? -->x=2*3; -->y=4; -->y=2*y+1; -->x=x*y; To find out the value assigned to an existing variable, simply type its name in the console and validate. For example, in the previous example : -->x x = 54. 6. Ferhat Abbas University SETIF 1 Faculty of Science OPM Course 1 Scilab lakhdar.amrani@univ-setif.dz Page 5/7 L. Amrani To find out which variables have been created, use the who command (or whos, which has a different display). The clear command deletes all variables. The clear x command deletes only variable x. 5. Character strings It's a data type (as is the number type), used to manipulate text in Scilab. A string is a sequence of alphanumeric characters (the characters available on a computer keyboard). In the Scilab language, character strings are delimited by apostrophes '. If a string already contains the ' character, it must be doubled. Example For example : --> When a years = When a You can assign a character string to a variable. Example For example : --> a = 'Scilab' a = Scilab - Scilab distinguishes a string of digits from the number it represents. For example, '12' is different from 12: the first is a string and the second a number. Example For example : --> Txt = '12+13' Txt = 12+13 The instruction Txt='12+13' assigns the variable Txt the value 12+13 (not 25), which is a five-character string. The icon associated with Txt in the Variable Browser indicates the presence of a character string. The number of characters in a string A is obtained with the instruction length(A). Example For example : --> length('toto') ans = 4. Ferhat Abbas University SETIF 1 Faculty of Science OPM Course 1 Scilab lakhdar.amrani@univ-setif.dz Page 6/7 L. Amrani If A is a string, then part(A,i) returns its i -th character (with the convention that they are numbered from 1). Example For example : --> A = '13=XIII' A = 13=XIII --> part(A,1) years = 1 --> part(A,2) years = 3 --> part(A,3) years = = --> part(A,8) years = More generally, the instruction part(A,i:j) gives the substring extracted from A, made up of the characters between positions i and j (inclusive). Example For example : --> Txt = '12+13'; --> part(Txt,2:4) ans = 2+1 The addition + operator is used to paste two strings together: this is the concatenation. Example For example : --> A = 'Toto' A = Toto --> B = 'Hello ' B = Hello --> B + A years = Hello Toto Ferhat Abbas University SETIF 1 Faculty of Science OPM Course 1 Scilab lakhdar.amrani@univ-setif.dz Page 7/