Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created...

44
Introduction to Scilab Use Scilab, not Matlab Kannan M. Moudgalya IIT Bombay [email protected] Scilab-Arduino Workshop IIT Bombay 3 July 2015 Kannan Moudgalya Use Scilab, not Matlab 1/68

Transcript of Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created...

Page 1: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Introduction to ScilabUse Scilab, not Matlab

Kannan M. MoudgalyaIIT Bombay

[email protected]

Scilab-Arduino WorkshopIIT Bombay3 July 2015

Kannan Moudgalya Use Scilab, not Matlab 1/68

Page 2: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Outline

I Open Source Software

I History of Scilab

I Usage of Scilab

I Comparing other open source softwaresystems

Kannan Moudgalya Use Scilab, not Matlab 2/68

Page 3: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

FOSS: Free and Open Source Software

I Commercial software is expensiveI Heavy penalties if unauthorised software

is used by industryI Stories from Italy, HLL, WIPRO

I Our SME’s don’t use ANY software:I commercial software is expensiveI they are not aware of open source software

I Makes small companies uncompetitive

I There is no alternative to open sourcesoftware

Kannan Moudgalya Use Scilab, not Matlab 3/68

Page 4: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Scilab

I A good substitute for Matlab

I About 95% compatibility

Kannan Moudgalya Use Scilab, not Matlab 4/68

Page 5: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

What is Scilab?

I Free and open source

I Easy to useI Excellent computational environment:

I LINPACK, EISPACK, LAPACK: same asMatlab

I Other software not available for Matlab:Dassl, ODEPACK, etc.

Kannan Moudgalya Use Scilab, not Matlab 5/68

Page 6: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Scilab is created for mathematicians

I Matrices and vectors can be createdeasily - no typing, storage allocation, etc.

I Matrix-vector product,scalar-vector/matrix products are writtenwithout any fuss - like themathematicians do

I Belongs to Matlab family - originallycreated by Prof. Cleve Moler, who hadworked on Linpack and Eispack projects

Kannan Moudgalya Use Scilab, not Matlab 6/68

Page 7: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

History of Scilab

I Prof. Cleve Moler created Matlabthrough NSF funding

I As Government funded, source code hadto be made available

I Many companies started using this ideaI Matrixx

I CTRL-CI MatlabI Scilab

I Used extensively for linear algebra,simulation, control system design

I Scilab - a recent story

Kannan Moudgalya Use Scilab, not Matlab 7/68

Page 8: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Scilab - other features

I Can call programs written in Fortran, C

I Good graphics capability

I Large installed base

I A lot of algorithms implemented ininterpreted language as well

I Free

I Check out www.scilab.org orwww.scilab.in

Kannan Moudgalya Use Scilab, not Matlab 8/68

Page 9: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

How reliable is Scilab?

I CNES - France’s ISRO

I CNES Arianne rockets

I CNES relies on Scilab for many criticalcalculations:trajectory, flight dynamics, orbit

Kannan Moudgalya Use Scilab, not Matlab 9/68

Page 10: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

CNES Talk

I Use of Scilab for Space Mission Analysisand Flight Dynamics Activities

I by Thierry Martin

I Senior Manager, CNES

Kannan Moudgalya Use Scilab, not Matlab 10/68

Page 11: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Purchase of Matlab at IIT Bombay - AStory

Kannan Moudgalya Use Scilab, not Matlab 11/68

Page 12: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Usage of Scilab

Kannan Moudgalya Use Scilab, not Matlab 12/68

Page 13: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Simple Arithmetic - 1

4+6+12

ans =

22.

a = 4, b = 6; c = 12

a =

4.

c =

12.

a+b+c

ans =

22.Kannan Moudgalya Use Scilab, not Matlab 13/68

Page 14: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Useful Commands

I demosI Gives demos on several different things

I aproposI Helps locate commands associated with a

word

I helpI functional invocation with no arguments

I Helps draw plots

I diaryI Stores all commands and resulting outputs

Kannan Moudgalya Use Scilab, not Matlab 14/68

Page 15: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Simple Arithmetic & Display

a = 4; b = 6; c = 12;

d = a+b+c

d =

22.

d = a+b+c;

d

d =

22.

Kannan Moudgalya Use Scilab, not Matlab 15/68

Page 16: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Simple Arithmetic

x = sqrt(2)/2, y = asin(x)

x =

0.7071068

y =

0.7853982

y_deg = y * 180 /%pi

y_deg =

45.Kannan Moudgalya Use Scilab, not Matlab 16/68

Page 17: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Vector Operation - 2 I

-->a = 1:5, b = 1:2:9

a =

! 1. 2. 3. 4. 5. !

b =

! 1. 3. 5. 7. 9. !

-->c = [b a]

c =

! 1. 3. 5. 7. 9. 1. 2. 3. 4. 5. !Kannan Moudgalya Use Scilab, not Matlab 17/68

Page 18: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Vector Operation - 2 II

-->d = [b(1:2:5) 1 0 1]

d =

! 1. 5. 9. 1. 0. 1. !

Kannan Moudgalya Use Scilab, not Matlab 18/68

Page 19: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Vector Operation - 3 I

-->a, b

a =

! 1. 2. 3. 4. 5. !

b =

! 1. 3. 5. 7. 9. !

-->a - 2

Kannan Moudgalya Use Scilab, not Matlab 19/68

Page 20: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Vector Operation - 3 II

ans =

! - 1. 0. 1. 2. 3. !

-->2*a-b

ans =

! 1. 1. 1. 1. 1. !

Kannan Moudgalya Use Scilab, not Matlab 20/68

Page 21: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Logical Operators

