Professional Documents
Culture Documents
Workshop Tutorial Scilab
Workshop Tutorial Scilab
SciLab
http://www.phy.hw.ac.uk/~peckham/programming/scilab/intro-
html.html
http://72.14.203.104/search?q=cache:81mxNhYzFQ8J:classroom.
psu.ac.th/users/asurapon/matscicomapp/Scilab_Matrix.ppt+scila
b+tutorial&hl=en&gl=us&ct=clnk&cd=10
Workshop Title 1
Author
Date
SciLab 3.1.1 Tutorial
Contents:
Introduction to Scilab
Comparison to Mathematica
Getting Started
Opening the Program
Talking Between Scilab and the Editor
Basic Matrix Operations and Commands
Introduction to Scilab:
“Scilab has been developed for system control and signal processing
applications and is easily interfaced with Fortran or C subprograms. Scilab is made of
three distinct parts: an interpreter, libraries of functions (Scilab procedures) and libraries
of Fortran and C routines.
“A key feature of the Scilab syntax is its ability to handle matrices:
basic matrix manipulations such as concatenation, extraction or transpose
are immediately performed, as well as basic operations such as addition
or multiplication. Scilab also aims at handling more complex objects than
numerical matrices. For instance, control people may want to manipulate
rational or polynomial transfer matrices. This is done in Scilab by
manipulating lists and typed lists which allow a natural symbolic
representation of complicated mathematical objects such as transfer
functions, linear systems or graphs. Scilab provides a variety of powerful
primitives for the analysis of non-linear systems. Integration of explicit and
implicit dynamic systems can be accomplished numerically. There exist
numerical optimization facilities for non linear optimization (including non
differentiable optimization), quadratic optimization and linear optimization.”
(www.scilab.org)
Comparison to Mathematica:
Other computational software on the market are usually fairly expensive and
often boast for being more ‘user friendly’, for instance, Mathematica.
“Mathematica seamlessly integrates a numeric and symbolic
computational engine, graphics system, programming language,
documentation system, and advanced connectivity to other applications. It
is this range of capabilities--many world-leading in their own right--that
makes Mathematica uniquely capable as a "one-stop shop" for you or your
organization's technical work. Some of these uses require in-depth
Mathematica knowledge, while others do not. Mathematica is unusual in
being operable for less involved tasks as well as being the tool of choice
for leading-edge research, performing many of the world's most complex
computations. It is Mathematica's complete consistency in design at every
stage that gives it this multilevel capability and helps advanced usage
evolve naturally.” (www.wolfram.com)
Scilab 3.1.1 2
Jennifer Murphy
Rev. 1.0 6-7-06
Mathematica costs about $200 for a temporary student license and almost $2,000 for
professional editions. Mathematica is not necessarily any easier to use than SciLab,
you will need to learn a new software program regardless of the one you choose, but
the layout of Mathematica is a little bit simpler to use. In Mathematica, you can
physically click and edit anywhere in your code, in SciLab you have to re-type or recall
the command in order to edit it.
Scilab 3.1.1 3
Jennifer Murphy
Rev. 1.0 6-7-06
want to execute. You can change this using Change Directory item under the File menu
or from the command line in Scilab using the command: -->‘chdir directory’.
Now we can run the commands from the newly created .sce file via this
command at the Scilab prompt:
--> exec ‘name of your file’.sce
Note, as you make changes to your executable file, you will need to save those
changes and then run the ‘exec’ command again (you can save typing by using the up
arrow to recall previous commands). Try changing your matrix ‘A’ in SciPad and re-
execute the file in Scilab again.
Task #2: Scilab provides many vector and matrix operations. For instance we
can multiply matrices and vectors. In Scilab, enter this command:
--> x = [ 0 ; 5 ; 35]
§ 2 12 8 ·
¨ ¸
and given a matrix A = ¨ 6 1 7 ¸ type the command:
¨13 9 3 ¸¹
©
-->A = [ 2 -12 8; 6 1 7; 13 9 -3 ] (semi-colons may be replaced by returns)
Ha! You have now learned how to do some basic Linear Algebra using Scilab!
You probably noticed that the last operation ‘a*x’ didn’t work, that’s because
Scilab is case sensitive so ‘a’ and ‘A’ will represent different variables. Also note
a semi-colon at the end of a line will stop Scilab output for that line which is
useful if you are working with large vectors or matrices. Try:
-->y=A*x;
Note that the answer is not printed out. To see ‘y’ just type:
-->y
Scilab 3.1.1 4
Jennifer Murphy
Rev. 1.0 6-7-06
Let us now rewrite our matrix ‘A’ by having Scilab create random numbers.
Previously, ‘A’ was a 3 x 3 matrix; enter this command at the Scilab prompt:
-->A=rand(3,3) (in the help menu, you will see that the command
rand(n,m) requires ‘n’ to be the number of rows and ‘m’ is the number of
columns). By using ‘A’ again, we have effectively written over the previous value
for ‘A’.
Task #3: First, let’s clear the value for ‘y’ and ‘x’ that we calculated in the
previous exercise. In Scilab enter this command:
-->clear y; clear x
Another simple feature Scilab has is producing vectors that increase at a certain
increment. For instance, try this:
-->x=0:0.5:50
This will produce a vector starting at 0 and increasing by 0.5 units until 50 is
reached. Note that a semi-colon at the end of the line would’ve been helpful
here.
We can also compute functions using vectors. For example, let’s do some
trigonometry! Try this:
-->y=sin(x) (note, the sine function is called in lowercase)
Now we have a vector ‘d’ and a vector ‘f’ of the same length (these vectors are
simply matrices that are 1 x 101, ‘x’ being 0 thru 50 in increments of .5 and ‘y’
being the sine of each of those values)
Task #4: Now let’s make a 2-d plot! Using the vectors found in the previous
task, let’s make a plot of vector ‘x’ verses vector ‘y’. Enter this command after
the Scilab prompt:
-->plot2d(x,y)
Beautiful! A plot of ‘x’ versus ‘y’ should be produced. You can save the graph to
a file by using the file export menu item on the graphics window. There are a
variety of types of files you can save your graph as, but it is important to type the
file extension after the title when you are saving it, otherwise it will just be a
generic file with no file type.
Yeah! Now you know some very basic operations and commands available to you
through Scilab. This program has virtually unlimited power and can do much more than
is possible to cover at an introductory level. As long as users are willing to sift through
the help menu, this program can be used by just about anyone for just about any
reason. Mathematica definitely has some competition!
Scilab 3.1.1 5
Jennifer Murphy
Rev. 1.0 6-7-06