# Scilab Operators Keyword variable Loops functions

Scilab basic contains basics of Scilab language. you will familier with all basic terms of Scilab.

## What is Scilab?

Scilab is free and open-source software for engineers & scientists. Scilab was developed with the Scilab team within the ESI Group.

It is a high-level numerical-oriented programming language.

Sci lab is used for Mathematics and Simulation, Optimization, Statistics Signal Processing,  Algorithm and application development, 2D and 3D data visualization, Image processing and Computer vision, in the field of IoT.

Scilab is an interpreted language. IT has a variety of functions to solve complex problems easily.

Scilab is available under the GPL License. It means any one can

Use the software for any purpose,

Change the software to suit your needs,

Share the software with your friends and neighbors, and

Share the changes you make.

## Scilab Basics

it contains following topics

1. Keyword
2. Variables
3. Constants
5. Operators
6. If else
7. looping
8. functions
9. file creation in Scilab

## Scilab keywords

Following are keywords in Scilab

• backslash â€” (\) left matrix division.
• brackets [,;] â€” Concatenation. Recipients of an assignment. Results of a function
• colon (:) â€” Ranging operator. Addresses all elements along an array dimension or of a list.
• comma â€” (,) comma; instruction, argument separator
• comparison â€” comparison, relational operators
• dollar â€” (\$) last index
• dot â€” (.) symbol
• equal â€” (=) assignment , comparison, equal sign
• getscilabkeywords â€” returns a list with all scilab keywords.
• hat â€” (^) exponentiation
• greater â€” (>) greater than comparison
• minus â€” (-) subtraction operator. Sign change
• not â€” (~) logical not
• parentheses â€” ( ) left and right parenthesis
• percent â€” (%) special character
• plus (+) â€” Numerical addition. Text concatenation (gluing)
• quote â€” (‘) transpose operator, string delimiter
• semicolon â€” (;) ending expression and row separator
• slash â€” (/) right divisions. System’s feed back. Comments
• star â€” (*) multiplication operator
• symbols â€” scilab operator names
• tilde â€” (~) logical not

## Scilab variables

In Scilab everything is the matrix. Scilab uses Boolean, string, integer, and complex numbers

### Rules for Variable names

• Variable names can take as long as you want.
• Variable are case sensitive.
• It allows characters (A-Z,a-z) digits(0-9) and special symbols(%,_,#,!,\$,?).
• First letter must be character or special character (%,_,#,!,\$,?).
• Multilingual UTF-8 characters are accepted.

Assigning value to variable

## Scilab Constants

Sr No Constant Description
1 SCI, WSCI Variable containing the value of the root path of Scilab.
2 SCIHOME Contains the path to preferences, history files of your Scilab session.
3 TMPDIR Temporary directory path.
4 home Gives the user directory.
5 %e Euler number.
6 %eps epsilon (floating-point relative accuracy)
7 %f or %F Boolean variable for false.
8 %i imaginary unit
9 %inf infinity
10 %nan not-a-number
11 %pi ratio of circle’s circumference to its diameter
12 %s A variable used to define polynomials.
13 %t or %T Boolean variable for true.
14 %z A variable used to define polynomials.

To make single line comment // are used and to make multiline comment /*  and  */

are used.

Example

`// This is a single line comment`

`/* this isMultiline comment*/`

## scilab Basic Operators

### Arithmetic Operators

Scilab has following arithmetic operators

Sr No Operator Example
2 – (Substraction) 5-4=1
3 * (Multiplication) 5*4=9
4 / (Division) 4/2=2
5 ^ (Power) 2^3=8

### relational operators in scilab

Scilab has following relational operators

Sr No Operator Example
1 > 5<6Â (Less than)Â Â Â Â Â Â  T
2 < (Greater than) 6<7Â Â Â Â Â Â Â  F
3 Â Â  <=Â  (Less than equals to) 5<=6Â Â Â Â  T
4 Â  >= (Greater than equals to) 6>=7Â Â Â Â  F
5 ==Â Â  (Equals to) 6==6Â Â Â Â  T
6 ~=Â  (Not Equals to)Â Â  orÂ  <> 7 ~=5Â Â Â Â  F

## scilab not equal

The not equals in sci lab is mentiond as ~=  (Not Equals to)   or  <>

### logical operators in scilab

Logical operator of scilab is as below

Sr No Operator Example
1 & (AND) %T & %F  F
2 |  (OR) %T |%F T
3 ~ (NOT) ~%T F

## if else in scilab

In programming, we have to choose any one choice either this or that. in this case to choose one among two options we use if-else statement.

Syntax of if-else is as below

Let’s see one example to check the greater among two numbers

Output

Using both if and else condition is Scilab

Output

## Select Statements

To select among multiple options scilab uses select statements

Syntax is select statement

Based on matching case expression statements are executed.

If no case expression is matched then else part is executed.

Here else is optional.

Example of case statement is as below

Output

## Looping Statements

Scilab supports for and while statements for looping

## scilab for loop

Syntax of for statment

Output

## How to perform a reverse loop in Scilab?

Output

### Use of break and continue in Scilab

The break is used to end the looping statements.

Continue transfer the control to the beginning of the loop statement.

## Example of break in Scilab

When break keyword is used in above program it break the loop and print value 1,2 and 3.

Output

## Example of continue in scilab

When continue occurs in the program it transfers the control to the beginning of the loop

Output

1. While  is a another looping keyword

Syntax is

`while expr `
`    statements`
`end`

## Functions in Scilab

Function definition syntax

Scilab function to add two numbers.

Above is a function definition. To call sum function use `sum(val1,val2)` as below.

## How to create a file is Scilab

open a new file

write a basic statement

`disp("Display from file")`

Save file.

Press F5.

this will execute the command on the command window.

Q Scilab uses which library for numerical computation

As per Scilab.org On Windows, if your machine is based on an Intel processor, theÂ Intel Math Kernel Library (MKL)Â enables Scilab to perform faster numerical computations.