electroSome

Getting Started with Scilab – Beginners Tutorial

SCILAB Logo

SCILAB Logo

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

 Install Scilab

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,

SCILAB – Environment

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

Simple Calculations

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,

Doing Simple Calculations in SCILAB Console

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.

Variables

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.

Variable Browser – SCILAB

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.

-->clc

Numbers

In SCILAB we can deal with generally three types of 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...

Viewing Variables

To display a list of all variables currently being used in SCILAB we can use the command ‘who’

-->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.

-->whos

Clearing Variables

We can erase a variable from memory if it is no longer required by using the command, clear variable_name.

-->clear c

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.

-->clear

Exit SCILAB

To exit SCILAB we can use the ‘ exit ‘ command. Note that all unsaved variables will be cleared prior to exit.

-->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’.

Loading Variables – SCILAB

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.