You are on page 1of 33

Bi 1: Gii thiu v Scilab

Vin CNTT & TT Trng HBK H Ni

Ni dung

1. 2. 3. 4.

Gii thiu chung Ci t Ti liu tham kho C bn v Scilab

1. Gii thiu chung

Scilab: free software, open source


Windows Linux Mac OS

Scilab: Ngn ng lp trnh, kt hp vi cc thut ton s hc trn nhiu lnh vc khoa hc


Thuc loi ngn ng thng dch (interpreted language) Kt hp vi LabViews platform


3

1. Gii thiu chung

Kh nng x l vi Scilab:

S hc tuyn tnh, ma trn tha Cc hm a thc v cc hm hu t (l thng ca 2 hm a thc) Php ni suy, xp x Php ti u tuyn tnh, bc 2 v phi tuyn tnh Gii phng trnh vi phn v cc phng trnh i s X l tn hiu Thng k X l th 2D, 3D
4

2. Ci t

Download link:

http://www.scilab.org/products/scilab/downl oad http://www.scilab.org/download/5.2.2/scila b-5.2.2.exe Lu : ci t c bn y , cn c internet ti cc module cn thit.


5

Phin bn 5.2.2:

Ci t nh cc software thng thng

2. Ci t

Chy chng trnh sau khi ci t:

3. Ti liu tham kho

Cung cp trn trang ch ca Scilab

http://www.scilab.org/support/documentation/

Mannual guide: gii thch chi tit cc t kha dng trong Scilab

http://www.scilab.org/support/documentation/ manuals

5 tutorial Ti liu thm:


http://www.neurotraces.com/scilab/scilab 2/node1.html http://comptlsci.anu.edu.au/Scilab/primer.pdf


7

4. C bn v Scilab

4.1. Ba phng thc tng tc vi Scilab

4.1.1. Console

Editor (Km kh nng Docking)

4.1.2. S dng hm exec 4.1.3. X l theo l

4.2. Cc loi bin trong Scilab

4.1.1. S dng console tng tc vi Scilab

4.1.1. S dng console tng tc vi Scilab

V d: In ra chui xin cho


-->s="xin cho" s = xin cho -->disp(s) xin cho
10

4.1.1. S dng console tng tc vi Scilab

Mt s lu :

S dng bn phm tng t nh cc b son tho khc

S dng phm , di chuyn trn dng lnh

i qua li vi dng lnh c thc hin:

S dng phm v auto-completion

S dng phm tab (hoc ctrl+space):

11

Editor

Editor:

D dng son tho file cha tp cc on code ca Scilab

Cho php son tho nhiu file cng lc 1. Vo menu Application Editor 2. Gi hm editor() t console

Cch gi ra Editor:

12

Editor

13

Editor: Mt s tnh nng

Load into Scilab:


Chy ton b on code trong file ang son tho S khc nhau gia s= "xin cho d"; v s= "xin cho d"

Evaluate Selection: Chy on code c bi en Execute File Into Scilab:


Chy 1 file nh khi gi hm exec Khc vi Load into Scilab:

Ch cho ra output trn mn hnh khi c lnh display()


14

Editor-Docking

Bt tin khi phi lm vic ng thi vi editor v console???

15

Editor-Docking
Ko & Th

16

Editor-Docking

Kt qu sau khi ko & th

17

Editor-Docking

Lu :

C th tch hp nhiu window lm 1 C th c nhiu la chn khi kt hp: Tri-phi, Trn-di, Kt hp theo tab: ko 1 window vo chnh gia 1 window khc

18

4.1.2. S dng hm exec


File .sci v .sce: d qun l code .sci:

Cha 1 hay nhiu hm t vit. Cc hm ny sau s c load vo mi trng ca scilab khi gi getf. Ch cch vit code
function out = halfbis (in) out = 0.5 * in; function out = ntimesbis (in1, in2) out = in1 * in2;

gi cc hm trong .sci trong console: hm getf


-->getf('example.sci') -->halfbis(5) ans = 2.5

.sce:

Cha c hm t vit v cc m lnh thc thi ca scilab


19

4.1.2. S dng hm exec

V d, ni dung file myscript.sce l:


disp("Hello World !")

Trong Scilab console, chng ta c th s dng hm exec thc thi on script trn:
-->exec (" myscript . sce ") -->disp (" Hello World !") Hello World !
20

4.1.3. X l theo l

S dng Scilab t command line


-e instruction -f file -l lang -mem N -ns -nb -nouserstartup -nw -nwni -version execute the Scilab instruction given in instruction execute the Scilab script given in the file setup the user language 'fr' for french and 'en' for english (default is 'en') set the initial stacksize. if this option is present, the startup le scilab.start is not executed if this option is present, then Scilab welcome banner is not displayed don't execute user startup les SCIHOME/.scilab or SCIHOME/scilab.ini start Scilab as command line with advanced features (e.g., graphics). start Scilab as command line without advanced features print product version and exit

