Sie sind auf Seite 1von 33

FDP on Electronic Design Tools : Computing with Scilab 12/12/2017

INTRODUCTION TO COMPUTING USING


SCILAB

Dr. C. SREEKUMAR,
Professor ,EEE Department,
GCE Kannur

December 12, 2017

Outline

SCILAB System and Environment

SCILAB Basics

SCILAB Scripting

SCILAB plotting

SCILAB File operations

SCILAB Control system commands

XCOS Environment

Dr. C. Sreekumar 1
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB - A POWERFUL COMPUTING TOOL

» Scilab is a scientific software package providing a powerful


open computing environment for engineering and scientific
applications.
» An OPEN Software initiative for numerical computations,
distributed freely and open source through the Internet
since 1994.
» Can be downloaded from Scilab web site
-http://www.scilab.org
» Both Linux and Windows versions are available. Scilab
6.0.0 is the latest stable version
» Alternative to MATLAB -the costlier Proprietary Software.
A lot like MATLAB

SCILAB - The History

» Scilab- developed by researchers from INRIA (French


National Institute for Research in Computer Science &
Control) & ENPC (National School of Bridges &
Roads)[1990]
» Freely distributed over internet since 1994, with source
code, on-line help user manuals
» The Scilab Consortium (DIGITEO) was formed by a
number of French institutions and companies [ May 2003 ]
» Scilab Consortium was integrated into DIGITEO
Foundation [July 2008] [supported till June 2012]
» The editing and development activities are taken over by
Scilab Enterprises, a company founded with the support of
INRIA [July 2012]

Dr. C. Sreekumar 2
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB -Features

» SCIENTIFIC Simulation LABORATORY


» Scilab includes hundreds of mathematical functions with
the possibility to add programs interactively from various
languages-C, Fortran,....
» It has sophisticated data structures (including lists,
polynomials, rational functions, linear systems.)
 A built-in interpreted high-level programming language.
» An interpreted language - Commands executed line by line
» A high level programming language using which Precise
numerical calculations and graphics illustrations are
possible

SCILAB -Features

 Everything in SCILAB is a matrix (Like MATLAB)


 The basic data element in SCILAB is an array that does
not require dimensioning.
 SCILAB commands are expressed in a notation close to
that used in Mathematics and Engineering
 Eg: sin,log,abs ......
 Problem solving in SCILAB is generally much faster than
traditional programming
 Eg: inv
Single SCILAB command to find the inverse of a matrix
 Because of natural notation,SCILAB code is clear and self
documented

Dr. C. Sreekumar 3
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB -Features

 SCILAB has a rich set of Toolboxes/application-specific


solutions to do specialized work
 Toolboxes are comprehensive collections of SCILAB
functions that extend the SCILAB environment to learn and
apply specialized technology
 XCOS - Similar to SIMULINK, GUI Builder
toolboxes(Scipad,guimaker etc), ANN Toolbox
 Electrical - Control Systems, Signal processing, Power
systems ,Scilab Image Processing Toolbox(SIP),
 Mathematics -Linear Algebra, Fuzzy logic(sciFLT),
Optimization, Wavelet etc..
 ATOMS (AuTomatic mOdules Management for Scilab)-
dedicated website listing of SCILAB external modules
which can bring the functionality you need.

Interface to MUMPS- A SCILAB Feature

 Multifrontal Massively Parallel sparse direct Solver


 Solution of large linear systems with symmetric positive
definite matrices, general symmetric matrices, general
unsymmetric matrices
 Real or complex arithmetic (single or double precision)
 Parallel factorization
 Iterative refinement and backward error analysis
 Interfaces to MUMPS: Fortran, C, Matlab and Scilab

Dr. C. Sreekumar 4
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB Environment

SCILAB Environment

 SCILAB Console - Place to interact with Scilab using


Commands, view the results etc.
 has the feature of autocompletion (functions suggestion on
the basis of the first letters the user types)
 SCILAB Editor: Scinotes - A text editor for writing scripts.
 Easy script edition with autocompletion
 Multiple instances management
 SCILAB Variable Browser and Editor - To view and edit
current variables.
 Command History Browser - An interface to see the
previously used commands of previous Scilab sessions.
 SCILAB file browser - Window to view the contents of the
current director and to browse for any file

Dr. C. Sreekumar 5
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB Environment- Contd..

 SCILAB Help Browser -help detailing Scilab functions and


