00 introduction of scilab

Upload: nguyen-anh-tuan

Post on 30-Oct-2015

99 views

Category:

Documents


1 download

TRANSCRIPT

  • Bi 1: Gii thiu v ScilabVin CNTT & TTTrng HBK H Ni*

  • Ni dung1. Gii thiu chung2. Ci t3. Ti liu tham kho4. C bn v Scilab*

  • 1. Gii thiu chungScilab: free software, open sourceWindowsLinuxMac OSScilab: Ngn ng lp trnh, kt hp vi cc thut ton s hc trn nhiu lnh vc khoa hcThuc loi ngn ng thng dch (interpreted language)Kt hp vi LabViews platform

    *

  • 1. Gii thiu chungKh nng x l vi Scilab:S hc tuyn tnh, ma trn thaCc hm a thc v cc hm hu t (l thng ca 2 hm a thc)Php ni suy, xp xPhp ti u tuyn tnh, bc 2 v phi tuyn tnhGii phng trnh vi phn v cc phng trnh i sX l tn hiuThng kX l th 2D, 3D

    *

  • 2. Ci tDownload link:http://www.scilab.org/products/scilab/downloadPhin bn 5.2.2:http://www.scilab.org/download/5.2.2/scilab-5.2.2.exeCi t nh cc software thng thngLu : ci t c bn y , cn c internet ti cc module cn thit.*

  • 2. Ci tChy chng trnh sau khi ci t:*

  • 3. Ti liu tham khoCung cp trn trang ch ca Scilabhttp://www.scilab.org/support/documentation/Mannual guide: gii thch chi tit cc t kha dng trong Scilabhttp://www.scilab.org/support/documentation/manuals5 tutorialTi liu thm:http://www.neurotraces.com/scilab/scilab2/node1.htmlhttp://comptlsci.anu.edu.au/Scilab/primer.pdf*

  • 4. C bn v Scilab4.1. Ba phng thc tng tc vi Scilab4.1.1. ConsoleEditor (Km kh nng Docking)4.1.2. S dng hm exec4.1.3. X l theo l4.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 ScilabV d: In ra chui xin cho

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

    *

  • 4.1.1. S dng console tng tc vi ScilabMt s lu :S dng bn phm tng t nh cc b son tho khcS dng phm , di chuyn trn dng lnhi qua li vi dng lnh c thc hin:S dng phm v S dng phm tab (hoc ctrl+space): auto-completion

    *

  • Editor: D dng son tho file cha tp cc on code ca ScilabCho php son tho nhiu file cng lcCch gi ra Editor:1. Vo menu Application Editor2. Gi hm editor() t console

    *Editor

  • Editor*

  • Editor: Mt s tnh nngLoad into Scilab:Chy ton b on code trong file ang son thoS khc nhau gia s= "xin cho d"; v s= "xin cho d"Evaluate Selection: Chy on code c bi enExecute File Into Scilab:Chy 1 file nh khi gi hm execKhc vi Load into Scilab:Ch cho ra output trn mn hnh khi c lnh display()*

  • Editor-DockingBt tin khi phi lm vic ng thi vi editor v console???*

  • Editor-DockingKo & Th*

  • Editor-DockingKt qu sau khi ko & th*

  • Editor-DockingLu :C th tch hp nhiu window lm 1C 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

    *

  • 4.1.2. S dng hm execFile .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 codefunction 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*

  • 4.1.2. S dng hm execV 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 !*

  • 4.1.3. X l theo lS dng Scilab t command line

    Sau khi ci t Scilab: th mc cha cc file binaries:scilab-5.2.0/binVi HH Windows: 2 file:WScilex.exe: Console ha tng tc thng thngScilex.exe: Console chy ch khng c ha vit bng java nh phn console*

    -e instructionexecute the Scilab instruction given in instruction-f fileexecute the Scilab script given in the file-l langsetup the user language'fr' for french and 'en' for english (default is 'en')-mem Nset the initial stacksize.-nsif this option is present, the startup le scilab.start is not executed-nbif this option is present, then Scilab welcome banner is not displayed-nouserstartupdon't execute user startup les SCIHOME/.scilabor SCIHOME/scilab.ini-nwstart Scilab as command line with advanced features (e.g., graphics).-nwnistart Scilab as command line without advanced features-versionprint product version and exit

  • 4.1.3. X l theo lV 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 4Undefined variable: plot-->

    *

  • 4.1.3. X l theo lV 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.2Consortium Scilab ( DIGITEO )Copyright (c) 1989 -2009 ( INRIA )Copyright (c) 1989 -2007 ( ENPC )___________________________________________Startup execution :loading initial environmentHello World !C:\ scripts >

    *

  • 4.2. Cc loi bin trong ScilabKiu ng cho binKhi to 1 bin: (Phi khai bo trc khi s dng)Khng cn khai bo kiuTy theo gi tr c gn ca, Scilab s t ng xc nh kiu d liu ph hpKhi bin nhn gi tr mi, Scilab cng cp nht kiu bin mi nu cnV d:-->x=1x =1.-->x+1ans =2.-->x=" foo "x =foo-->x+" bar "ans =foobar

    *

  • 4.2. Cc loi bin trong ScilabTn bin: di ty , nhng ch xt 24 k t u tinM ASCII: a-z, A-Z, 0-9, %_#!$?Phn bit ch hoa, thngComment trong Scilab:Ch comment dng, khng c comment khi-->// This is my comment .-->x =1..- - >+2..- - >+3..-->+4x =10.

    *

  • 4.2. Cc loi bin trong ScilabBin ton hc c bit:c Scilab nh ngha trcBt u bng k t %V d:%pi%T, %F%i

    *

  • 4.2. Cc loi bin trong Scilab4.2.1. Bin thc4.2.2. Bin Boolean4.2.3. Bin phc4.2.4. Bin xu4.2.5. Hm ton hc c bn*

  • 4.2.1. Bin thcV d: Gn x=1, thc hin tnh x*2-->x=1x =1.-->x = x * 2x =2Lu : ton t =Cc ton t c bn:*

  • 4.2.2. Bin BooleanLu gi tr true/falseV d:-->a=%Ta =T-->b = ( 0 == 1 )b =F-->a&bans =FLu : 1 s ton t so snhInput: thc/phc/nguyn/xu

    *

  • 4.2.3. Bin phcV d:-->x= 1+ %ix = 1. + i--> isreal (x)ans = F-->x'ans = 1. - i-->y=1- %iy = 1. - i-->real (y)ans = 1.-->imag (y)ans = - 1.

    Kim tra (1 + i)(1 - i) = 1 - i2 = 2 bng Scilab:-->x*yans =2.

    Lu : 1 s hm thao tc trn s phc

    *

  • 4.2.4. Bin xuV d:-->x = " foo "x =foo-->y=" bar "y =bar-->x+yans =FoobarLu :Gi tr ca bin xu t trong " "

    *

  • 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^2ans =1.

    *

  • Bi tp v nh1. Bi tp bt buc:Download, ci t ScilabDownload cc ti liu hng dnChy li tt c cc v d trn lpThc hnh tng tc vi Scilab theo 3 cch2. Bi tp thm:Gii phng trnh bc 2Gii h phng trnh bc nht 3 nVi kin thc hc, t a ra 1 v d ng dng ca Scilab trong thc tBui thc hnh tip: 4 tita im: Trung tm my tnh (Tng 3, D5)Kim tra bi tp c, nh gi, cho imHng dn cc ni dung mi ca Scilab*

    *