Sau khi ci t Scilab: th mc cha cc file binaries:

scilab-5.2.0/bin WScilex.exe: Console ha tng tc thng thng Scilex.exe: Console chy ch khng c ha vit bng java nh phn console
21

Vi HH Windows: 2 file:

4.1.3. X l theo l

V d 1:

Chy Scilex.exe vi option nwni, ta gi hm v plot(), s b li:

C:\Users\DatTT>"C:\Program Files\scilab-5.2.2\bin\Scilex.exe" -nwni ___________________________________________ scilab-5.2.2 Consortium Scilab (DIGITEO) Copyright (c) 1989-2010 (INRIA) Copyright (c) 1989-2007 (ENPC) ___________________________________________ Startup execution: loading initial environment -->plot() !--error 4 Undefined variable: plot -->

22

4.1.3. X l theo l

V d 2:

Son tho file C:/scripts/myscript2.sce :


disp (" Hello World !") quit ()

Chy file trn command line:


C:\scripts>"C:\Program Files\scilab-5.2.2\bin\Scilex.exe" -f myscript2.sce ___________________________________________ scilab -5.2.2 Consortium Scilab ( DIGITEO ) Copyright (c) 1989 -2009 ( INRIA ) Copyright (c) 1989 -2007 ( ENPC ) ___________________________________________ Startup execution : loading initial environment Hello World ! C:\ scripts >

23

4.2. Cc loi bin trong Scilab

Kiu ng cho bin

Khi to 1 bin: (Phi khai bo trc khi s dng)


Khng cn khai bo kiu Ty theo gi tr c gn ca, Scilab s t ng xc nh kiu d liu ph hp

Khi bin nhn gi tr mi, Scilab cng cp nht kiu bin mi nu cn

V d:
-->x=1 x =1. -->x+1 ans =2. -->x=" foo " x =foo -->x+" bar " ans =foobar
24

4.2. Cc loi bin trong Scilab

Tn bin:

di ty , nhng ch xt 24 k t u tin M ASCII: a-z, A-Z, 0-9, %_#!$? Phn bit ch hoa, thng Ch comment dng, khng c comment khi
-->// This is my comment . -->x =1.. - - >+2.. - - >+3.. -->+4 x =10.
25

Comment trong Scilab:

4.2. Cc loi bin trong Scilab

Bin ton hc c bit:


c Scilab nh ngha trc Bt u bng k t % %pi %T, %F %i

V d:

26

4.2. Cc loi bin trong Scilab


4.2.1. 4.2.2. 4.2.3. 4.2.4. 4.2.5.

Bin thc Bin Boolean Bin phc Bin xu Hm ton hc c bn

27

4.2.1. Bin thc

V d: Gn x=1, thc hin tnh x*2


-->x=1 x= 1. -->x = x * 2 x= 2

Lu : ton t = Cc ton t c bn:


28

4.2.2. Bin Boolean

Lu gi tr true/false
V d: -->a=%T a= T -->b = ( 0 == 1 ) b= F -->a&b ans = F

Lu : 1 s ton t so snh

Input: thc/phc/nguyn/xu
29

4.2.3. Bin phc

V d:
-->x= 1+ %i x = 1. + i --> isreal (x) ans = F -->x' ans = 1. - i -->y=1- %i y = 1. - i -->real (y) ans = 1. -->imag (y) ans = - 1.

Kim tra (1 + i)(1 - i) = 1 - i2 = 2 bng Scilab:


-->x*y ans =2.

Lu : 1 s hm thao tc trn s phc


30

4.2.4. Bin xu

V d:
-->x = " foo " x= foo -->y=" bar " y= bar -->x+y ans = Foobar

Lu :

Gi tr ca bin xu t trong " "


31

4.2.5. Cc hm ton hc c bn

V d: Kim tra sin(x)2 +cos(x)2 =1


-->x = cos (2) x= - 0.4161468 -->y = sin (2) y= 0.9092974 -->x^2+ y^2 ans = 1.
32

Bi tp v nh

1. Bi tp bt buc:

Download, ci t Scilab Download cc ti liu hng dn Chy li tt c cc v d trn lp Thc hnh tng tc vi Scilab theo 3 cch Gii phng trnh bc 2 Gii h phng trnh bc nht 3 n Vi kin thc hc, t a ra 1 v d ng dng ca Scilab trong thc t a im: Trung tm my tnh (Tng 3, D5) Kim tra bi tp c, nh gi, cho im Hng dn cc ni dung mi ca Scilab

2. Bi tp thm:

Bui thc hnh tip: 4 tit


33

You might also like