giving examples to get started.
 Provides a better place to start with...
 ATOMS (AutomaTic mOdules Management for Scilab)
 Interface to view the installed external modules
 Interface to view the available modules
 Media to download and automatically install external
modules
 Dependencies managed between installed modules
 Facilitates automatic loading of the installed modules at
Scilab start,
 Automatic notifications to update an installed module

Basic Operations

 Entering a Matrix - Several ways


 Enter an explicit list of elements
 Load matrices from external data files
 Generate matrices using built-in functions
 Create matrices with your own SCILAB functions

 Basic Conventions
 Separate the elements of a row with blanks or commas
 Use a semicolon ; to indicate the end of each row.
 Surround the entire list of elements with square brackets [ ]

Dr. C. Sreekumar 6
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Basic Operations...Contd

 » A= [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

16 3 2 13
5 10 11 8
A=
9 6 7 12
4 15 14 1
 To suppress output, end the line with a semicolon
»a=3
a=3
»a=3;
 Variable names ⇒ Case Sensitive
 » B= [1,6,3,2;5,1,0,8;9,6,7,2;4,15,1,4];
 If variable name is not specified, the default name is ’ans’

Basic Operations.- Contd..

 »A1 = [1 2 3;2 1 3;3 1 2]

1 2 3
A1 = 2 1 3
3 1 2

 »A2 = [A 3*A;A-(2*A) A+A]

1 2 3 3 6 9
2 1 3 6 3 9
3 1 2 9 3 6
A2 =
−1 −2 −3 2 4 6
−2 −1 −3 4 2 6
−3 −1 −2 6 2 4

Dr. C. Sreekumar 7
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB -Basic Commands

 sum(A) - gives the sum of column elements


 To find the sum of row elements transpose the matrix and
take the sum
⇒ A’ gives the transpose of A
⇒ sum(A’)
 diag(A) - gives the diagonal elements
⇒sum(diag(A))- gives the sum of diagonal elements
 The element in row i and column j of A is denoted by A(i,j)
⇒ A(1,1) gives 16

SCILAB -Basic Commands-Contd..

 spec(A) gives the eigen values of A


 inv(A) gives the inverse of A
 det(A) gives the determinant of A
 size(A) gives the dimensions of A
 A(:,2) gives the elements of the 2nd column
 A(2,:)=[3 6 4 3]; ⇒ replaces second row of A

Dr. C. Sreekumar 8
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB -Basic Commands-Contd...

» rank(A) →To find the rank of a matrix, A


» det(A) →To find the determinant of a matrix, A
» trace(A)→To find the trace(sum of diagonal elements)of A
» inv(A) →To find the inverse of a matrix,A

SCILAB -Basic Commands-Generating Matrix using


built in functions
» zeros( , ) →To To generate zero matrix of specified size
» ones( , ) →To get a matrix of 1’s of specified size
» eye(A)→To find identity matrix of specified size
» diag([ ])→To get matrix with the specified diagonal
» rand(A) →To get random matrix with the dimensions of A

Dr. C. Sreekumar 9
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB Commands to Save and retrieve matrices

» save(’file name’, ’var1’, ’var2’, . . . ); To save the variable


matrices
» load(’file name’, ’var1’, ’var2’, . . . ); To retrieve the matrices
» a = 3; b = 10.5; s = ’scilab’;
» save(’myvar.dat’, a, b, c);
» clear a; // delete the variable a
» clear ; //delete all variables
» load(’myvar.dat’, ’a’,’b’, ’c’); // load all the saved variables
» load(’myvar.dat’,’b’); // It loads only variable b
» listvarinfile("myvar.dat");// list variables in a file saved by
the function save

SCILAB-Basic Commands- Contd..


 To solve the linear equations,2x + y + 3z =
4, 4x + 3y + z = 6, x + y + 3z = 3.Ax = b; x = A−1 B.

Dr. C. Sreekumar 10
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB-Basic Commands- Contd..

 The
⎛ ⎞back slash operator also gives the same result
x
⎝y ⎠ = A\b
z

SCILAB-Basic Commands- Contd..


» p=poly([1 2 3],"x") →To define a polynomial with roots at
1,2,3
» roots(p) →To find the roots of polynomial, p.

Dr. C. Sreekumar 11
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
User defined SCILAB- *.sce file
 SCILAB commands can be put together in a *.sce file,
which can be used many times. Can be modified later

Numerical solution of differential equation

dy (x−y )
dx = 2

Dr. C. Sreekumar 12
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Numerical solution of differential equation

Plotting Curves

 Generating data for plots


» x=linspace(0,4*%pi,10);
» y=sin(x);
 Plot values against their index
» plot(y);
 To plot y versus x
» plot(x,y);
 To make the plot smooth, evaluate the function at more
points
» x=linspace(0,4*%pi,1000);
» plot(x,sin(x));

Dr. C. Sreekumar 13
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017

Plotting Curves - Contd....

 Can change the line color, marker style, and line style by
adding a string argument
» plot(x,y,’k.-’); ⇒ k indicates color, . indicates point marker, -
indicates line style
 Try → » help plot ⇒ practice the various options
 A second plot command normally overwrites the first
 To draw 2 curves in the same graph
» plot(x,y,’r’,x,2*y,’g’);
» legend("speed","scaled speed");
» xlabel("Time");
» ylabel("speed");
» title("PLOT ");

Dr. C. Sreekumar 14
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017

Plotting - A Code to try

Dr. C. Sreekumar 15
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Plotting - A Code to try

Heart
2.0

1.5

1.0

0.5

0.0

-0.5

-1.0

-1.5

-2.0
-1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0

LOVE SCILAB .......LEARN SCILAB

2dplot and its variants- Different Plotting styles

Dr. C. Sreekumar 16
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Simple 3d plot

A simple 3d plot

15

10

Function 0

−5

−10

−15
0 0
1 1
2 2
3 3
4 4
Time 5 5 Time
6

Stylish 3d plots

1 1

Z Z
0 0

−1 −1
−1 −1 −1
−0.5 −0.5
0 0 X 0 0 X
Y Y
0.5 0.5
1 1 1 1

1 1

Z Z
0 0

−1 −1
−1 −1 −1
−0.5 −0.5
0 0 X 0 0 X
Y Y
0.5 0.5
1 1 1 1

Dr. C. Sreekumar 17
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Animated 3d plots

10

1
1
0 0.5
1 0
0.5 −0.5
0 −1
−0.5
−1

Contour Plots

2.5 0.181
0.271
0.542
0.6320.3610.0903
2 0.813
0.903
0.722
0.451
0.3610.0903
0.903 0.542
0.813 0.181 0.1810.542
0.361
0.632
0.722 0.271
0.451 0.0903
0.271
0.451
0.632
1.5

0.5

−0.5 0.181
0.0903
0.271
0.542
−1 0.361
0.632
0.813
0.722
0.903
0.722
0.632
0.813 0.451
0.271
0.361
0.542 0.0903 0.451 0.451
0.271 0.632
−1.5 0.903 0.181 0.181
0.361
0.0903 0.542
−2

−2.5

−3
−4 −3 −2 −1 0 1 2 3 4

Dr. C. Sreekumar 18
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Surface Plots

0.8

0.6

0.4

0.2

1 −0.2

0.5 −0.4
1
0 0.5
Y
0
−0.5 X
−0.5
−1 −1

Surface Plots

Dr. C. Sreekumar 19
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017

To plot on a new figure


» figure;
» plot(x,y);
To plot a 3D figure

Subplots in SCILAB

 SCILAB Permits multiple plots in the same figure window

Dr. C. Sreekumar 20
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Plots of user defined functions

 Functions can be defined as sequences of instructions


written in text strings. deff command make on-line
definition of function
» deff(’output]=functionname(input)’,definition[,options])
» deff(’[x]=mysum(y,z)’,’x=y+z’)

