You are on page 1of 15

Scllab LnLerprlses S.A.S - 143 bls rue ?ves Le Coz - 78000 versallles (lrance) - www.scllab-enLerprlses.


kcos for very beg|nners

xcos for very beglnners - 2/13

1hls documenL has been wrlLLen by Scllab LnLerprlses.
2013 Scllab LnLerprlses. All rlghLs reserved.

xcos for very beglnners - 3/13
1ab|e of content

AbouL Lhls documenL 4
lnsLall Scllab 4
Malllng llsLs 4
ComplemenLary resources 4

8ecome fam|||ar w|th kcos
Ceneral envlronmenL 3
Lxample of a slmple dlagram deslgn 6
Superblocks 9

Menu bar 11
Avallable paleLLes 13
lnsLall a C compller 14

xcos for very beglnners - 4/13

About th|s document
1he purpose of Lhls documenL ls Lo gulde you sLep by sLep ln explorlng Lhe varlous baslc feaLures
of xcos Lool lncluded ln Scllab for a user who has never used a hybrld dynamlc sysLems modeler
and slmulaLor. 1hls presenLaLlon ls lnLenLlonally llmlLed Lo Lhe essenLlal Lo allow easler handllng
of xcos.
1he examples, dlagrams and lllusLraLlons are made wlLh Scllab 3.4.1. ?ou can reproduce all Lhose
examples from Lhls verslon.

Insta|| Sc||ab
Scllab ls open source sofLware for numerlcal compuLaLlon LhaL anybody can freely download.
Avallable under Wlndows, Llnux and Mac CS x, Scllab can be downloaded aL Lhe followlng
address: hLLp://
?ou can be noLlfled of new releases of Scllab sofLware by subscrlblng Lo our noLlflcaLlon channel
aL Lhe followlng address: hLLp://

Ma|||ng ||sts
1o ease Lhe exchange beLween Scllab users, dedlcaLed malllng llsLs exlsL (llsL for Lhe educaLlon
world, lnLernaLlonal llsL ln Lngllsh). 1he prlnclple ls slmple: reglsLranLs can communlcaLe wlLh
each oLher by e-mall (quesLlons, answers, sharlng of documenLs, feedbacks...).
1o browse Lhe avallable llsLs and Lo subscrlbe, go Lo Lhe followlng address:

