You are on page 1of 16

IntroductiontoScientific

ComputingTool Scilab

ChaoChiehLanandJianHao Liou
DepartmentofMechanicalEngineering
National Cheng Kung University
NationalChengKungUniversity
2009/09/22

ComputingToolsforMechanismAnalyses
p
g
y
Lowlevel

Mediumlevel

C++Fortran

MathematicaMatlab

Highlevel
g
WorkingModelADAMS

L
Lowlevel:
l l
Generalpurpose

Fastcomputation

Matrixmanipulationiscumbersome

Nodirectgraphicssupport

Difficulttodebug

Mediumlevel:
Matrixmanipulationiseasy Directgraphicssupport
Lessgeneral

Easytodebug

Slowercomputation

Highlevel:
g
Graphicaluserinterface

Youdontknowifthesoftwarecheatyou!

Scilab AFreeAlternativetoMatlab
A Free Alternative to Matlab
Scilabisascientificsoftwarepackagefornumerical
computations.ItwasinitiallydevelopedbyINRIAandENPCin
France.
Scilabisanopensourcesoftware.
Since1994ithasbeendistributed
freely along with the source code
freelyalongwiththesourcecode
viatheInternet.Now,thelatest
edition is 5.1.1.
editionis5.1.1.
Scilabsyntaxislargelybasedonthe
MATLAB language
MATLABlanguage.
OtherfreealternativestoMatlabincludeOctaveand RlabPlus.
3

Scilab Layout
y
Commandwindow:
*.sceisascriptfilethatyoucanstore
youprogram.
*.sciisafunctionfilethatyoucanstore
youfrequentlyusedsubroutines.

Scipad:
Youcanedit*.scefile
and*.scifileshere

BasicOperations
p
Thesimplestwaytoexecutescilab codeistotypeit
inattheprompt,>>,inthegraphicalcommand
window.
Scilabdoesntneedtodeclareavariablebefore
usingit.Nopointersarerequiredeither.
Scilabisacasesensitivesoftware.Forexample
A=[12;34];butaisnotequaltoA
Use;afterthecommandtosuppressoutputtoscreen.
=%pi,imaginarynumber=%i,%e=2.71828
Linesafter// arecomments.Usetosplitalonglineintotwolines.
atan(p/q):2quadrantinversetangent;atan(p,q):4quadrantinversetangent
CrossproductNosuchcommandforScilab.Youhavetowriteitbyyourself.
Cross productNo such command for Scilab You have to write it by yourself
Scilabis1indexing,differentfromC++whichis0indexing.

MatrixManipulations
(1) Therowelementsofmatrixareseparatedbyspace orcomma(,) ;thecolumn
elementsofmatrixareseparatedbysemicolon(;),forexample:
A=[123;456]A=[]
(2)

Themultiplicationandproductofmatrices
ThemultiplicationofAandBisA*B
h
l i li i
f
d i * orA*B
*
theproductofA B isA.*B

A=[]B=[]

(3) Set A is a matrix A is the transposition matrix of A A [


(3)SetAisamatrix,AisthetranspositionmatrixofA.A=[
] A [
]A=[]
]
(4)DenotesthesolutiontothematrixequationAX=B.
if a1*x1+a2*x2=b1 a3*x1+a4*x2=b2
ifa1*x1+a2*x2=b1,a3*x1+a4*x2=b2
SetA=[
],B=[ ],x=[ ]X=A\B

(5)ColonisaveryusefultoolinScilab.
6

Programming:LoopandConditionalControl
(1)forforindex=start : increment : end
statements
end

(2) while
whileexpression
statements
end
d

(3) if
iflogicalexpressionthen
statements
else then
elsethen
statements
end

(4)breakitcan
interruptloops.

ProgrammingTipsandUseful
Commands
Put
Putthecommand
the command clear
clear and
and close
close intheverybeginningofa
in the very beginning of a *.sce
sce
scriptfiletodeletepreviousresults.
Putacommand
a command pause
pause inbetweenthelinestoserveasabreakpoint.
in between the lines to serve as a break point.
Put
Usereturntocontinueexecuting.
Usecommandwho_usertolistusersdefinedvariables.
browsevar():anembeddedfunctionwhichyoucanbrowseandeditexisting
variables.
a ab es
fsolve:findazeroofasystemofnnonlinearfunctions.Itscallingsequenceis
[[x]=fsolve(x0,fun,tol),xistheoptimizersolution,x0istheinitialvalue
] so e( 0 , u , to ) ,
s t e opt
e so ut o , 0 s t e t a a ue
whichyoustartingguessatthesolution,funisthefunctionthatyouwantto
solve,andtolistheprecisiontolerance.
8

Programming ofFunction
of Function
(1) EditthefunctiononSciPad
(2) cross
(2)
cross isthefunctionname.You
is the function name You
cannameitbyyourself.
(3) fistheoutputofthefunction.u1,
u2,u3,v1,v2andv3aretheinput
2 3 1 2 d 3
th i
t
parametersofthefunction.
(4)Savethefileascross.sci
(5) Loadthefunctionexec(filepath)
andtheyoucanexecuteit
d h
i
(6)Thevariablesdefinedinsidethe
functionarelocal.Theydonot
affectthevariablesoutsidethe
function.

GraphicsPlot
p
(1)xinit: Openanewgraphic.Ifyoudontdothisdatawillbeplottedinthe
samegraphic.
(2)plot(x,y): Usethiscommandtoplotthecurveabouttherelationshipofx
andy,wherexandyarebothvectors.
(3) l t (i 1) Fi d t th l ti
(3)locate(i,1):Findoutthelocationofthepoints(p1,p2.pi)
f th
i t ( 1 2 i)

(a)thepointswhichyouchoose.

(b)thecoordinatesofthepoints.
10

GraphicsLineProperties
p
p
(1) Use
Usethecommendged()
the commend ged() to
to
changethepropertiesoffigure.

((2)Choosetheitemthatyouwantto
)
y
changeitsproperties.
(3)Changetypeandwidthofthecurve.
(4)Changethecolorofthecurve.
11

GraphicsAxes
Graphics
AxesProperties
Properties

(1)Keyinthelabelofaxes.
(2) Choose the item to adjust the properties of axes
(2)Choosetheitemtoadjustthepropertiesofaxes.
(3)Changethefontsizeoflabel.
(4)Thefontsizeoftheaxes.
12

GraphicsExport
Graphics
ExportandPrint
and Print
(1) Choose
fileExport
(2)ChoosetheExport
typeitem,anddecide
thefiletypethatyou
wanttosave.

FilePrintPostscript

13

Animationofmechanisms

Slidercrankmechanismdemo
(ex4.3,p140ofCleghorn)

14

Animationofcams

(ex8.7,p.397ofWaldron)

Oscillating Roller Follower


OscillatingRollerFollower

15

Scilab BrowseHelpandWebResources

Scilabhompage
http://www.scilab.org/
TheinstructionofScilab(1)
The instruction of Scilab (1)
http://msdl.me.ncku.edu.tw/scilab/Site/Scilab_files/cintro.pdf
TheinstructionofScilab(2)
h //
http://mail.nkmu.edu.tw/~crlin/SciLab_Tutorial/SciLab_tut.htm
l k
d
/ l /
b
l/
b
h

16

You might also like