Getting Started with Scilab – Beginners TutorialKarthik Narayanan
In our previous posts we had explained how to use and perform complex calculations and signal processing using MATLAB. Now we shall see an all new mathematical modelling tool, the SCILAB
SCILAB provides a powerful computation environment along with a rich collection of numerical algorithms to quench the needs of both the engineering and scientific community. Scilab is released as open source under the CeCILL license (GPL compatible), which means that it is free of cost. Being a high level programming language, it provides access to a verity of features like advanced data structures and 2-D an 3-D graphical functions.
Its capabilities include
- Linear algebra, sparse matrices,
- Polynomials and rational functions,
- Interpolation, approximation,
- Linear, quadratic and non linear optimization,
- Ordinary differential Equation solver and differential Algebraic Equations
- Classic and robust control, Linear Matrix Inequality optimization,
- Signal processing,
Being a freeware SCILAB is available for download at its official website, whatever your platform may be (i.e. Windows, Linux or Mac). You can download it here.
So all windows users has to do it to just download the file and follow the install wizard.
Environment and Console
When you launch SCILAB the environment will consist of the following windows,
- File system
- Variable browser
- Command history
Their specific uses are self explanatory but it is the console that is most commonly used to run SCILAB programs. Now let us see how to use SCILAB
The console provides an interactive platform to type commands and analyze the results in SCILAB. The commands you type will be printed beside the ‘ –> ‘ (known as the prompt) and pressing the enter key will execute the statement. For example, this is what happens when you type ‘ 2 + 3 ‘ in the console, and press the ‘enter’ key,
Now, consider the commands,
-->a = 1 + 2 a = 3
Here the result of the expression will be added to the variable named ‘a’. As of the previous command the result was stored in a default variable ‘ans’ used whenever a variable to store the result is not specified.
The same format can be followed for all mathematical computations like additions, subtraction, multiplication or division.
In SCILAB, the equal to sign is used to assign values to variables as in
-->b = 3 b = 3. --> c = 4.945 c = 4.945
As you can see the statement you typed will be mirrors back to you as the value is assigned to the variable. The list of variables used until now and their values can be viewed in the variable browser as shown below.
A semicolon can be used to avoid the mirroring of the output back to the user.
-->b = 3; -->c = 4.945;
Clearing the Console
To clear the console we can use the ‘ clc ‘ command.To use it, type ‘ clc ‘ and press enter.
In SCILAB we can deal with generally three types of numbers.
- Real numbers.
- Complex numbers
We have already deal with integers and real numbers. Complex numbers in SCILAB can be represented in rectangular format with the value of √-1 represented as ‘ %i ‘. So to set the value ‘2 +4i’ to a variable c,
-->c = 2+4*%i c = 2. + 4.i
As opposed to MATLAB which uses Inf,-Inf and NaN to represent non numbers, division by zero or other similar operations will invoke errors in SCILAB.
-->0/0 !--error 27 Division by zero... -->7/0 !--error 27 Division by zero...
To display a list of all variables currently being used in SCILAB we can use the command ‘who’
Similarly the command ‘ whos ‘ can be used to view the list of variables along with it’s type, size and the number of bytes it uses up.
We can erase a variable from memory if it is no longer required by using the command, clear variable_name.
Now if we use ‘whos’ to view the used variables we can find that c will now be cleared from that list. Alternatively we can use the ‘ clear ‘ command to clear all user defined variables.
To exit SCILAB we can use the ‘ exit ‘ command. Note that all unsaved variables will be cleared prior to exit.
Saving and Loading Variables
To save all variables prior to exiting SCILAB we can use the ‘ save ‘ command. It uses the syntax ‘ save file_name ‘.
-->a = 1 a = 1. -->b = 2 b = 2. -->c = 3 c = 3. -->save var
Now these variable s have been stored to a file named ‘var’ (in ‘my documents’ by default) to load the file after restarting SCILAB use the command, ‘load file_name’.
In this article you familiarized with the SCILAB environment and learned to perform simple calculations using SCILAB. In my next post we will follow this up by introducing functions and learning to perform much more complex calculations.