Comp|ementary resources
Scllab webslLe has a dedlcaLed secLlon on Scllab use
(hLLp:// wlLh useful llnks and documenLs LhaL can
be freely downloaded and prlnLed.
?ou can also flnd ln Lhe same secLlon a slmllar documenL enLlLled Scllab for very beglnners"
whlch ls avallable for download.
xcos for very beglnners - 3/13
8ecome fam|||ar w|th kcos
numerlcal slmulaLlon ls nowadays essenLlal ln sysLem deslgn process. Complex phenomena
slmulaLlon (physlcal, mechanlcal, elecLronlcs, eLc.) allows Lhe sLudy of Lhelr behavlor and resulLs
wlLhouL havlng Lo conducL cosLly real experlmenLs. Wldely used ln Lhe world of lndusLry, Lhe
fuLure generaLlon of englneers and sclenLlsLs are Lralned slnce secondary school Lo Lhe concepLs
of modellng and slmulaLlon.
xcos ls Scllab Lool dedlcaLed Lo Lhe modellng and slmulaLlon of hybrld dynamlc sysLems lncludlng
boLh conLlnuous and dlscreLe models. lL also allows slmulaLlng sysLems governed by expllclL
equaLlons (causal slmulaLlon) and lmpllclL equaLlons (acausal slmulaLlon). xcos lncludes a
graphlcal edlLor whlch allows Lo easlly represenL models as block dlagrams by connecLlng Lhe
blocks Lo each oLher. Lach block represenLs a predeflned baslc funcLlon or a user-deflned one.

Genera| env|ronment
AfLer launchlng Scllab, Lhe envlronmenL by defaulL conslsLs of Lhe console, flles and varlables
browsers and a command hlsLory.

ln Lhe console afLer Lhe prompL --> ", [usL Lype a command and press Lhe LnLer key Lo obLaln
Lhe correspondlng resulL.
xcos can be launched:
lrom Lhe Loolbar, vla Lhe lcon, or
lrom Lhe menu bar, ln AppllcaLlons/xcos, or
lrom Lhe console, ln Lyplng:

xcos for very beglnners - 6/13
xcos opens by defaulL wlLh Lwo wlndows:
A paleLLe browser whlch provldes a seL of predeflned blocks,
An edlLlng wlndow whlch ls Lhe worklng space Lo deslgn dlagrams.

1o deslgn a dlagram, [usL selecL blocks ln Lhe paleLLe browser and poslLlon Lhem ln Lhe edlLlng
wlndow (cllck, drag and drop). 8locks are Lhen connecLed Lo each oLher uslng Lhelr dlfferenL porLs
(lnpuL, ouLpuL, evenL) ln order Lo slmulaLe Lhe creaLed model.

Lxamp|e of a s|mp|e d|agram des|gn
We are golng Lo explaln how Lo deslgn from scraLch a model of conLlnuous-Llme sysLem
represenLed by a flrsL-order Lransfer funcLlon.

Launch xcos.
As seen before, xcos opens by defaulL wlLh Lhe paleLLe browser and an edlLlng wlndow. ln Lhe
paleLLe browser, we are golng Lo use Lhe followlng blocks:

Des|gnat|on kepresentat|on Sub-pa|ette

ConLlnuous Lransfer funcLlon

ConLlnuous Llme



xcos for very beglnners - 7/13
Arrange Lhe blocks ln Lhe edlLlng wlndow. 1o connecL Lhe lnpuL and ouLpuL porLs Lo each oLher,
cllck on Lhe ouLpuL (black arrow) of Lhe S1L-lunC1lCn block and ln malnLalnlng Lhe
mouse buLLon pressed, connecL lL Lo Lhe lnpuL porL of Lhe CL8 block (a green hlghllghLed square
appears Lo lndlcaLe LhaL Lhe llnk ls correcL) as descrlbed ln Lhe lmages below:

8elease Lo compleLe Lhe llnk.

CompleLe Lhe connecLlons beLween Lhe dlfferenL blocks Lo achleve Lhls resulL:

lL ls posslble Lo lmprove Lhe general look of your dlagram ln uslng Lhe blocks allgnmenL opLlons
(lormaL Menu/Allgn blocks) and Lhe llnks sLyle (lormaL Menu/Llnk sLyle). AL any Llme, blocks can
be moved or reposlLloned by selecLlng Lhem and by malnLalnlng Lhe mouse buLLon pressed whlle
movlng Lhem. 8elease Lhe blocks ln Lhe deslred poslLlon.
SlmulaLlon ls launched by cllcklng on Lhe lcon (or from Lhe SlmulaLlon Menu/SLarL) and can
be sLopped by cllcklng on Lhe lcon (or from Lhe SlmulaLlon Menu/SLop).

A new wlndow ls dlsplayed (scope) wlLh Lhe slmulaLlon runnlng. AL Lhe boLLom of Lhe dlagram
edlLlng wlndow, a sLaLemenL lndlcaLes LhaL Lhe slmulaLlon ls ln progress:

xcos for very beglnners - 8/13

?ou can see LhaL Lhe slmulaLlon Llme ls qulLe long (you may have needed Lo sLop Lhe slmulaLlon
whlle runnlng) and LhaL Lhe response ls flaL. 1hus, we choose Lo modlfy Lhe parameLers of CL8
block and of Lhe slmulaLlon.

A "ConLexL" conLalnlng Scllab scrlpL allows easy use of funcLlons and varlables ln xcos blocks. We
are golng Lo use Lhls conLexL Lo seL Lhe blocks parameLers for dlagram slmulaLlon.

Cllck on SlmulaLlon/SeL ConLexL ln Lhe menu bar and deflne Lhe
followlng varlables:
k = 1
1au = 1

?ou can now use Lhese varlables Lo seL up Lhe dlagram blocks.

uouble-cllck on CL8 block. A dlalog box opens wlLh Lhe defaulL
seLLlngs of Lhe block. Modlfy Lhese seLLlngs as follows:
numeraLor: k
uenomlnaLor: 1+1au*s

1he new Lransfer funcLlon ls dlsplayed on Lhe block:

lf necessary, enlarge Lhe block so LhaL Lhe dlsplay flLs ln lL.
xcos for very beglnners - 9/13
We are now golng Lo seL up Lhe slmulaLlon and Lhe
blocks Lo vlsuallze Lhe Llme response of Lhe sysLem
Lo a sLepe. lor Lhls, we llmlL Lhe slmulaLlon Llme Lo 3
seconds (SlmulaLlon Menu/SeLup) ln modlfylng Lhe
flnal lnLegraLlon Llme.

uouble-cllck on CSCCL block Lo seL up Lhe dlsplay
of values beLween 0 and 1.2, Lhen Lhe scope refresh
perlod Lo 3 seconds. 1o do lL, change Lhe followlng
?mln: 0
?max: 1.2
8efresh perlod: 3

8esLarL Lhe slmulaLlon and vlew Lhe resulL:

1o ease Lhe undersLandlng of cerLaln dlagrams, lL ls ofLen useful Lo use superblocks or composlLe
blocks. A superblock conLalns a parL of a dlagram and blocks represenLlng lLs lnpuLs and ouLpuLs.
1he superblock can be handled as a slngle block wlLhln Lhe parenL dlagram.

AfLer deslgnlng a dlagram and selecLlng Lhe parL of Lhe
dlagram (or sub-dlagram) LhaL we wanL Lo gaLher lnLo a
block, Lhe creaLlon of Lhe superblock ls done from Lhe
menu LdlL/8eglon Lo superblock.

1he selecLlon ls now a block whlch conLenL can be
dlsplayed by double-cllck. A new edlLlng wlndow opens
wlLh Lhe lnlLlal selecLed blocks.

xcos for very beglnners - 10/13

lL ls also posslble Lo hlde Lhe creaLed superblock Lo dlsable access Lo Lhe subdlagram. 1o do so,
rlghL-cllck on Lhe superblock, Lhen on Superblock Mask/CreaLe.

We can also make some sub-dlagram conflguraLlon seLLlngs avallable ln a slngle seLup lnLerface
by a rlghL-cllck on Lhe superblock, Lhen Superblock Mask/CusLomlze.
1hen [usL add Lhe parameLers you wanL Lo make avallable.

1hls presenLaLlon was lnLenLlonally shorL and many oLher posslblllLles for slmulaLlng sysLems
exlsL wlLh many avallable blocks. 1o conLlnue Lo handle easlly xcos, we lnvlLe you Lo vlslL Lhe
many dlagrams examples avallable ln xcos demonsLraLlons by cllcklng on Lhe menu ?/xcos

xcos for very beglnners - 11/13

Menu bar
1he useful menu bar of xcos ls Lhe one of Lhe edlLlng wlndow.

I||e Menu
New d|agram (CLrl+n under Wlndows and Llnux/Cmd+n under Mac CS x)
Cpen a new xcos edlLlng wlndow.
Cpen (CLrl+C under Wlndows and Llnux /Cmd+C under Mac CS x)
Load a xcos flle lncludlng a dlagram or a paleLLe ln .zcos or .xcos formaL.
Cpen f||e |n Sc||ab current d|rectory
Load a xcos flle lncludlng a dlagram or a paleLLe from Scllab worklng dlrecLory ln .zcos or
.xcos formaL.
kecent f||es
rovlde Lhe recenLly opened flles.
C|ose (CLrl+W under Wlndows and Llnux /Cmd+W under Mac CS x)
Close Lhe currenL dlagram lf several dlagrams are opened. CulL xcos lf only one dlagram
ls opened. 1he auxlllary wlndows such as Lhe paleLLe browser are also closed ln closlng
Lhe lasL dlagram.
Save (CLrl+S under Wlndows and Llnux /Cmd+S under Mac CS x)
Save Lhe changes Lo Lhe dlagram. lf Lhe dlagram has noL been prevlously saved ln a flle,
lL wlll be proposed Lo be saved (see Save As).
Save as (CLrl+ShlfL+S under Wlndows and Llnux /Cmd+ ShlfL +S under Mac CS x)
Save Lhe dlagram or Lhe paleLLe wlLh a new name. 1he dlagram Lakes Lhe name of Lhe
flle (wlLhouL Lhe exLenslon).
Lxport (CLrl+L under Wlndows and Llnux /Cmd+L under Mac CS x)
LxporL an lmage of Lhe currenL xcos dlagram ln sLandard formaLs (nC, SvC, eLc.).
Lxport a|| d|agrams
LxporL lmages of Lhe dlagram and Lhe conLenL of lLs superblocks.
r|nt (CLrl+ under Wlndows and Llnux /Cmd+ under Mac CS x)
rlnL Lhe currenL dlagram.
u|t kcos (CLrl+C under Wlndows and Llnux /Cmd+C under Mac CS x)
CulL xcos.

Ld|t Menu
Undo (CLrl+Z under Wlndows and Llnux /Cmd+Z under Mac CS x)
Cancel Lhe lasL operaLlon.
kedo (CLrl+? under Wlndows and Llnux /Cmd+? under Mac CS x)
8esLore Lhe lasL operaLlon canceled.
Cut (CLrl+x under Wlndows and Llnux /Cmd+x under Mac CS x)
8emove Lhe selecLed ob[ecLs of a dlagram and keep a copy ln Lhe cllpboard.
Copy (CLrl+C under Wlndows and Llnux /Cmd+C under Mac CS x)
uL a copy of Lhe selecLed ob[ecLs ln Lhe cllpboard.
aste (CLrl+v under Wlndows and Llnux /Cmd+v under Mac CS x)
Add Lhe conLenL of Lhe cllpboard ln Lhe currenL dlagram.

xcos for very beglnners - 12/13
De|ete (ueleLe)
Lrase Lhe selecLed blocks or llnks. When a block ls erased, all lLs connecLed llnks are also
Se|ect a|| (CLrl+A under Wlndows and Llnux /Cmd+A under Mac CS x)
SelecL all Lhe elemenLs of Lhe currenL dlagram.
Inverse se|ect|on
8everse Lhe currenL selecLlon.
8|ock arameters (CLrl+8 under Wlndows and Llnux /Cmd+8 under Mac CS x)
SeL Lhe selecLed block (see Lhe block help Lo obLaln more lnformaLlon on lLs seLup).
keg|on to superb|ock
ConverL a selecLlon of blocks lnLo a superblock.

V|ew Menu
2oom In (CLrl+lus numerlc keypad under Wlndows and Llnux /Cmd+lus numerlc
keypad under Mac CS x)
Lnlarge Lhe vlew of 10.
2oom Cut (CLrl+Mlnus numerlc keypad under Wlndows and Llnux /Cmd+Mlnus
numerlc keypad under Mac CS x)
8educe Lhe vlew of 10.
I|t d|agram or b|ocks to v|ew
Ad[usL Lhe vlew Lo Lhe wlndow slze.
Norma| 100
Scale Lhe vlew Lo lLs defaulL slze.
a|ette browser
Show / Plde Lhe paleLLe browser.
D|agram browser
ulsplay a wlndow whlch llsLs Lhe global properLles of Lhe dlagram and of all Lhe ob[ecLs lL
conLalns (blocks and llnks).
Show / Plde a compleLe overvlew of Lhe currenL dlagram. WlLh vlewporL, Lhe user can
move Lhe worklng area on a parLlcular parL of Lhe dlagram.

S|mu|at|on Menu
Modlfy Lhe slmulaLlon parameLers.
Lxecut|on trace and Debug
SeL Lhe slmulaLlon ln a debug mode.
Set Context
Lnable Lo enLer Scllab lnsLrucLlons Lo deflne varlables or funcLlons LhaL can be used ln
seLLlng up dlagram blocks.
Complle Lhe dlagram.
Mode||ca |n|t|a||ze
Lnable Lhe lnlLlallzaLlon of Lhe varlables ln Lhe acausal dlagram subsysLem.
Launch Lhe slmulaLlon.
SLop Lhe slmulaLlon.
xcos for very beglnners - 13/13
Iormat Menu
kotate (CLrl+8 under Wlndows and Llnux/Cmd+8 under Mac CS x)
8oLaLe Lhe selecLed block(s) 90 counLerclockwlse.
I||p (CLrl+l under Wlndows and Llnux/Cmd+l under Mac CS x)
8everse Lhe poslLlons of lnpuL and ouLpuL evenLs poslLloned above and below of a
selecLed block.
M|rror (CLrl+M under Wlndows and Llnux/Cmd+M under Mac CS x)
8everse Lhe poslLlons of regular lnpuL and ouLpuL poslLloned on Lhe lefL and on Lhe rlghL
of a selecLed block.
Show ] n|de shadow
Show / Plde Lhe shadow of Lhe selecLed block.
A||gn b|ocks
8y selecLlng several blocks, lL ls posslble Lo allgn Lhem on Lhe horlzonLal axls (lefL, rlghL
and cenLer) or on Lhe verLlcal axls (Lop, boLLom and mlddle).
8order co|or
Change Lhe border color of Lhe selecLed blocks.
I||| co|or
Change Lhe flll color of Lhe selecLed blocks.
L|nk sty|e
Modlfy a llnk sLyle
D|agram background
Change Lhe background color of Lhe dlagram.
Lnable / ulsable Lhe grld. 1hanks Lo Lhe grld, blocks and llnks poslLlonlng ls easler.

1oo|s Menu
Code generat|on
Allow Lhe generaLlon of Lhe slmulaLlon code of Lhe selecLed superblock.

? Menu
kcos ne|p
Cpen Lhe help on xcos funcLlonlng, paleLLes, blocks and examples.
8|ock ne|p
Cpen Lhe help on a selecLed block
kcos Demos
Cpen examples of dlagrams and slmulaLe Lhem. 1he user can, lf he wanLs Lo, modlfy
Lhose dlagrams and save Lhem for a fuLure use. (8e careful, Lhe execuLlon of some
demonsLraLlon dlagrams needs Lo have a C compller lnsLalled on your machlne. lease
refer Lo Lhe page 13).

Ava||ab|e pa|ettes
Common|y Used 8|ocks
More used blocks.
Cont|nuous t|me systems
ConLlnuous blocks (lnLegraLlon, derlvaLlve, lu).
xcos for very beglnners - 14/13
8locks whose ouLpuLs are dlsconLlnuous funcLlons of Lhelr lnpuLs (hysLeresls).
D|screte t|me systems
8locks for modellng ln dlscreLe Llme (derlvaLlve, sampled, blocked).
Lookup 1ab|es
8locks compuLlng ouLpuL approxlmaLlons from Lhe lnpuLs.
Lvent hand||ng
8locs Lo manage evenLs ln Lhe dlagram (clock, mulLlpllcaLlon, frequency dlvlslon).
Mathemat|ca| Cperat|ons
8locks for modellng general maLhemaLlcal funcLlons (coslne, slne, dlvlslon,
8locks for slmple and complex maLrlx operaLlons.
8locks represenLlng baslc elecLrlcal componenLs (volLage source, reslsLor, dlode,
8locks allowlng Lhe manlpulaLlon of lnLegers (loglcal operaLors, loglc gaLes).
ort & Subsystem
8locks Lo creaLe subsysLems.
2ero cross|ng detect|on
8locks used Lo deLecL zero crosslngs durlng slmulaLlon. 1hese blocks use Lhe solvers
capablllLles (CuL or uAL) Lo perform Lhls operaLlon.
S|gna| kout|ng
8locks for slgnal rouLlng, mulLlplexlng, sample/blocked.
S|gna| rocess|ng
8locks for slgnal processlng appllcaLlons.
8locks for lmpllclL sysLems modellng.
8locks used for annoLaLlons.
CuLpuL blocks used for graphlcal dlsplay (scope) and for daLa exporL (flle or Scllab).
8locks of daLa sources (pulse, ramp, slne wave) and for readlng daLa from Scllab flles or
8locks represenLlng baslc Lhermo-hydraullc componenLs (pressure source, plpes, valves).
Demonstrat|ons b|ocks
8locks used ln demonsLraLlon dlagrams.
User-Def|ned Iunct|ons
user-blocks Lo model a behavlor (C, Scllab or Modellca slmulaLlon funcLlon).

Insta|| a C comp||er
lor some sysLems slmulaLlon (acausal sysLems conLalnlng for example hydraullc or elecLrlcal
blocks), lL ls necessary Lo have a C compller lnsLalled ln Lhe machlne.

Under W|ndows
lnsLall MlnCW module from Scllab, AppllcaLlons Menu / Module manager - A1CMS / Wlndows
1ools caLegory. MlnCW module wlll make Lhe llnk beLween Scllab and CCC compller (whlch you
xcos for very beglnners - 13/13
also have Lo lnsLall separaLely). lollow Lhe procedure deLalled ln Lhe module lnsLall wlndow
whlch wlll gulde you sLep by sLep ln Lhe lnsLall of MlnCW and CCC compller.

Under L|nux
CCC compller ls avallable by defaulL under Llnux CS. !usL check LhaL Lhe compller ls lnsLalled and
up Lo daLe (vla SynapLlc, ?um or any oLher package managemenL sysLem).

Under Mac
uownload xcode vla Lhe App SLore (Mac CS > 10.7) or vla Lhe Cu supplled wlLh Lhe compuLer
(Mac CS 10.3 and 10.6). lor earller verslons, see Lhe Apple webslLe. Conflrm Lhe posslblllLy Lo use
Lhe compller ouL of xcode envlronmenL. 1o do so, afLer launchlng xcode, go Lo "SeLLlngs", Lhen
"uownloads" and ln Lhe "ComponenLs" Lab, selecL Lhe "Check for and lnsLall updaLes
auLomaLlcally" box and lnsLall Lhe "Command Llne 1ools" exLenslon.

naLurally, lf you already have an lnsLalled C compller ln your machlne, you do noL have Lo lnsLall
anoLher one. 1o check LhaL Scllab has deLecLed a compller, use Lhe command LhaL reLurns 1 lf a
compller ls lnsLalled:
--> haveacompiler()