== equal to< less than> greater than<= less than or equal to>= greater than or equal to<> or ∼= not equal to

Kannan Moudgalya Use Scilab, not Matlab 21/68

Page 22: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Vector Operations Using LogicalOperators I

-->A = 1:9, B = 9-A

A =

! 1. 2. 3. 4. 5. 6. 7. 8. 9. !

B =

! 8. 7. 6. 5. 4. 3. 2. 1. 0. !

-->tf = A==B

Kannan Moudgalya Use Scilab, not Matlab 22/68

Page 23: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Vector Operations Using LogicalOperators II

tf =

! F F F F F F F F F !

-->tf = A>B

tf =

! F F F F T T T T T !

Kannan Moudgalya Use Scilab, not Matlab 23/68

Page 24: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Transpose I

-->c = [1;2;3]

c =

! 1. !

! 2. !

! 3. !

-->a=1:3

Kannan Moudgalya Use Scilab, not Matlab 24/68

Page 25: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Transpose II

a =

! 1. 2. 3. !

-->b = a’

b =

! 1. !

! 2. !

! 3. !

Kannan Moudgalya Use Scilab, not Matlab 25/68

Page 26: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix I

-->A=[1 2 3;4 5 6;7 8 9]

A =

! 1. 2. 3. !

! 4. 5. 6. !

! 7. 8. 9. !

-->A(3,3)=0

Kannan Moudgalya Use Scilab, not Matlab 26/68

Page 27: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix II

A =

! 1. 2. 3. !

! 4. 5. 6. !

! 7. 8. 0. !

Kannan Moudgalya Use Scilab, not Matlab 27/68

Page 28: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix I

A

A =

! 1. 2. 3. !

! 4. 5. 6. !

! 7. 8. 0. !

-->B=A(3:-1:1,1:3)

Kannan Moudgalya Use Scilab, not Matlab 28/68

Page 29: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix II

B =

! 7. 8. 0. !

! 4. 5. 6. !

! 1. 2. 3. !

Kannan Moudgalya Use Scilab, not Matlab 29/68

Page 30: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix

-->A

A =

! 1. 2. 3. !

! 1. 4. 7. !

! 7. 8. 0. !

-->B=A(:,2)

B =

! 2. !

! 4. !

! 8. !

Kannan Moudgalya Use Scilab, not Matlab 30/68

Page 31: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix I

-->b=[5 -3;2 -4]

b =

! 5. - 3. !

! 2. - 4. !

-->x=abs(b)>2

Kannan Moudgalya Use Scilab, not Matlab 31/68

Page 32: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Submatrix II

x =

! T T !

! F T !

-->y=b(abs(b)>2)

y =

! 5. !

! - 3. !

! - 4. !

Kannan Moudgalya Use Scilab, not Matlab 32/68

Page 33: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Special Matrices I

-->zeros(3,3)

ans =

! 0. 0. 0. !

! 0. 0. 0. !

! 0. 0. 0. !

-->ones(2,4)

Kannan Moudgalya Use Scilab, not Matlab 33/68

Page 34: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Special Matrices II

ans =

! 1. 1. 1. 1. !

! 1. 1. 1. 1. !

-->rand(2,1)

ans =

! 0.2113249 !

! 0.7560439 !

Kannan Moudgalya Use Scilab, not Matlab 34/68

Page 35: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Go for Vector Computation

Kannan Moudgalya Use Scilab, not Matlab 35/68

Page 36: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Go for Vector Computation I

-->a = ones(10000,1);

-->timer()

ans =

0.02

-->for i = 1:10000, b(i)=a(i)+a(i); end

-->timer()

Kannan Moudgalya Use Scilab, not Matlab 36/68

Page 37: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Go for Vector Computation II

ans =

0.31

-->c = a+a;

-->timer()

ans =

0.03

Kannan Moudgalya Use Scilab, not Matlab 37/68

Page 38: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Plots

Go through the Demos!

Kannan Moudgalya Use Scilab, not Matlab 38/68

Page 39: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Comparing Matlab and Scilab

I Capability comparison - a correctquestion?

I Is Matlab required for class students?

I Matlab and versions

I Mathworks: 2,000 employees

I Scilab: 23 full time employees

Kannan Moudgalya Use Scilab, not Matlab 39/68

Page 40: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Hardware Interfacing through FOSS

I ScilabI Xcos, HART, COMEDI

I GNURadio

Kannan Moudgalya Use Scilab, not Matlab 40/68

Page 41: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Scilab for Hardware Interfacing

I COMEDI has device drivers for 150 A/Dand Digital I/O cards

I We can call ALL of them from ScilabI Using Xcos (' Simulink), HART

I Devices not in COMEDI, but with Cdrivers

I Devices without device drivers

Kannan Moudgalya Use Scilab, not Matlab 41/68

Page 42: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

GNURadio for Hardware Interfacing

I Open source software

I Uses C++ and Python

I Can call OpenCVI Has graphic front end

I Has sliders, etc. - allows change ofparameters in real time

I Calling Scilab functions from GNURadioI Calling Xcos functions from GNURadio

I LabView does not allow Simulink calls!

Kannan Moudgalya Use Scilab, not Matlab 42/68

Page 43: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Control of Single Board Heater Systemthrough Scilab and GNURadio

Kannan Moudgalya Use Scilab, not Matlab 43/68

Page 44: Introduction to Scilab Use Scilab, not Matlab · History of Scilab I Prof. Cleve Moler created Matlab through NSF funding I As Government funded, source code had to be made available

Thanks

Kannan Moudgalya Use Scilab, not Matlab 44/68