You are on page 1of 33

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

com





#$%&'( )*+ ,-+. (-/%00-+1


Scllab for very beglnners - 2/33






































1hls documenL has been co-wrlLLen by Scllab LnLerprlses and ChrlsLlne Comez, maLhemaLlcs Leacher aL Lycee uescarLes
(uescarLes Plgh School) ln AnLony, PauLs-de-Selne (lrance).
2013 Scllab LnLerprlses. All rlghLs reserved.

Scllab for very beglnners - 3/33
2'(&- *) $*03-03



403+*56$3%*0
AbouL Lhls documenL 4
lnsLall Scllab 4
Malllng llsL 4
ComplemenLary resources 4

78'93-+ : ; <-$*=- )'=%&%'+ >%38 #$%&'(
1he general envlronmenL and Lhe console 3
Slmple numerlcal calculaLlons 6
1he menu bar 7
1he edlLor 8
1he graphlcs wlndow 9
Wlndows managemenL and workspace cusLomlzaLlon 11

78'93-+ ? ! @+*/+'==%0/
varlables, asslgnmenL and dlsplay 12
Loops 16
1esLs 17
2 and 3u ploLs 18
SupplemenLs on maLrlces and vecLors 23
CalculaLlon accuracy 29
Solvlng dlfferenLlal equaLlons 30

78'93-+ A ; B1-)6& #$%&'( )60$3%*01
ln analysls 32
ln probablllLy and sLaLlsLlcs 32
1o dlsplay and ploL 33
uLlllLles 33

Scllab for very beglnners - 4/33
403+*56$3%*0

C(*63 38%1 5*$6=-03
1he purpose of Lhls documenL ls Lo gulde you sLep by sLep ln explorlng Lhe varlous baslc feaLures
of Scllab for a user who has never used numerlcal compuLaLlon sofLware. 1hls presenLaLlon ls
volunLarlly llmlLed Lo Lhe essenLlal Lo allow easler handllng of Scllab.
CompuLaLlons, graphs and lllusLraLlons are made wlLh Scllab 3.4.0. ?ou can reproduce all Lhose
commands from Lhls verslon.

4013'&& #$%&'(
Scllab ls numerlcal compuLaLlon sofLware LhaL anybody can freely download. Avallable under
Wlndows, Llnux and Mac CS x, Scllab can be downloaded aL Lhe followlng address:
hLLp://www.scllab.org/
?ou can be noLlfled of new releases of Scllab sofLware by subscrlblng Lo our channel noLlflcaLlon
aL Lhe followlng address: hLLp://llsLs.scllab.org/mallman/llsLlnfo/release

D'%&%0/ &%13
1o faclllLaLe Lhe exchange beLween Scllab users, dedlcaLed malllng llsLs exlsL (llsL ln lrench, 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:
hLLp://www.scllab.org/communlLles/user_zone/malllng_llsL

7*=9&-=-03'+. +-1*6+$-1
lf you have an lnLerneL connecLlon, we lnvlLe you Lo vlslL Scllab webslLe where you wlll flnd a
secLlon dedlcaLed Lo Lhe use of Scllab (hLLp://www.scllab.org/supporL/documenLaLlon), wlLh llnks
and relevanL documenLs whlch can be freely downloaded and prlnLed.

Scllab for very beglnners - 3/33
78'93-+ : ; <-$*=- )'=%&%'+ >%38 #$%&'(
1he useful workspace ln Scllab conslsLs of several wlndows:
1he console for maklng calculaLlons,
1he edlLor for wrlLlng programs,
1he graphlcs wlndows for dlsplaylng graphlcs,
1he embedded help.

28- /-0-+'& -0,%+*0=-03 '05 38- $*01*&-
AfLer double-cllcklng Lhe lcon Lo launch Scllab, Scllab envlronmenL by defaulL conslsLs of Lhe
followlng docked wlndows - console, flles and varlables browsers, command hlsLory (see
Wlndows managemenL and workspace cusLomlzaLlon", page 11):

ln Lhe console afLer Lhe prompL --> , [usL Lype a command and press Lhe LnLer key (Wlndows
and Llnux) or 8eLurn key (Mac CS x) on Lhe keyboard Lo obLaln Lhe correspondlng resulL.
--> 57/4
ans =
14.25
--> (2+9)^5
ans =
161051.

lL ls posslble Lo come back aL any momenL wlLh Lhe keyboard's arrow keys ^ - j or wlLh Lhe
mouse. 1he lefL and rlghL keys are used Lo change Lhe lnsLrucLlons and Lhe up and down keys are
used Lo come back on a prevlously execuLed command.
MenLlon
8efore Lhe resulL, ans ls
dlsplayed for answer".
Scllab for very beglnners - 6/33
#%=9&- 06=-+%$'& $'&$6&'3%*01
All compuLaLlons done wlLh Scllab are numerlcal. Scllab performs compuLaLlons wlLh maLrlces
(see chapLer 2, page 23).
CperaLlons are wrlLLen wlLh + for addlLlon, for subLracLlon, * for mulLlpllcaLlon, /
for dlvlslon, ^ for exponenLs. lor example:
-->2+3.4
ans =
5.4

1he case ls senslLlve. lL ls Lhus necessary Lo respecL uppercase and lowercase for Lhe calculaLlons
Lo be performed properly. lor example, wlLh sqrt command (whlch calculaLes Lhe square rooL):
-->sqrt(9)
ans =
3.
whlle: -->SQRT(9)
!--error 4
Undefined variable: SQRT

@'+3%$6&'+ 06=(-+1
%e and %pi represenL respecLlvely e and !:
--> %e
%e =
2.7182818
--> %pi
%pi =
3.1415927

%i represenLs Lhe i of complexes ln lnpuL and ls dlsplayed i ln ouLpuL:
--> 2+3*%i
ans =
2. + 3.i

E*+ 0*3 5%19&'.%0/ 38- +-16&31
ln addlng a seml colon ; aL Lhe end of a command llne, Lhe calculaLlon ls done buL Lhe resulL ls
noL dlsplayed.
-->(1+sqrt(5))/2; --> (1+sqrt(5))/2
ans =
1.618034
Scllab for very beglnners - 7/33
2* +-=%05 38- 0'=- *) ' )60$3%*0
1he names of commonly used funcLlons are summarlzed ln ChapLer 3 of Lhls documenL (page 32).
lor example:
--> exp(10)/factorial(10)
ans =
0.0060699

1he Lab key -! on Lhe keyboard can be used Lo compleLe Lhe name of a funcLlon or a varlable by
glvlng lLs flrsL few leLLers.
lor example, afLer Lyplng ln Lhe console Lhe command:
-->fact
and Lhen presslng Lhe Lab key, a wlndow ls dlsplayed wlLh all Lhe funcLlons and varlables names
beglnnlng wlLh fact, such as factorial and factor. !usL double cllck on Lhe requlred
funcLlon or selecL lL wlLh Lhe mouse or wlLh Lhe keys ^ j and press LnLer (Wlndows and Llnux)
or 8eLurn (Mac CS x) Lo lnserL lL ln Lhe command llne.

28- =-06 ('+
1he menus llsLed below are parLlcularly useful.
C99&%$'3%*01
1he command hlsLory allows you Lo flnd all Lhe commands from prevlous sesslons Lo Lhe
currenL sesslon.
1he varlables browser allows you Lo flnd all varlables prevlously used durlng Lhe currenL
sesslon.
F5%3
@+-)-+-0$-1 (ln #$%&'( menu under Mac CS x) allows you Lo seL and cusLomlze colors, fonLs and
fonL slze ln Lhe console and ln Lhe edlLor, whlch ls very useful for screen pro[ecLlon.
Cllcklng on 7&-'+ 7*01*&- clears Lhe enLlre conLenL of Lhe console. ln Lhls case, Lhe command
hlsLory ls sLlll avallable and calculaLlons made durlng Lhe sesslon remaln ln memory. Commands
LhaL have been erased are sLlll avallable Lhrough Lhe keyboard's arrow keys.
7*03+*&
1o lnLerrupL a runnlng program, you can:
1ype pause ln Lhe program or cllck on 7*03+*&G 403-++693 ln Lhe menu bar (CLrl x under
Wlndows and Llnux or Command x under Mac CS x), lf Lhe program ls already runnlng.
ln all cases, Lhe prompL --> wlll Lurn lnLo -1-> , Lhen lnLo -2-> ., lf Lhe
operaLlon ls repeaLed.
1o reLurn Lo Lhe Llme prlor Lo Lhe program lnLerrupLlon, Lype resume ln Lhe console or
cllck on 7*03+*& G H-16=-.
1o qulL for good a calculaLlon wlLhouL any posslblllLy of reLurn, Lype abort ln Lhe
console or cllck on 7*03+*& G C(*+3 ln Lhe menu bar.
MenLlon
All avallable funcLlons are
also llsLed ln Lhe embedded
help by cllcklng ln Lhe menu
bar on I G #$%&'( J-&9.
Scllab for very beglnners - 8/33
28- -5%3*+
1yplng dlrecLly lnLo Lhe console has Lwo dlsadvanLages: lL ls noL posslble Lo save Lhe commands
and lL ls noL easy Lo edlL mulLlple llnes of lnsLrucLlon. 1he edlLor ls Lhe approprlaLe Lool Lo run
mulLlple lnsLrucLlons.
K9-0%0/ 38- -5%3*+
1o open Lhe edlLor from Lhe console, cllck on Lhe flrsL lcon ln Lhe Loolbar or on C99&%$'3%*01
G #$%L*3-1 ln Lhe menu bar.
1he edlLor opens wlLh a defaulL flle named Untitled 1 .

M+%3%0/ %0 38- -5%3*+
1yplng ln Lhe edlLor ls llke as ln any word processor.
ln Lhe LexL edlLor, openlng and closlng parenLheses, end loops, funcLlon and LesL commands are
added auLomaLlcally. Powever, Lhese feaLures can be dlsabled ln K93%*01 G C63*!$*=9&-3%*0 *0
menu, ln cllcklng on Lhe Lwo below enLrles enabled by defaulL:
NOPOQ
%)O)60$3%*0OQ

Whlle ln prlnclple each lnsLrucLlon should be enLered on a separaLe llne, lL ls posslble Lo Lype
mulLlple sLaLemenLs on a same llne separaLlng each sLaLemenL wlLh a semlcolon ; .
A space aL Lhe sLarL of Lhe llne called lndenLaLlon ls auLomaLlc when a loop or a LesL ls sLarLed.
ln Lhe followlng example, we calculaLe 10 Lerms of Lhe sequence !!
!
! deflned by:
!
!
! !
!
!!!
! !!
!
! !


MenLlon
- CommenLs preceded wlLh // wlll noL be Laken lnLo accounL ln Lhe calculaLlons.
- 1o change Lhe fonL, cllck on K93%*01 G @+-)-+-0$-1.
- When wrlLlng a program, lndenLaLlon ls auLomaLlc. lf Lhls ls noL Lhe case, cllck on E*+='3 G 7*++-$3 %05-03'3%*0 Lo resLore lL
(CLrl l under Wlndows and Llnux or Command l under Mac CS x).
Scllab for very beglnners - 9/33
#',%0/
Any flle can be saved by cllcklng on E%&- G #',- '1.
1he exLenslon .sce aL Lhe end of a flle name wlll launch auLomaLlcally Scllab when openlng lL
(excepL under Llnux and Mac CS x).
Copylng lnLo Lhe console, execuLlng a program
ln cllcklng on LxecuLe ln Lhe menu bar, Lhree opLlons are avallable:
LxecuLe Q)%&- >%38 0* -$8* (CLrl ShlfL L under Wlndows and Llnux, Cmd ShlfL L under
Mac CS x): Lhe flle ls execuLed wlLhouL wrlLlng Lhe program ln Lhe console (savlng Lhe
flle flrsL ls mandaLory).
LxecuLe R Q )%&- >%38 -$8* (CLrl L under Wlndows and Llnux, Cmd L under Mac CS x):
rewrlLe Lhe flle lnLo Lhe console and execuLes lL.
LxecuLe Q603%& 38- $'+-3O >%38 -$8* (CLrl L under Wlndows and Llnux, Cmd L under
Mac CS x): rewrlLe Lhe selecLlon chosen wlLh Lhe mouse lnLo Lhe console and execuLes lL
or execuLe Lhe flle daLa unLll Lhe careL poslLlon deflned by Lhe user.

SLandard copy/pasLe can also be used.

28- /+'98%$1 >%05*>
K9-0%0/ ' /+'98%$1 >%05*>
A graphlcs wlndow opens auLomaLlcally when maklng any ploL. lL ls posslble Lo ploL curves,
surfaces, sequences of polnLs (see chapLer 2, page 18).
1o obLaln an example of curve, Lype ln Lhe console:
-->plot

MenLlon
- 1o erase a prevlous ploL,
Lype clf
( clear flgure ).
- 1o open anoLher graphlcs
wlndow, Lype scf; ( seL
currenL flgure ).
lf several graphlc wlndows
are open, you can choose ln
whlch Lhe ploL wlll be drawn
by Lyplng scf(n), n for Lhe
graphlcs wlndow number
(menLloned on Lhe Lop lefL).
Scllab for very beglnners - 10/33
D*5%).%0/ ' 9&*3
1he magnlfylng glass allows zoomlng. 1o zoom ln Lwo dlmenslons, cllck on Lhe Lool and wlLh
Lhe mouse creaLe a recLangle whlch wlll consLlLuLe Lhe new enlarged vlew. 1o zoom ln Lhree
dlmenslons, cllck on Lhe Lool and creaLe a paralleleplped whlch wlll consLlLuLe Lhe new enlarged
vlew. lL ls also posslble Lo zoom ln uslng Lhe mouse wheel. 1o reLurn Lo Lhe lnlLlal screen, cllck on
Lhe oLher magnlfylng glass .
1he lcon enables roLaLlon of Lhe flgure (parLlcularly useful ln 3-u) wlLh rlghL cllck acLlons
whlch are gulded by messages ln Lhe boLLom of Lhe graphlcs wlndow.
lor more preclse modlflcaLlons, cllck on F5%3 G E%/6+- 9+*9-+3%-1 or CS-1 9+*9-+3%-1 and leL
yourselves be gulded (Lhls opLlon ls noL yeL avallable under Mac CS x).

K0&%0- 8-&9
1o access Lhe onllne help, cllck on I G #$%&'( J-&9 ln Lhe menu bar, or Lype ln Lhe console:
-->help



1o geL help wlLh any funcLlon, Lype help ln Lhe console followed by Lhe name of Lhe approprlaLe
funcLlon. lor example:
-->help sin
dlsplays help for sin (slne) funcLlon.


MenLlon
Lxamples of use can be
execuLed ln Scllab and
edlLed ln SclnoLes ln uslng
Lhe assoclaLed buLLons ln
Lhe example framework.
Scllab for very beglnners - 11/33
M%05*>1 ='0'/-=-03 '05 >*+T19'$- $613*=%U'3%*0
As ln Lhe defaulL Scllab envlronmenL, where Lhe console, flles and varlables browsers and
command hlsLory are all LogeLher docked wlndows, all oLher wlndows ln Scllab can be
reposlLloned ln a slngle one. lor example, Lhe user can choose Lo poslLlon Lhe edlLor ln Lhe
defaulL envlronmenL of Scllab.
1o dock a wlndow ln anoLher one, flrsL ldenLlfy Lhe blue horlzonLal bar under Wlndows, or black
under Mac CS x and Llnux, aL Lhe Lop of Lhe wlndow ln Lhe Loolbar conLalnlng a quesLlon mark on
Lhe rlghL.
under Wlndows and Llnux, cllck on Lhls bar wlLh Lhe lefL mouse buLLon and, whlle
malnLalnlng Lhe cllck, move Lhe mouse polnLer ln Lhe deslred wlndow.
under Mac CS x, cllck on Lhls bar and whlle malnLalnlng Lhe cllck, move lL ln Lhe deslred
wlndow.
A recLangle appears lndlcaLlng Lhe fuLure poslLlonlng of Lhe wlndow. When Lhe poslLlon ls Lhe
one you wanL, release Lhe mouse buLLon. 1o cancel and brlng ouL Lhe wlndow, cllck on Lhe small
arrow on Lhe rlghL of Lhe same bar.



Scllab for very beglnners - 12/33
78'93-+ ? ! @+*/+'==%0/

ln Lhe examples glven ln Lhls documenL, any llne preceded by --> ls a command, Lhe oLher
llnes are Lhe reLurns from commands (calculaLlon resulLs, error messages.). uo noL wrlLe -->
ln Lhe edlLor. 1hey are lnLroduced here Lo make Lhe dlsLlncLlon beLween command llnes and
calculaLlon resulLs as lL ls dlsplayed ln Lhe console afLer copylng/pasLlng. When presenLed ln a
Lable (wlLhouL --> and no calculaLlon resulL), Lhe commands are deplcLed exacLly as Lhey
should be Lyped ln Lhe edlLor.

V'+%'(&-1O '11%/0=-03 '05 5%19&'.
V'+%'(&-1
Scllab ls noL a compuLer algebra sysLem. lL calculaLes only wlLh numbers. All calculaLlons are done
wlLh maLrlces, alLhough Lhls may go unnoLlced. Lven lf Lhe concepL of maLrlces ls unknown,
vecLors and sequences of numbers can explaln lL, as Lhey are, ln facL, maLrlces of dlmenslon 1 !
or ! 1 and a number ls lLself a maLrlx of dlmenslon 1 1.
varlables do noL need Lo be declared ln advance, buL any varlable musL have a value. lor
example, obLalnlng Lhe value of a varlable whlch has noL been glven a value produces an error:
-->a
!--error 4
Undefined variable : a

lf a value ls asslgned Lo Lhe varlable a, Lhere ls no longer an error:
--> a=%pi/4
a =
0.7853982
--> a
a =
0.7853982

varlables may Lake any name LhaL ls noL already deflned by Lhe sysLem:
--> Piby2=%pi/2
Piby2 =
1.5707963

MenLlon
Llke Lhe Scllab funcLlons, a
varlable name musL noL
have accenLs or speclal
characLers.
Scllab for very beglnners - 13/33
1he resulL of a calculaLlon LhaL ls noL asslgned Lo a varlable ls auLomaLlcally asslgned Lo Lhe
varlable called ans:
-->3*(4-2)
ans =
6.

-->ans
ans =
6.

E60$3%*01
luncLlons are Lhe easlesL and mosL naLural way Lo make compuLaLlons from varlables and for
obLalnlng resulLs from varlables.
A funcLlon deflnlLlon beglns wlLh function and ends wlLh endfunction. lor example, Lo
converL euros (e) ln dollars (d) wlLh an exchange raLe (L), Lhe dollars funcLlon ls deflned. 1he
varlables are e and t and Lhe lmage ls d.
-->function d=dollars(e,t); d=e*t; endfunction

-->dollars(200,1.4)
ans =
280.

very usually numerlcal funcLlons are funcLlons of one real varlable. lor example, Lwo funcLlons f
and g are deflned uslng Lhe followlng commands:
-->function y=f(x); y=36/(8+exp(-x)); endfunction

-->function y=g(x); y=4*x/9+4; endfunction

1he deflned funcLlons can Lhen be used Lo calculaLe values:
--> f(10)
ans =
4.4999745
--> g(12.5)
ans =
9.5555556
MenLlon
1he varlables x and y are
dummy varlables, Lhelr
names can be reused when
deflnlng oLher funcLlons or
ln Scllab.
Scllab for very beglnners - 14/33
H-W6-13%0/ 38- '11%/0=-03 *) ' ,'+%'(&-
AsslgnmenL ls made easlly uslng Lhe = operaLor.

X%19&'.
WrlLlng
1yplng Lhe name of a varlable dlsplays lLs value, excepL when Lhere ls ; aL Lhe end of Lhe
command llne.

8rackeLs
MaLrlces are deflned uslng square brackeLs (see page 23). As menLloned before, maLrlx
compuLaLlon ls Lhe basls of calculaLlons ln Scllab. A space or comma ls used Lo separaLe columns
and semlcolons are used Lo separaLe rows.

1o deflne a column vecLor and obLaln a column dlsplay:
-->v=[3;-2;5]
v =
3.
- 2.
5.

1o deflne a row vecLor and obLaln a row dlsplay:
-->v=[3,-2,5]
v =
3. - 2. 5.

1o deflne a maLrlx and obLaln a Labular dlsplay:
-->m=[1 2 3;4 5 6;7 8 9]
m =
1. 2. 3.
4. 5. 6.
7. 8. 9.


MenLlon
1hls command can also be
Lyped under Lhe form:
v=[3 -2 5]
MenLlon
1hls command can also be
Lyped under Lhe form:
m=[1,2,3;4,5,6;7,8,9]
Scllab for very beglnners - 13/33
dlsp funcLlon
disp musL always be used wlLh parenLheses.
WlLh Lhe vecLor v prevlously deflned:
-->v(2)
ans =
- 2.

-->disp(v(2))
- 2.

1o dlsplay a sLrlng (usually a senLence), puL lL beLween quoLes:
-->disp("Bob won")
Bob won

1o dlsplay a comblnaLlon of words and values use Lhe string command whlch converLs values
Lo characLer sLrlngs uslng a + beLween Lhe dlfferenL parLs:
-->d=500;

-->disp("Bob won "+string(d)+" dollars")
Bob won 500 dollars

lf Lhe senLence conLalns an slngle quoLe, Lhe laLLer needs Lo be doubled ln Lhe sLrlng Lo be
dlsplayed properly:
-->disp("It''s fair")
It's fair

Y**91
40$+-=-03'3%*0
1he : operaLor allows Lo deflne vecLors of numbers whose coordlnaLes are ln arlLhmeLlc
sequence. We glve: << beglnnlng value: sLep: endlng value>>. lL ls posslble LhaL endlng value" ls
noL reached. lf Lhe sLep ls noL menLloned, lLs defaulL value ls 1.
lor example, Lo deflne a row vecLor of lnLegers whlch lncremenLs ln sLeps of 1 from 3 and 10:
-->3:10
ans =
3. 4. 5. 6. 7. 8. 9. 10.
or whlch lncremenLs ln sLeps of 2 from 1 Lo 10:
-->1:2:10
ans =
1. 3. 5. 7. 9.
Scllab for very beglnners - 16/33
or whlch decreases ln sLeps of 4 from 20 Lo 2:
-->u=20:-4:2
u =
20. 16. 12. 8. 4.

E*+
1he easlesL loop sLrucLure for a flxed number of lLeraLlons ls wrlLLen wlLh for end.

Lxample: CalculaLlon of 20 Lerms of a sequence deflned by recurrence by:
!
!
! !
!
!!!
! !
!
! !! ! !


AlgorlLhm Scllab LdlLor
uL 4 ln u(1)
lor n from 1 Lo 20
u(n+1) Lakes Lhe value u(n)+2n+3
and u(n)
ulsplay n and u(n)
Lnd for
u(1)=4;
for n=1:20
u(n+1)= u(n)+2*n+3;
disp([n,u(n)])
end

M8%&-
1o sLop a loop when a glven goal ls reached, while end ls used.

l planLed a ChrlsLmas Lree ln 2003 measurlng 1.20 m. lL grows by 30 cm per year. l declded Lo cuL
lL when lL exceeds 7 m. ln whaL year wlll l cuL Lhe Lree?

AlgorlLhm Scllab LdlLor
uL 1.2 ln h (h = Lree helghL)
uL 2003 ln y (y = year)
Whlle h<7
h Lakes Lhe value h+0.3 (Lhe Lree grows)
y Lakes Lhe value y+1 (one year passes)
Lnd whlle
ulsplay y (Lhe flnal year)

h=1.2;
y=2005;
while h<7
h=h+0.3;
y=y+1;
end
disp("I will cut the..
tree in "+string(y))

MenLlon
When a command ls Loo long Lo be wrlLLen ln one llne, Lhe edlLor wlll wrap llnes. Cne can also wrap llnes uslng .. (Lwo
doLs) before golng Lo Lhe nexL llne.
Scllab for very beglnners - 17/33
2-131
7*=9'+%1*0 *9-+'3*+1
useful LesLs lnclude comparlng numbers or deLermlnlng wheLher a sLaLemenL ls Lrue or false.
8elow Lhe correspondlng commands:
Lqual ulfferenL Less CreaLer Less or equal
CreaLer or
equal
== <> < > <= >=
1rue lalse And Cr no
%T %F & | ~


1o compare Lwo vecLors (or Lwo maLrlces), Lhe LesLs == and <> wlll compare Lerm by Lerm.
lor example:
-->X=[1,2,5]; Y=[5,3,5];

-->X==Y
ans =
F F T

1o LesL lf Lwo vecLors are equal, isequal ls used and ~isequal ls used lf Lhey are dlfferenL:
-->isequal(X,Y)
ans =
F

-->~isequal(X,Y)
ans =
T

4)Q38-0
1he baslc condlLlonal sLaLemenLs are Lhe followlng:
if then else end,
if then elseif then else end.

if then musL be wrlLLen on Lhe same llne and llkewlse wlLh elseif then.

MenLlon
8e cauLlous wlLh calculaLlon accuracy. CalculaLlons are approached and == wlll someLlmes glve wrong resulLs (see
CalculaLlon accuracy, page 30).
Scllab for very beglnners - 18/33
Lxample: Allce Lhrows Lhree dlce.
lf she geLs Lhree 6's she wlns $20,
lf she geLs Lhree ldenLlcal numbers dlfferenL from 6 she wlns $10,
lf she geLs Lwo ldenLlcal numbers she wlns $3,
CLherwlse she wlns noLhlng.

SlmulaLe a Lrlal and calculaLe Allce's wlnnlngs uslng Lhe funcLlons:
grand (see page 22),
unique(D)whlch keeps only once Lhe values LhaL appears several Llmes ln D,
length(unique(D)) whlch reLurns Lhe slze of Lhe obLalned vecLor, LhaL ls Lo say 1 lf
Lhree dlce are equal, and 2 lf Lwo dlce are equal.

AlgorlLhm Scllab LdlLor
uL Lhe Lhree values ln u
lf Allce geLs Lhree 6, Lhen
Allce wlns 20 dollars
Llse lf she recelves Lhree ldenLlcal values,
Lhen
Allce wlns 10 dollars
Llse, lf she recelves Lwo ldenLlcal values, Lhen
Allce wlns 3 dollars
CLherwlse
Allce wlns noLhlng
Lnd lf
ulsplay Allce's wlnnlngs

D=grand(1,3,"uin",1,6);
if D==[6,6,6] then
W=20;
elseif length(unique(D))==1 then
W=10;
elseif length (unique(D))==2 then
W=5;
else
W=0;
end
disp("Alice wins "+..
string(W)+ " dollars")

?!X '05 A!X 9&*31
plot command ls used Lo creaLe ploLs ln Lhe plane. Color and appearance can be speclfled by
puLLlng lndlcaLlons of color and polnLs sLyle wlLhln quoLes:
Colors
"b" = blue (by defaulL), "k" = black, "r" = red, "g" = green, "c" = cyan, "m" = magenLa,
"y" = yellow, "w" = whlLe.
olnL sLyles
!olned (by defaulL), or ".", "+", "o", "x", "*".
CLher opLlons are avallable wlLh: "s", "d", "v", "<", and ">".


Scllab for very beglnners - 19/33
<'1%$ 9&*31
1o ploL a polnL
loL Lhe polnL A(1 , 2) wlLh a red polnL.
Scllab LdlLor Craphlcs Wlndow
plot(1,2,".r")


1o ploL a segmenL
loL Lhe segmenL [A8] ln blue (by defaulL) wlLh A(1 , 2) and 8(3 , 3).
Scllab LdlLor Craphlcs Wlndow
plot([1,3],[2,5])


@&*31 *) 9&'0- $6+,-1 5-)%0-5 (. )60$3%*01 .Z)NS[
lor a funcLlon ! ! !!!! Lhe values of x are speclfled uslng Lhe linspace command by wrlLlng:
x=linspace(a,b,n); ln whlch a ls Lhe smallesL value of Lhe varlable !, b Lhe hlghesL value
of !, and n Lhe number of values calculaLed beLween a and b.
uo noL forgeL Lhe ; sympbol oLherwlse all n values of ! wlll be dlsplayed.

lor example, conslder Lwo funcLlons ! and ! deflned over Lhe lnLerval [-2 , 3] by:
! ! ! !!
!
! !!!!
!!
, and ! ! ! !"#
!
!


Scllab for very beglnners - 20/33
WlLh Lhe program below, we ploL Lhe curve deflned by!, ln blue by defaulL:
Scllab LdlLor Craphlcs Wlndow
function y=f(x)
y=(x^2+2*x)*exp(-x)
endfunction
x=linspace(-2,5,50);
plot(x,f)

8y addlng Lhe program below, we obLaln Lhe ploL of Lwo curves, LhaL of f ln red and LhaL of g ln
green. 1he prevlous ploL was cleared Lhrough Lhe clf command ( clear flgure ).
Scllab LdlLor Craphlcs Wlndow
function y=g(x)
y=sin(x/2)
endfunction
x=linspace(-2,5,50);
clf
plot(x,f,"r",x,g,"g")


@&*31 *) 1-W6-0$-1 *) 9*%031
1erms of a sequence
1he mosL common case ls Lo ploL Lhe sequences of polnLs !!!! ! ! ! afLer calculaLlng Lhe
coordlnaLes !!!! of a vecLor !. plot(u,"*r") speclfles Lhe sLyle and color of Lhe polnLs ln
quoLes: red and non-connecLed sLars. 8y defaulL, polnLs are ploLLed ln blue and are connecLed.
Scllab LdlLor Craphlcs Wlndow
for n=1:50
u(n)=(-0.8)^n;
end
clf; plot(u,"*r")

Scllab for very beglnners - 21/33
8lvarlaLe sLaLlsLlcal daLa
8lvarlaLe sLaLlsLlcal daLa are glven ln Lhe form of Lwo vecLors: leL's call Lhem x and ?.
plot(X,Y,"<") wlll ploL a scaLLer ploL of !!!
!
! !
!
! wlLh blue Lrlangles.
Scllab LdlLor Craphlcs Wlndow
X=[1,3,3,7,7,9,10];
Y=[8,7,5,5,4,2,2];
clf; plot(X,Y,"<")


@&*31 %0 A 5%=-01%*01
Scllab can be used Lo ploL surfaces and curves ln space, wlLh many opLlons for Lhe LreaLmenL of
hldden faces, face colors, polnLs of vlew, eLc. 1he followlng examples wlll lllusLraLe 3-u ploLs.
1he surf funcLlon can be used for ploLLlng surfaces. 1hls funcLlon has Lhree lnpuL varlables, x, y
and z. x and y are respecLlvely vecLors of slze ! and ! correspondlng Lo polnLs on Lhe axes !!"!
and !!"!. z ls a maLrlx of dlmenslon !!! wlLh elemenL !
!"
correspondlng Lo Lhe helghL of Lhe
polnL wlLh x-coordlnaLe !
!
and ?-coordlnaLe !
!
.
1o ploL Lhe surface deflned by a funcLlon of Lhe form ! ! !!!! !!, lL ls necessary Lo :
ueflne funcLlon !
CalculaLe z=feval(x,y,f)'
feval(x,y,f) reLurns Lhe !!! maLrlx whose !" elemenL ls !!!
!
! !
!
! whlch wlll be
Lransposed by uslng Lhe slngle quoLe symbol '
LxecuLe surf(x,y,z).

1o ploL Lhe surface ! ! !!
!
! !
!
(elllpLlc parabolold):
Scllab LdlLor Craphlcs Wlndow
function z=f(x,y)
z=2*x^2+y^2;
endfunction
x=linspace(-1,1,100);
y=linspace(-2,2,200);
z=feval(x,y,f)';
clf
surf(x,y,z)

Scllab for very beglnners - 22/33
Curves ln space may be ploLLed uslng Lhe param3d funcLlon. param3d has Lhree argumenLs, x,
y and z, each vecLors has Lhe same dlmenslon and corresponds Lo Lhe polnLs !!
!
! !
!
! !
!
! on Lhe
curve.

1o ploL Lhe hellx deflned by !! ! !"# ! ! ! ! !"# ! ! ! ! !!:
Scllab LdlLor Craphlcs Wlndow
t=linspace(0,4*%pi,100);
param3d(cos(t),sin(t),t)


#%=6&'3%*01 '05 13'3%13%$1
Several funcLlons are avallable ln Scllab Lo perform slmulaLlons qulckly and efflclenLly.
8andom sequences
grand(1,p,"uin",m,n) reLurns a vecLor of ! random lnLeger sequences beLween
! and ! wlLh ! poslLlve lnLeger, ! and ! lnLegers and ! ! !.
-->t= grand(1,4,"uin",1,6)
t =
3. 1. 3. 6.

grand(1,p,"unf",a,b) reLurns a vecLor of ! random real sequences beLween !
and ! wlLh ! poslLlve lnLeger, ! and ! real and ! ! !.
-->tr= grand(1,2,"unf",-1,1)
tr =
- 0.7460264 0.9377355

Scllab for very beglnners - 23/33
#3'3%13%$1
All Lhe sLandard sLaLlsLlcal funcLlons are llsLed on page 32.
keep parLlcularly ln mlnd:
1he funcLlon bar(x,n,color) whlch draws bar graphs:
Scllab LdlLor Craphlcs Wlndow
x=[1:10];
n=[8,6,13,10,6,4,16,7,8,5];
clf; bar(x,n)

lor a bar graph represenLlng Lwo seLs slde by slde: conslder Lhe serles of values x and
Lhe Lwo serles of numbers n1 and n2. lor ploLLlng, n1 and n2 musL be column vecLors
LhaL ls why Lransposes are used ln Lhe example below:
Scllab LdlLor Craphlcs Wlndow
X=[1,2,5];n1=[5,10,5];n2=[6,8,7];
bar(X,[n1',n2'])

1he color opLlonal argumenL deflnes Lhe color as ln Lhe plot funcLlon.

C55%3%*0'& %0)*+='3%*0 *0 ='3+%$-1 '05 ,-$3*+1
C$$-11%0/ -&-=-031
Square braces are used Lo deflne maLrlces. A space or a comma ls used Lo swlLch from one
column Lo anoLher and semlcolons are used Lo swlLch from one llne Lo anoLher.

-->m=[1 2 3;4 5 6]
m =
1. 2. 3.
4. 5. 6.

arenLheses are used Lo access elemenLs or Lo modlfy Lhem.
MenLlon
1hls command can also be
Lyped under Lhe form:
m=[1,2,3;4,5,6]
Scllab for very beglnners - 24/33
-->m(2,3)
ans =
6.

-->m(2,3)=23
m =
1. 2. 3.
4. 5. 23.

1he : operaLor ls used Lo deslgnaLe all Lhe rows or all columns of a maLrlx.

1o vlew Lhe second row of Lhe maLrlx m, Lype:
-->m(2,:)
ans =
4. 5. 23.

And Lhe Lhlrd column:
-->m(:,3)
ans =
3.
23.

1o obLaln Lhe Lranspose of a maLrlx or a vecLor use Lhe slngle quoLe symbol ' :
-->m'
ans =
1. 4.
2. 5.
3. 23.

K9-+'3%*01
1he operaLlons * , / are maLrlx operaLlons. 1o make elemenL wlse operaLlons, we need Lo
puL a doL before Lhe operaLlng slgn: .* , ./ .
-->A=[1,2,3;4,5,6]
A =
1. 2. 3.
4. 5. 6.

-->B=[1;1;2]
Scllab for very beglnners - 23/33
B =
1.
1.
2.
-->A*B
ans =
9.
21.
MaLrlx mulLlpllcaLlon
-->A*A
!--error 10
Inconsistent multiplication.
ulmenslons are noL conslsLenL
-->A.*A
ans =
1. 4. 9.
16. 25. 36.
LlemenL wlse mulLlpllcaLlon
-->2*(A+2)
ans =
6. 8. 10.
12. 14. 16.
1he operaLlon ls performed on each elemenL
because 2 ls a number
-->A/A
ans =
1. 1.518D-16
3.795D-15 1.
Clves Lhe maLrlx x for whlch x*A = A
1he exacL resulL ls:
1. 0
0 1.

lor reasons of calculaLlon accuracy, Lhe resulL can
be sllghLly dlfferenL dependlng on your verslon of
Scllab and your operaLlng sysLem (see calculaLlon
accuracy, page 29).
-->A./A
ans =
1. 1. 1.
1. 1. 1.
Clves Lhe maLrlx dlvlded elemenL wlse
ln Lhe case of vecLors:
-->C=1:4
C =
1. 2. 3. 4.

-->C*C
!--error 10
Inconsistent multiplication.
ulmenslons are noL conslsLenL

Scllab for very beglnners - 26/33
-->C.*C
ans =
1. 4. 9. 16.
lL ls also posslble Lo wrlLe C^2 because, for
vecLors, exponenLs are lnLerpreLed as an operaLlon
elemenL wlse. 1hls ls noL Lhe case wlLh maLrlces.
-->1/C
ans =
0.0333333
0.0666667
0.1
0.1333333
ln Lhls parLlcular case wlLh vecLors, we flnd Lhe
vecLor x for whlch C*x = 1
-->(1)./C
ans =
1. 0.5 0.3333333
0.25
8everse elemenL wlse
As prevlously, C^(-1) ls posslble. 1he
parenLheses around 1 are necessary so LhaL Lhe
polnL ls noL consldered as a comma as parL of Lhe
number 1. lL ls also posslble Lo wrlLe 1 ./C wlLh
a space beLween 1 and .

#*&,%0/ &%0-'+ 1.13-=1
1o solve Lhe llnear sysLem Ax = ?, ln whlch A ls a square maLrlx, use Lhe backslash \
x = A \ ?.
8e cauLlous, Lhe operaLlon ? / A wlll glve (only lf Lhe dlmenslons are correcL) anoLher resulL, LhaL
ls Lo say Lhe maLrlx Z for whlch Z A = ?.

1o solve Lhe sysLem:
! ! !
! ! !
!! !
!
!

-->A=[1 2 3;4 5 6];

-->Y=[1;1];

-->X=A\Y
X =
- 0.5
0.
0.5

-->A*X
ans =
1.
1.

Scllab for very beglnners - 27/33
#*=- 61-)6& )60$3%*01
SorL
1he gsort funcLlon ls used Lo sorL Lhe elemenLs of a vecLor ln ascendlng or descendlng order.
-->v=[2,6,9,6,-4,0,2]
v =
2. 6. 9. 6. - 4. 0. 2.

--> gsort(v,"g","i")
ans =
- 4. 0. 2. 2. 6. 6. 9.

--> gsort(v)
ans =
9. 6. 6. 2. 2. 0. - 4.

LengLh
1he length funcLlon reLurns Lhe number of coordlnaLes for a vecLor. 1he size funcLlon reLurns
Lhe dlmenslons (rows, columns) for a maLrlx.
-->U=[1:10]
U =
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

-->length(U)
ans =
10.

-->m=[1 2 3;4 5 6];

-->size(U)
ans =
2. 3.


Scllab for very beglnners - 28/33
Sum and producL
1he sum and prod funcLlons respecLlvely calculaLe Lhe sum and Lhe producL of Lhelr argumenL
elemenLs.
-->U=[1:10];

-->sum(U)
ans =
55.

-->prod(U)
ans =
3628800.

unlque
1he unique funcLlon keeps only once Lhe elemenLs of a vecLor (even lf Lhey are repeaLed
several Llmes) and sorLs Lhem ln ascendlng order.
-->v=[2,6,9,6,-4,0,2]
v =
2. 6. 9. 6. - 4. 0. 2.

-->unique(v)
ans =
- 4. 0. 2. 6. 9.

llnd
1he find funcLlon searches for elemenLs ln a vecLor or a maLrlx and reLurns a vecLor conLalnlng
Lhe correspondlng lndlces.
1o flnd all Lhe elemenLs of Lhe vecLor ! smaller Lhan 3:
-->w=[1,5,3,8,14,7,3,2,12,6]; find(w<5)
ans =
1. 3. 7. 8.

1he resulLlng vecLor (1,3,7,8) lndlcaLes LhaL elemenLs !
!
! !
!
! !
!
and !
!
are smaller Lhan 3.

Scllab for very beglnners - 29/33
1o flnd all Lhe elemenLs of Lhe vecLor ! equal Lo 3:
-->w=[1,5,3,8,14,7,3,2,12,6]; find(w==3)
ans =
3. 7.

1he resulLlng vecLor (3,7) lndlcaLes LhaL elemenLs !
!
and !
!
are equal Lo 3.

C$$6+'$. $*=963'3%*0
7*=963'3%*0
numbers have an absoluLe value beLween abouL 2.210
-308
and 1.810
+308
.
1he number %eps equals Lo 2.220446049D-16 glves Lhe smallesL relaLlve preclslon LhaL can
be obLalned ln compuLaLlons, whlch Lherefore glves abouL 16 declmal dlglLs.

FS'=9&- :\ 7*=963'3%*0 *) 1%0N][
-->sin(%pi)
ans =
1.225D-16

1he value of !"# ! above ls noL 0, buL lL ls consldered as zero. lndeed, compared Lo Lhe
maxlmum value of Lhe slne funcLlon (l.e. 1), lL ls equal Lo 0 wlLh a value less Lhan %eps.

FS'=9&- ?\ 2-13%0/ %) 38- 3+%'0/&- >%38 1%5-1 !O : -3 ? %1 ' +%/83!'0/&-5 3+%'0/&-\
-->a=sqrt(3)
a =
1.7320508

-->b=1
b =
1.

-->c=2
c =
2.

-->a^2+b^2==c^2
ans =
F
1he program responds false
because Lhe value of a2 + b 2 ls approxlmaLe

Scllab for very beglnners - 30/33
-->abs(a^2+b^2-c^2)<%eps
ans =
F
1he program responds false because absoluLe
preclslon ls called for
-->abs(a^2+b^2-c^2)/c^2<%eps
ans =
T
1he program responds Lrue because relaLlve
preclslon ls called for

X%19&'.
8esulLs are dlsplayed, by defaulL, wlLh 10 characLers, lncludlng Lhe declmal polnL and Lhe slgn.
1he format funcLlon ls used Lo dlsplay more dlglLs. 1o dlsplay 20 dlglLs, Lype format(20).
8econslderlng ! ! !:
-->a^2
ans =
3.
Pere Lhere are 7 declmal places, and we do noL see
Lhe error.
-->format(20)

-->a^2
ans =
2.99999999999999956
Pere Lhere are 17 declmal places, and we can see
Lhe error


#*&,%0/ 5%))-+-03%'& -W6'3%*01
1o flnd Lhe soluLlons of an expllclL sysLem of dlfferenLlal equaLlons, slmply reduce Lo dlfferenLlal
equaLlons of order 1.
!
!
! ! ! !! ! !
! !
!
! !
!
ln whlch !
!
and ! represenL Llme and !
!
and !!!! are vecLors,
Lhen apply Lhe ode funcLlon: y=ode(y0,L0,L,f), wlLh:
y0: lnlLlal condlLlon, vecLor of dlmenslon !,
t0: lnlLlal Llme,
t: vecLor of dlmenslon 1 correspondlng Lo Lhe Llmes ln whlch Lhe soluLlon ls compuLed.
1hls vecLor musL begln wlLh t0.
f: funcLlon deflnlng Lhe sysLem under Lhe form:
function yprim=f(t,y)
yprim(1)=...
yprim(2)=...
....
yprim(n)=...
endfunction

Scllab for very beglnners - 31/33
1he soluLlon y ls a maLrlx of dlmenslon :
!
!
! !
!
! ! !
!
!
!
!
! !
!
! ! !
!
!
! ! !
!
!
! !
!
! ! !
!
!


FS'=9&-\ #*&,%0/ 38- 5%))-+-03%'& -W6'3%*0
!! ! !!"
! ! ! !! !
!
! ! !

1hls equaLlon of order 2 ls reduced Lo a sysLem of Lwo equaLlons of order 1 as deflned by:
! !
!!!!
!!!!
!
!
!!
! !"#$% !
!"#$%!!!
!"#$%!!!
!
!!
!!
and
!"#$% ! ! !
!"#$% ! ! !!!!!!!


CommenL Scllab LdlLor
We deflne Lhe funcLlon reLurnlng ouLpuL vecLor y'
from lnpuL varlables L and y (y ls a vecLor).
We deflne Lhe values of L for ploLLlng.
(Lhe solver chooses lLself Lhe good values of L for
Lhe lnLernal compuLaLlon of Lhe soluLlon).
We deflne Lhe lnlLlal condlLlons.
We execuLe ode.
We ploL Lhe lnLegral curve of y wlLh respecL Lo L.
function yprim=f(t,y)
yprim(1)=y(2);
yprim(2)=-4*y(1) ;
endfunction
t0=0; tmax=5;
t=t0:0.05:tmax;
y0=3; yprim0=0;
y=ode([y0;yprim0],t0,t,f);
clf; plot(t,y(1,:))

!
n "T
Scllab for very beglnners - 32/33
78'93-+ A ; B1-)6& #$%&'( )60$3%*01


C0'&.1%1
sqrt(x) reLurns Lhe square rooL of ! wlLh ! real poslLlve or zero, and Lhe complex
rooL of real poslLlve parL oLherwlse.
log(x) reLurns Lhe naLural logarlLhm of x wlLh x real or complex number.
exp(x) reLurns Lhe exponenLlal of ! wlLh ! real or complex number.
abs(x) reLurns Lhe absoluLe value of ! real (or Lhe module lf ! ls complex).
int(x) reLurns Lhe LruncaLlon of ! real (Lhe lnLeger before Lhe declmal).
floor(x) reLurns Lhe lnLeger parL of ! real (Lhe lnLeger ! for whlch ! ! ! ! ! ! !).
ceil(x) for ! real reLurns Lhe lnLeger ! for whlch ! ! ! ! ! ! !.


@+*('(%&%3. '05 13'3%13%$1
factorial(n) reLurns Lhe facLorlal of n wlLh n poslLlve or zero lnLeger.
grand(1,p,"uin",m,n) reLurns a vecLor of p random lnLeger sequences Laken
beLween m and n wlLh p poslLlve lnLeger, m and n lnLegers and ! ! !.
grand(1,p,"unf",a,b) reLurns a vecLor of p random real sequences Laken
beLween a and b wlLh p poslLlve lnLeger, a and b real and ! ! !.
sum(n) reLurns Lhe sum of Lhe values of vecLor ! (used Lo calculaLe a LoLal).
cumsum(n) reLurns Lhe vecLor of lncreaslng cumulaLlve values of vecLor ! (used Lo
calculaLe Lhe lncreaslng cumulaLlve numbers).
length(v) reLurns Lhe number of coordlnaLes of vecLor !.
gsort(v) reLurns Lhe vecLor of numbers or sLrlngs ! sorLed ln descendlng order.
gsort(v,"g","i") reLurns Lhe vecLor of numbers or sLrlngs ! sorLed ln ascendlng
order.
mean(v) reLurns Lhe average of Lhe vecLor of numbers !.
stdev(v) reLurns Lhe sLandard devlaLlon of numbers ! vecLor.
bar(v,n,couleur) draws Lhe bar graph wlLh ! as x-coordlnaLe, ! as ?-coordlnaLe,
! and ! belng same slze llne vecLors. 8y defaulL, bar(n) draws Lhe bar graph of ! ln
blue wlLh 1,2,3. as x-coordlnaLes.
bar(v,[n1,n2]) draws a double bar graph wlLh ! as x-coordlnaLe, n1 as ?-
coordlnaLe ln blue and n2 as ?-coordlnaLe ln green, wlLh !, n1 and n2 belng same slze
llne vecLors.
rand(n,p) wlLh ! and ! poslLlve lnLegers, reLurns a maLrlx !!! of numbers randomly
Laken beLween 0 and 1.
rand() reLurns a real number randomly Laken beLween 0 and 1.
floor(x) reLurns Lhe lnLeger parL of ! real number. ln parLlcular, lf ! ls real beLween
0 and 1, floor(rand()+p) wlll be 1 wlLh ! probablllLy and 0 wlLh ! ! ! probablllLy.



Scllab for very beglnners - 33/33
X%19&'. '05 9&*3
clf means clear flgure and clears Lhe currenL flgure on Lhe graphlcs wlndow.
plot allows Lo draw curves and scaLLer ploLs ln 2 dlmenslons.
linspace(a,b,n), wlLh ! and ! real and ! lnLeger, deflnes a vecLor of ! values
regularly spaced beLween ! and !.
scf allows Lo open or Lo selecL oLher graphlcs wlndows Lhan Lhe currenL one.
surf allows 3-u surface ploLs.
bar(X,Y) ln whlch x and ? are vecLors, draws Lhe bar graph of Lhe serles of values for
x whlch has for numbers Lhe values of ?.
plot(X,Y,"*") draws Lhe scaLLer ploL of coordlnaLes (x(l),?(l)) as sLars. 1he color can
be speclfled.
plot(Y,"+") draws Lhe scaLLer ploL of coordlnaLes (l,?(l)) as cross.
disp("Sentence") dlsplays whaL ls wrlLLen ln double quoLes.
disp(A) ln whlch A ls a maLrlx of numbers, dlsplays Lhe Lable of Lhe values of A.
disp("Sentence"+string(x)) dlsplays Lhe senLence and Lhe value of number !.
xclick reLurns Lhe coordlnaLes of Lhe polnL cllcked ln a graphlcs wlndow.

B3%&%3%-1
unique(v) reLurns Lhe vecLor ! wlLh a unlque occurrence of lLs repeaLed
componenLs.
sum(v) reLurns Lhe sum of all Lhe elemenLs of Lhe vecLor or Lhe maLrlx !.
prod(v) reLurns Lhe producL of all Lhe elemenLs of Lhe vecLor or Lhe maLrlx !.
find(<test about v>) reLurns Lhe lndlces of Lhe elemenLs of vecLor ! saLlsfylng
Lhe LesL.
disp(x,y,) dlsplays Lhe values of lLs argumenLs ln Lhe console.
string(x) converLs number ! Lo a sLrlng.
format(n) ln whlch ! ls an lnLeger greaLer Lhan or equal Lo 2, seLs Lhe dlsplay Lo !
characLers, lncludlng Lhe slgn and Lhe declmal doL.
zeros(n,p) deflnes a !!!

maLrlx LhaL only conLalns zeros.
feval(x,y,f) ln whlch ! and ! are respecLlvely vecLors of slze ! and !, deflnes Lhe
maLrlx !!! whose elemenL !!! !! ls !!! ! ! ! ! !.
help funcLlon opens Lhe help browser on Lhe rlghL funcLlon page.
tic sLarLs a clock.
toc sLops Lhe clock.

You might also like