Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Scilab Programming Language

BY ALESSANDRA WILLIAMS

12-A

Installing the program

1. Installing the Program

1.

Go to the link:

https://cloud.scilab.in/

2.

2. Running the program

Using this link, you can run any Scilab program. First, you insert the structure you want to run where it says “Scilab code”. Then, you select “execute” to run the program. Finally, the result will appear in the section that says “Result”. To reset the runned program, select “Reset”.

Running the program

3. Basic Syntax/ Structure

3.

The basic data is a 1D or 2D array.

a = 1; a = 2+1i; % real and complex numbers

b = [1 2 3 4]; % row vector

c = [1; 2; 3; 4]; % column vector

d = 1:2:7; % here one has d=[1 3 5 7]

Basic Sintax

Example

A

The code for the topic.

4. Types of Variables

4.

Types of Variables

a. Integer: int(X) returns the integer part of the real matrix X. Same as fix.

b. Float: A floating point system is defined by the four integers β, p, emin and emax where

• β ∈ N is the radix and satisfies β ≥ 2,

• p ∈ N is the precision and satisfies p ≥ 2,

• emin, emax ∈ N are the extremal exponents such that emin < 0 < emax.

c. String: The string function converts a matrix x into a matrix of strings.

If x is a function [out, in, text] = string(x) returns three vectors of strings: out is the vector of output variables, in is the vector of input variables, and text is the (column) vector of the source code of the function.If x is a lib variable (library), text is a character string column vector. The first element contains the path of library file and the other the name of functions it defines.

Integer Example

A

The code for the topic.

Float Example

A

The code for the topic.

String Example

A

The code for the topic.

5. Operators

5.

Operators

Arithmetic: Within Scilab we can perform: additions, subtractions, multiplications, left and right divisions and exponentiation. Except for exponentiation, all mathematical operations can be applied to scalars, vectors, and matrices. Also, Scilab sets priorities regarding the calculation order.

Relational: In order to compare two or more variables between them, Scilab uses the relational operators. With these operators, you can make the following comparisons: smaller, greater, smaller or equal, greater or equal, equal, not equal

Logic: In order to perform logical operations in Scilab we can use AND, OR, and NOT operators. The logical operators are mostly used within conditional loop like: if, while, etc.

Arithmetic Example

A

The code for the topic.

Relational Example

A

The code for the topic.

Logic Example

A

The code for the topic.

6. Comments

6.

Comments

A sequence of two consecutive slashes // out of a string definition marks the beginning of a comment. The slashes as well as all the following characters up to the end of the lines are not interpreted.

Another way to comment a block of code is to use /* at the beginning and */ at the end. It is more useful than // which must be positioned at the beginning of each line to comment.

Inside a function, the first comment lines, up to the first instruction or an empty line may be used to provide the default contents for the function help.

Example

A

The code for the topic.

7. Conditional Statements

7.

If-Else: The if statement evaluates a logical expression and executes a group of statements when the expression is true.

The expri are expressions with numeric or boolean values. If expri is a non-scalar value then the condition is true only if all entries of this value are true or different from zero.

The optional elseif and else provide for the execution of alternate groups of statements. An end keyword, which matches the if, terminates the last group of statements. The line structure of if is not significant, the only constraint is that each then keyword must be on the same line as its corresponding if or elseif keyword.

The keyword then can be replaced by a carriage return or a comma.

Conditional Statements

Example

A

The code for the topic.

Video tutorial

VIDEO

Learn more about creating dynamic, engaging presentations with Prezi