Plots of user defined functions-Contd..


 fplot2d(x,f) - 2D plot of a curve defined by a function

 xgrid :adds a grid on a 2D plot


 xtitle :xtitle add titles on a 2D or 3D plot

 xclear : Clears one or more windows

 clf() : Clears the grpahic window

 xbasc: Clears graphic window and erase recorded

Dr. C. Sreekumargraphics 21
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Plots -functions in separate files Saving Figures

Saved eps file


Saved pdf file
changes in me
1 800
me2
me3
1 600

1 400

1 200
mesquare_and_cube

1 000

800

600

400

200

0
0 1 2 3 4 5 6 7 8 9 10 11 12
ME

Dr. C. Sreekumar 22
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Plotting functions of two variables

 Plot of z = x 4 − y 3 − 2 ∗ x 3 − y ∗ sin(2 ∗ x) ∗ e(−y +3)


f

Plotting Vector fields

 Plot of F (x, y) = xi + (x 2 + y 2 )j)

Dr. C. Sreekumar 23
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Histograms

//Generate 1*10000 matrix


of random numbers
following normal distribution
d=rand(1,10000,’normal’);
// histogram with minimum
20 interval with color
green=3
histplot(20,d,3);

Pie charts

//New figure to draw pie


chart
figure()
pie([3 1 6])

