Scilab Unit 1
Scilab Unit 1
Scilab Unit 1
Unit – I
Outline Views
Overview of Scilab
How to get started with Scilab
Getting help from Scilab
demonstrations and macros
The Console – The Editor
Batch Processing
Creating Real Variables
Elementary mathematical functions – Booleans
Complex Numbers - Integrers
Floating Points - Strings - Dynamic Variables
Overview of Scilab
•Scilab is a scientific software package for numerical computations providing a
powerful open computing environment for engineering and scientific applications.
•Developed since 1990 by researchers from INRIA (French National Institute for
Research in Computer Science and Control) and ENPC (National School of
Bridges and Roads), it is now maintained and developed by Scilab Consortium
since its creation in May 2003 and integrated into Digiteo Foundation in July
2008.
•Since 1994 it is distributed freely along with source code through the Internet
and is currently being used in educational and industrial environments around the
world. From version 5 it is released under the GPL compatible CeCILL license.
Cont…
•Scilab includes hundreds of mathematical functions with the possibility to add
•Scilab has been designed to be an open system where the user can define new
•• Basic data type is a matrix, and all matrix operations are available as built-in
•operations.
<path>/scilab-5.2.0/bin/scilab.
•When this script is executed, the console immediately appears and looks exactly
the same as on Windows.
Nevertheless, it has one little drawback: the version of Scilab packaged for your
Linux distribution may not be up-to-date. This is because there is some delay
(from several weeks to several months) between the availability of an up-to-date
version of Scilab under Linux and its release in Linux distributions.
•For now, Scilab comes on Linux with a linear algebra library which is
optimized and guarantees portability. Under Linux, Scilab does not come
with a binary version of ATLAS, so that linearalgebra is a little slower for
that platform.
Installing Scilab under Mac OS
•Under Mac OS, the binary versions are available from Scilab website as a .dmg le.
This binary works for Mac OS versions starting from version 10.5. It uses the Mac OS
installer, which provides a classical installation process. Scilab is not available on
Power PC systems.
•Scilab version 5.2 for Mac OS comes with a Tcl / Tk library which is disabled for
technical reasons. As a consequence, there are some small limitations on the use of
Scilab on this platform.
•For example, the Scilab / Tcl interface (TclSci), the graphic editor and the variable
editor are not working. These features will be rewritten in Java in future versions of
Scilab and these limitations will disappear. Still, using Scilab on Mac OS system is
easy, and uses the shorcuts which are familiar to users of this platform.
• For example, the console and the editor use the Cmd key (Apple key) which is found
on Mac keyboards. Moreover, there is no right-click on this platform. Instead,
Scilab is sensitive to the Control-Click keyboard event.
How to get help
•The most simple way to get the online help integrated to Scilab is to use the
function help.
•To use this function, simply type "help" in the console and press the <Enter>
key, as in the following session.
help
•Suppose that you want some help about the optim function. You may try to
browse the integrated help, and the optimization section and then click on the
optim item to display its help.
•Another possibility is to use the function help, followed by the name of the
function which help is required, as in the following session.
help optim
•Scilab automatically opens the associated entry in the help.
•We can also use the help provided on Scilab web site
http://www.scilab.org/product/man
•A list of commercial books, free books, online tutorials and articles is presented
on the Scilab homepage:
http://www.scilab.org/publications
Mailing lists
The mailing list [email protected] is designed for all Scilab usage questions.
To subscribe to this mailing list, send an e-mail to
[email protected] .
•The mailing list [email protected] focuses on the development of Scilab, be it
the development of Scilab core or of complicated modules which interacts deeply
with Scilab core.
•To subscribe to this mailing list, send an e-mail to
•[email protected] .
•These mailing lists are archived at:
http://dir.gmane.org/gmane.comp.mathematics.scilab.user
and
http://dir.gmane.org/gmane.comp.mathematics.scilab.devel
•Therefore, before asking a question, users should consider looking in the
archive if the same question or subject has already been answered.
Scilab wiki
•The Scilab wiki is a public tool for reading and publishing general information
about Scilab:
http://wiki.scilab.org
•An efficient way of getting up-to-date information is to use RSS feeds. The RSS
feed associated with the Scilab website is
http://www.scilab.org/en/rss_en.xml
We make our first steps with Scilab and present some simple
tasks we can perform with the interpreter.
•The command-line interface clear, clc et, clf erase respectively data in memory,
the commands on the screen and the plots. These commands should be executed
regularly to avoid errors and make the memory free.
The Console’s menu bar(1/6): File
The Help Browser is not very helpful and it does not even recognize the
Interrupt command
The Console’s menu bar(5/6): Applications
Scilab Web
Scilab Help: Same as the question resources
mark icon in the Toolbar
Hints:
Scilab is case-sensitive.
// is not interpreted (it is a
comment line)
% is used in front of defined
keywords (e.g. %e = 2.718)
The $ symbol stands for the
last row or last column index of
a matrix or vector.
The colon symbol stands for
“all rows” or “all columns”
Shift Right/Left:
Indent/unindent a row by one
step (this pair should be on the
toolbar)
Comment/Uncomment Selection:
Add/delete a comment
Editor menu bar: Preferences
Console Editor
Graphics Window
Help Browser
The Editor
We can also select a few lines in the script, right click (or Cmd+Click under Mac),
and get the context menu.
The Edit menu provides a very interesting feature, commonly known as a "pretty
printer" in most languages.
This is the Edit > Correct Indentation feature, which automatically indents the
current selection.
The editor provides a fast access to the inline help. Indeed, assume that we have
selected the disp statement.
When we right-click in the editor, we get the context menu, where the Help about
"disp" entry allows to open the help associated with the disp function.
How to use:
Editor
Hints:
When save file, remember write filename + extension
(*.sce , *.sci )
.sce files are executed
.sci files are loaded to be used when we need them
Built-in functions
Below is a list of common math functions in Scilab. A full list of built-in
functions can be found under Help\Elementary Functions, which also
explains requirements on arguments (there are both mandatory and
optional arguments).
Scilab Variables
• Special variables:
– ans: default variable name for the result.
– %pi: π = 3.1415926
=> % is used in front of defined keyword
- %i : i is an imaginary number
- %inf : infinity (∞)
ASCII stands for American Standard Code for Information Interchange
41
The fact that obtained value of sin(Pi) is
not exactly equal to 0 is a consequence of
the fact that Scilab stores the real numbers
with limited precision.
42
Complex Numbers
43
-->x=1+%i
x =
1. + i
-->x'
ans =
1. - i
-->y=1-%i
y =
1. - i
-->real(y)
ans =
1.
-->imag(y)
ans =
- 1.
-->x*y
ans =
2.
44
Lists
• Real
• String
• Matrix
• Boolean
• Polynomial
Example:
list_variable=list(142, "someText", [1 4;6 2], %T, %s^2+1)
The type and typeof functions
These two functions are useful when processing the input arguments of a function.
The type and typeof functions
Strings
48
Strings
-->X="Mathematics"
X =
Mathematics
-->Y="Workshop"
Y =
Workshop
-->X+Y
ans =
MathematicsWorkshop
49
Strings
50
Strings
51
Strings
52
Polynomials
Scilab allows to manage univariate polynomials. The implementation is based
on a vector containing the coefficients of the polynomial. At the user's level, we
can manage a matrix of polynomials. Basic operations like addition,
subtraction, multiplication and division are available for polynomials. We can,
of course, compute the value of a polynomial p(x) for a particular input x.
Moreover, Scilab can perform higher level operations, such as computing the
roots, factoring or computing the greatest common divisor or the least common
multiple of two polynomials. When we divide one polynomial by another
polynomial, we obtain a new data structure representing the rational function.
53
Polynomials
54
Polynomials
55
Polynomials
56
Polynomials
57
Scilab Arithmetics Operators
Operator Description
+ Addition
- Subtraction
.* Multiplication (element wise)
./ Right division (element wise)
.\ Left division (element wise)
= Assignment operator,e.g. a = b,
(assign b to a)
: Colon operator (Specify Range )
.^ Power (element wise)
' Transpose
* Matrix multiplication
/ Matrix right division
\ Matrix left division
; Row separator in a Matrix
^ Matrix power
Calculations at Command Lines
z =
1.5707963
Computing terminology: brief introduction
64
-->a=%T
a =
T
-->b=(0==1)
b =
F
-->a&b
ans =
F
65
Floating point
•ceil — round up
•clean — cleans matrices (round to zero small entries)
•double — conversion from integer to double precision representation
•fix — round towards zero
•floor — round down
•format — number printing and display format
•frexp — dissect floating-point numbers into base 2 exponent and mantissa
•ieee — set floating point exception mode
•int — round towards zero
•isinf — check for infinite entries
•isnan — check for "Not a Number" entries
•nearfloat — get previous or next floating-point number
•nextpow2 — next higher power of 2.
•number_properties — determine floating-point parameters
•round — round to nearest integer
66
Calendar
67
Example -1
68
Example -2
69
Example -3
70
Example -4
71
Example -5
72
Example -6
73
Assignment - 1
1. What are the other ways of obtaining online help in Scilab, other than
typing “help” at the command prompt?
2. Where are the demo programs that demonstrate Scilab's capabilities?
3. Where can you find user contributed documents on using and applying
Scilab? What are the categories for these documents? Which categories
interest you?
4. How can you search for a word or pattern in the Scilab online help
browser?
5. Can you use the built-in variable “ans” in your calculations? If so, is it a
good idea to do so or is it better to use your own named variables?
6. When do you think it is useful to use the semicolon (;) to suppress the
output of a Scilab statement?
7. What are the rules for choosing names for variables in Scilab? Can you
use a numeric character as the first character? Can you use
underscore ( _ ) as the first character? Can you use special characters,
such as -, +, /, ? in a variable name?
8. Can you change the font used by Scilab
9. What is the command to clear the screen?
10. What is the short cut key to clear the screen?
11. What is command history? What are the shortcut keys to use the
74
command history?
Assignment - 1
12. List areas within your proposed branch of specialization where Scilab can be a
useful tool.
13. Is there a command to record all commands that you type and save them to a
file so that you can see them later?
14. Can you describe some useful application of the diary command?
15. Can you customize Scilab startup to suit your specific needs?
16. What are the available data types in Scilab?
17. What is the command to list all variables in the Scilab workspace
whose name begins with the letters “sa”?
18. What is the command to list all variables in the Scilab workspace of
type boolean?
19. What is the Scilab constant for the value of π?
20. What is the command to find the Scilab current working directory?
21. Where can you find the Scilab current working directory?
22. How can you change the Scilab current working directory to a different
location?
23. Why is it important to know the Scilab current working directory?
24. Is Scilab a strongly typed language?
75
Any questions?
76