Introduction to Scilab Aditya Sengupta and Deepak Patil National - - PowerPoint PPT Presentation

introduction to scilab
SMART_READER_LITE
LIVE PREVIEW

Introduction to Scilab Aditya Sengupta and Deepak Patil National - - PowerPoint PPT Presentation

Introduction to Scilab Aditya Sengupta and Deepak Patil National Mission on Education through ICT Indian Institute of Technology Bombay E mail: sengupta@ee.iitb.ac.in deepakp@ee.iitb.ac.in Outline Introduction Scilab Objects: Matrices and


slide-1
SLIDE 1

Introduction to Scilab

Aditya Sengupta and Deepak Patil

National Mission on Education through ICT Indian Institute of Technology Bombay Email: sengupta@ee.iitb.ac.in deepakp@ee.iitb.ac.in

slide-2
SLIDE 2

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Outline

1 Introduction 2 Scilab Objects: Matrices and Polynomials. 3 Basic Programming 4 Basic Input And Output 5 Basic Graphics

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-3
SLIDE 3

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

About Scilab

Around since 1990 Numerical Computational package Free and Open Source Maintained by INRIA

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-4
SLIDE 4

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

About Scilab

Inspired by Cleve Molers MATLAB Interpreted Very High Level Scilab: C = C : Assembly Available for Linux, Mac and Windows

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-5
SLIDE 5

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Scilab Window looks like

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-6
SLIDE 6

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

42 + 4^2 64/4 a = 1, b=2, c=3 a + b + c institute = ‘‘IITB’’; typeof(institute) clear(‘‘institute’’) exists(‘‘institute’’)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-7
SLIDE 7

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

1/0 ieee(2) 1/0 ➐e sin(➐pi/2), cos(➐pi/2) (10+5*➐i)*(2*➐i) 2*cos(➐pi/5)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-8
SLIDE 8

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

About Scilab

Everything is a matrix! Even a real scalar is a 1 × 1 matrix You can define numbers, character strings, booleans, polynomials and lists

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-9
SLIDE 9

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

a=[1 2 3], b=[2 3 4] a’ a*b a.*b a’*b a*b’ size(a) length(a) diag(a)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-10
SLIDE 10

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

A=[1 2; 0 4], B=[1 2; 3 4] A+B, A-B A*B, B*A, A.*B, B.*A det(A) inv(A) size(A) length(A) spec(A) trace(A) diag(A)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-11
SLIDE 11

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

A=1:4 //This is a comment B=2:2:8 // range B([3 4]) // submatrix extraction A(6)=6 // add an element // oops! Forgot the fifth element! A($ − 1)=5 // ‘‘ ✩’’ is last element B=2*A // reassignment B=[B 2*B; 3*B] // new rows B($ + 1,:)=4*B(1,:) B([2 3], 2:$ − 1) //submatrix extraction

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-12
SLIDE 12

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

pwd cd(‘‘path-to-directory’’) diary(‘‘ my-record-of-what-follows.sci’’) inv([1 2; 0 4]) C=rand(3,3) C>.5 // boolean matrix find(C>.5) C(find(C>.5)) disp(C)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-13
SLIDE 13

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

P=poly([2 3 1], ‘x’, ‘coeff’) Q=poly([-1 4], ‘x’) P*Q, P+Q, P-Q roots(P), roots(Q), roots(P*Q) factors(P), factors(Q), factors(P*Q) 1/P Q/P derivat(P), derivat(Q), derivat(Q/P)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-14
SLIDE 14

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Conventions

Commands may be put in scripts. Extension is .sce If it only contains function definitions, the extension is .sci These are conventions! Execute:exec(‘path-to-script/script-name.sce’)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-15
SLIDE 15

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Functions

function [y1, y2, ...]=foo(x1, x2, ...) statement statement statement endfunction OR deff(‘‘[y]=foo([x])’’, ‘‘statements’’)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-16
SLIDE 16

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Functions

If function definitions are in a script file, use getf(‘path/script.sci’) To see the source of a Scilab coded function use fun2string(function-name)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-17
SLIDE 17

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Branching

if condition then statement statement statement else statement statement statement end

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-18
SLIDE 18

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Iterations

for name = expression statement statement statement end // Use break to stop execution within statement block

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-19
SLIDE 19

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Iterations

while condition statement statement statement // Use break to stop execution within statement block

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-20
SLIDE 20

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

function y = myfactorial(x) if x==0 then y=1 else y = x*myfactorial(x-1) end endfunction

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-21
SLIDE 21

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Try This Stuff

// try a few examples: myfactorial(5), myfactorial(0) // now try Scilabs own function: factorial(5), factorial(0)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-22
SLIDE 22

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Input

name=input(‘‘Enter your name: ’’) // oops (try entering your name in “ ”)

  • r try this:

name=input(‘‘Enter your name: ’’, ‘‘string’’) disp(name); more comfortable with C? try this: mprintf(‘‘Your name is ➐s’’, name)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-23
SLIDE 23

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

[Optional] Look these up in help:

mopen mprintf mfprintf mscanf mfscanf mclose

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-24
SLIDE 24

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

plot2d

x=linspace(-➐pi, ➐pi, 40) plot2d(x, sin(x)) //Try getting the axes in the centre //Don’t like the continuous version? plot2d3(x,sin(x))

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-25
SLIDE 25

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

plot3d

y=x plot3d(x, y, sin(x)’*cos(y)) — Notice the transpose

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-26
SLIDE 26

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

z=sin(x)’*cos(y)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics

slide-27
SLIDE 27

Outline Introduction Scilab Objects: Matrices and Polynomials. Basic Programming Basic Input And Output Basic Graphics

Thankyou!

www.scilab.org www.scilab.in http://scilab.in/cgi- bin/mailman/listinfo/scilab-indi “Modeling and Simulation in Scilab/Scicos” by Stephen L.Campbell, Jean-Philippe Chancelier and Ramine Nikoukah,(Springer)

Aditya Sengupta and Deepak Patil, CC group, EE, IITB Scilab/Objects/Programming/Input & Output/Graphics