Dr. C. Sreekumar 24
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Bar charts

// New figure to draw bar


chart
figure()5
bar([3 1 6 2 5 7 10])

SCILAB-File Writing


      


   
 



       

   

Dr. C. Sreekumar 25
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
SCILAB-File Reading


      

      

 
    




  
  

  
  

  
  

  


   

!






SCILAB-Operations with EXCEL File


       
     


 
 
 

 

    
    
 

        



   
  ! "# 
   $
 
 "#$

 
 % &''   $%& 
' #


()
*()
)(*
)  )' ) )
)*)()*+, 
"$

- $
#."" 
$  "
/) )0 1)2)))1)1)1)%11113
-4$ ( $ ((
 
 
#$"" ( "(
$ $ $  
5 #
-
4$  $ 

Dr. C. Sreekumar 26
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
De ning system in TF or SS Form

More Control system commands

Dr. C. Sreekumar 27
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Bode Plots 40

20

Magnitude (dB)
0

−20

−40

−60
−3 −2 −1 0 1 2 3
10 10 10 10 10 10 10
Frequency (Hz)

−20

−40

Phase (degree)
−60

−80

−100

−120
−3 −2 −1 0 1 2 3
10 10 10 10 10 10 10
Frequency (Hz)

gainplot(sys)-magnitude plot
 show-margins(sys)- phaseplot(sys)-frequency
display gain and phase plot
phase
margin and crossover
frequencies
 g-margin(sys)-
 p-margin(sys)

Root Locus Plots

Dr. C. Sreekumar 28
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Nyquist Plots

Nyquist plot
30
−0.0727 −0.0476
25
−0.116
20

15
−0.217 −0.0152

10

1e+03
0 0.001

−5

−10
0.217 0.0152

−15

−20 0.116

−25 0.0727 0.0476

−30
−10 −5 0 5 10 15 20 25 30 35 40 45 50 55 60

Control -Plotting - A Code to try

Dr. C. Sreekumar 29
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Plotting - A Code to try

Heart
4
90

120 60
3

2 150 30

0 0

0.5
-1 1

1.5

-2 210 2 330

2.5

-3 3
240 300

270
-4
-4 -3 -2 -1 0 1 2 3 4

Signal Sampling

 
 



 



   


  
 Cont inuous signal
 !! 1.0

"! # 0.8


0.6
$ %&' !(&& 0.4
Am plit ude

) %*!*! 0.2


0.0
  -0.2
 $+)   $," , -0.4

 +)   $,-. , -0.6


-0.8
 *$ -1.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
$ ,/, Tim e
 Sam pled Signal
1.0
 %&' !(&&&" 0.8
) %*!*% 0.6

  0.4
Am plit ude

0.2
 $+)   $," , 0.0

 +)   $,-. , -0.2


-0.4
%.' * -0.6
$ , ., -0.8
-1.0
0 10 20 30 40 50 60 70 80 90 100

Dr. C. Sreekumar 30
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
xcos GUI

 A GUI containing a number of library blocks


 Blocks can be dragged and connected to do simulations

xcos GUI

 There are two main types of signals associated with Xcos


blocks
 Event signals and data signals
 Event signals
 have ports colored in red
 can not be saved in the workspace
 handling blocks are in the Event handling library (see
Palette browser)
 can be seen as function calls or triggers (as in Matlab
Simulink)
 Data signals
 are colored in black
 can be saved in the workspace
 represent numerical values (scalars or vectors)

Dr. C. Sreekumar 31
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017
Simulation using Xcos

1.5

y
0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t

Simulation using Xcos

1.5 1.5

1 1

0.5 0.5

0 0
y

−0.5 −0.5

−1 −1

−1.5 −1.5

Dr. C. Sreekumar0 2 4 6 8 10 12 14
t
16 18 20 22 24 26 28 30 0 2 4 6 8 10 12 14
t
16 18 20 22 24 26 28 30
32
FDP on Electronic Design Tools : Computing with Scilab 12/12/2017

THANK YOU

Dr. C. Sreekumar 33

Das könnte Ihnen auch gefallen