[go: up one dir, main page]

0% found this document useful (0 votes)
12 views6 pages

Introduction To Scilab

Scilab is a software that supports various mathematical operations, including arithmetic, algebra, graphics generation, and solving differential equations. It features multiple data types such as constants, doubles, integers, booleans, complex numbers, strings, polynomials, and lists, allowing for flexible programming and data handling. Variable naming in Scilab follows specific rules, and all variables are stored in double precision by default, which may lead to representation errors in calculations.

Uploaded by

Danmar Malalis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

Introduction To Scilab

Scilab is a software that supports various mathematical operations, including arithmetic, algebra, graphics generation, and solving differential equations. It features multiple data types such as constants, doubles, integers, booleans, complex numbers, strings, polynomials, and lists, allowing for flexible programming and data handling. Variable naming in Scilab follows specific rules, and all variables are stored in double precision by default, which may lead to representation errors in calculations.

Uploaded by

Danmar Malalis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

SCILAB

Scilab is provided with a number of demos to show the software


abilities. SCILAB can be used for simple arithmetic operations as well as for
some algebraic operations, to generate graphics, to program functions, and to
solve linear algebra problems and ordinary differential equations, among other
things. You can also program SCILAB and produce simple or fancy graphic
user interface components for your program.

Data Types

 Constant - are special variables that are defined in Scilab. The titles imply
that the values of these variables cannot change; they are constant. To
access these variables, use the character "%" at the beginning of the
name.

 Double - It is important to note that the default type of a numeric value in


Scilab is double. For example, in a=1 or a=[1,2], a is treated as a double.

 Integers (int8, int16, int32)


 int8 - conversion to one byte integer representation.
 int16 - conversion to 2 bytes integer representation.
 int32 - conversion to 4 bytes integer representation.
- These data types are especially useful to store big objects such as
images, long signals,…

 Boolean - A boolean variable is either %t (for "true") or %f (for "false").


These variables can be used to define boolean matrices using the
standard syntax. Boolean matrices can be manipulated as ordinary
matrices for elements extraction/insertion and concatenation.

 Complex - c=complex(a) creates a complex number from its real part a


and zero as the imaginary part. c=complex(a,b) creates a complex
number from its real part a and imaginary part b.

 String - in the programming/coding world, a string is any finite sequence of


characters. The characters can be either letters, numbers, symbols or
punctuation marks. The complete list of characters is given by the ASCII
(American Standard Code for Information Interchange) standard.

 Polynomial - The Scilab function for polynomials definition is poly().


Depending on the options of the function, the polynomial can be defined
based on its coefficients or its roots.

 List - The list is a collection of data objects not necessarily of the same
type. A list can contain any of the already discussed data types (including
functions) as well as other lists. Lists are useful for defining structured
data objects. There are two kinds of lists, ordinary lists and typed-lists.
 Functions - Usually, they are defined in files with an editor and loaded into
Scilab using the exec function or through a library (see lib or genlib). But
they can also be defined on-line (see deff or function. A function is defined
by two components:

1. a "syntax definition" part as follows:

function [y1, ..., yn]=foo(x1, ...,xm)


function [y1, ..., yn, varargout]=foo(x1, ...,xm,varargin)

2. a sequence of Scilab instructions.


The "syntax definition" line gives the "full" calling syntax of this function.
The yi are output variables calculated as functions of input variables xi
and variables existing in Scilab when the function is executed.

 Graphics Handle

Constants – Special Scilab Variables


In Scilab are defined some special variables which are called constants. The
names suggest that these variables can not change their values, they are
constant. In order to access these variable the character „%” must be used at
the beginning of the name.

The values of these variables can not be changed, they are protected to
writing. If you try to assign a different value to any of them, Scilab will output
an error message without taking into account the instruction:
These special Scilab variables are considered predefined, they can not be
deleted nor saved using the save function. A part of these variables are
defined in the scilab.start file which can be found in SCI + “/etc” folder.

Hint: Instead of %i, the Scilab user can use sqrt(-1).

Scilab Variables – naming, real numbers, constants


Every Scilab script, function or routine that we need to write will contain for
sure variables. From the variables point of view Scilab is very flexible, similar
to Matlab®.

Scilab variables are named also objects. So in other tutorials, books, you’ll
find “objects” instead of “variables”. I prefer to call them variables maybe
because the term “variables” is used in other programming languages like C
or Python.

In order to define a variable, in the Scilab console type: „variable name” =


„value” and press <ENTER>:

Variable naming rules


Scilab has specific rules for variable definition that must be taken into
account. The variable names can contain any:
letters, uppercase or lowercase (e.g. vAriaBle)
numbers, except for the first character (e.g. var1aBl3)
of the following characters (e.g. #first_variable)

* The percent character can only be used as first character in the variable
name

The length of the variable name is limited to 24 characters. Any characters


above 24 will be ignored.

-->_12345678910111213141516171819202122232425 = 10
Warning :
The identifier : _12345678910111213141516171819202122232425
has been truncated to: _12345678910111213141516.

_12345678910111213141516 =

10.

-->

But since the version is now updated, then we observe that there is no
warning notice even if we input more than 24 characters
Be ware that the variables names are stores in the same space with function
names. So if you name your variable the same as a function, Scilab will use
the variable instead of function.

In the example above we have created a variable named sin which will be
used as a variable instead as a trigonometric function. Scilab warned me
about this function redefining! After sin declaration I can used it as an ordinary
variable. This was not normally possible with a function (see example with
cos).

Even if it’s not recommended from the readability point of view, you can define
a Scilab variable name as:

Real numbers
Default coding for Scilab variables is in double precision, on 64 bits. So if you
don’t specify the data type of the variable, Scilab will store it as double.
Since all the variables are coded in a specific format they have an
representation error. That means that the calculation done in Scilab are not
exact but with a very good accuracy. Nevertheless the variable coding within
Scilab is sufficient for the most of the applications.

In order to see the approximation for the example above we will change the
display format of the variable to see the maximum number of digits:

You can clearly see that 3.6 is not represented exactly but approximately with
a very good precision. More, if we want to check if Scilab is interpreting
3.6000000000000000888178 as 3.6 we will use the following code:

where T is a Scilab Boolean variable for „true”.

You might also like