Sie sind auf Seite 1von 9

Us|ng Mat|ab

O 1o asslgn a varlable a number Lype a leLLer followed by Lhe equal slgn and Lhen Lhe deslred
value of Lhe varlable lor example x2 wlll asslgn Lhe value 2 Lo Lhe varlable x and xx/2 + 1/x
wlll asslgn a new value Lo x (ln Lhls case 13)
O ou can use Lhe up key Lo go back Lo Lhe prevlous demand
O qulck way Lo geL help abouL a maLlab command ls uslng Lhe help command lor example help
______"
O ou can also access Lhe help menu by cllcklng Lhe blue clrcle wlLh a ?" Lo Lhe lefL of currenL
folder
O lor more speclflc lnformaLlon you can use Lhe doc command lor example doc _____"
O ,flles are [usL plaln LexL flles conLalnlng ,1L commands n ,flle has m exLenslon When
an ,flle ls execuLed all Lhe commands wlLhln Lhe ,flle are execuLed
O 1o download an ,flle lefL cllck Lhe name of Lhe ,flle and choose Lhe opLlon Lo save Lhe flle ln
your accounL or on your compuLer
O whaL" llsLs Lhe ,flles ln Lhe currenL worklng dlrecLory
O pwd" glves Lhe resenL (currenL) orklng lrecLory
O 1he are several ways of creaLlng a new ,flle uslng Lhe ,1L edlLor 1hese lnclude
Cllck on Lhe - MI|| lcon Lhe blank page lmmedlaLely under Lhe I|| menu
lLem aL Lhe Lop lefL of Lhe ,1L wlndows
use Lhe I|| menu Lhe - lLem Lhen selecL Lhe |ank MI|| opLlon
ln Lhe ,1L command wlndow Lype edlL fllenamem
O 1he are several ways of openlng an exlsLlng ,flle for edlLlng wlLh Lhe ,1L edlLor
lncludlng
Cllck on Lhe n lcon Lhe yellow open folder [usL under Lhe L|t menu lLem aL
Lhe Lop lefL of Lhe ,1L wlndows
use Lhe I|| menu Lhe n lLem Lhen selecL Lhe approprlaLe flle
ln Lhe ,1L command wlndow Lype edlL fllenamem lf Lhe flle fllenamem
already exlsLs lL wlll be opened

|thmt|c
O rlLhmeLlc operaLlons lnclude
ddlLlon (+)
SubLracLlon ()
,ulLlpllcaLlon (*)
ulvlslon (/)
owers ()
O 8emember Lo add brackeLs whenever you're unsure of Lhe lnpuL lor example 4/2+1 ls 3
whlle 4/(2+1)13333 and 82/3213333 and 8(2/3)4
O 8emember LhaL operaLlons of Lhe same precedence are evaluaLed from lefL Lo rlghL
12/2/3 ls 12 dlvlded by 2 whlch ls 6 Lhen 6 ls dlvlded by 3 whlch ls 2
O lor very large or small numbers sclenLlflc noLaLlon ls used lor example 16e10
16x1010
O y defaulL ,1L only dlsplays 3 declmal dlglLs 1hls can be changed by uslng Lhe
followlng commands

O oLh l and [ ln ,1L denoLes Lhe square rooL of 1 so lL ls usually a bad ldea Lo asslgn
l or [ Lo anoLher consLanL
O 1o creaLe a complex number you can elLher Lype ln a+b*l (where a and b are real
numbers) or do complex(ab) lor example complex(32)3+2*l
O real(a+b*l) wlll glve Lhe real parL of Lhe complex number a+b*l whlch ls a
O lmaglnary(a+b*l) wlll glve Lhe lmaglnary parL of Lhe complex number a+b*l whlch ls b
O abs(a+b*l) wlll glve Lhe modulus of Lhe complex number a+b*l whlch ls square rooL of
a2 + b2
O angle(a+b*l) wlll glve Lhe argumenL
O 1he command exp(x) ls equlvalenL Lo ex
O poslLlve number dlvlded by zero would glve lnf whlle a negaLlve number dlvlded by
zero would glve lnf
O 0/0 glves nan (noL a number)

O 8emember Lhe followlng


Ia|ab|s
O varlable names cannoL begln wlLh a number lor example 3chem ____ wlll glve an
error expresslon whlle chem3 ____ won'L
O ,1L ls cases senslLlve Lherefore x would noL be equal Lo x
O 8emember you also can'L have spaces for a varlable name 3 chem ____ wlll glve an
error expresslon
O ,1L ls [usL a compuLer program Lherefore lL has llmlLaLlons 1yplng ln eps" wlll
show 22204e016 meanlng LhaL aL mosL 16 declmal dlglLs can be sLored on Lhe compuLer
O 1yplng ln realmax shows 17977e+308 whlch ls Lhe largesL number LhaL can be sLored ln
double preclslon
O 1yplng ln realmln shows 22231e308 whlch ls Lhe smallesL number Lhan can be sLored ln double
preclslon
O uLLlng a afLer a command suppresses Lhe ouLpuL 1hls saves space as maLrlces and oLher
calculaLlons can geL qulLe large
O 1he who" command can be used Lo llsL all Lhe varlable names ln Lhe currenL work space
O 1he whos" command can be used Lo llsL all Lhe varlables ln Lhe currenL workspace wlLh exLra
lnformaLlon on Lhelr slze eLc
O ou can clear a varlable by uslng Lhe clear" command lor example clear x" wlll geL rld of Lhe
asslgned x value

Ictos
O 1o creaLe a row vecLor slmply puL number beLween and have a space/comma
beLween each number lor example 3 6 7 glves a row vecLor wlLh x13 x26 x37
O lf you asslgn a varlable Lo Lhe vecLor such as x367 Lhen Lhe flrsL elemenL of Lhe
vecLor ls glven by x(1) whlch ls 3 Lhe second elemenL ls glven by x(2) whlch ls 6 and so
on noLe LhaL when you do x(2)9 Lhe second elemenL of Lhe vecLor x now becomes a 9
O uolng x(1 3) wlll glve Lhe flrsL and Lhlrd elemenL of Lhe vecLor x
O 1he number of elemenLs ln a vecLor can be found uslng Lhe command numel" lor
example numel(x) wlll glve us Lhe amounL of elemenLs ln Lhe vecLor x 1hls can also be
achleved by uslng Lhe command lengLh" lengLh(x) wlll also glve Lhe amounL of
elemenLs ln x
O 1he colon operaLor as seen ln ab wlll creaLe a row vecLor sLarLlng from a and Lhen
lncreases ln lncremenLs of 1 unLll b ls reached
O 1he colon operaLor as seen ln abc wlll creaLe a row vecLor sLarLlng from a and Lhen
lncreases by b unLll c ls reached lor example 3211 wlll make a row vecLor wlLh values
3 7 9 11 and 3210 wlll make a row vecLor wlLh values 3 7 9
O noLher way Lo do Lhe above ls a+bcd lor example 1+003020 wlll glve a vecLor
wlLh values 1 103 11 2 1hls ls Lhe same as 10032
O 1he command llnspace(a b n) creaLes n equally spaced polnLs beLween a and b lncludlng boLh
a and b lor example llnspace(1210) wlll creaLe 10 equally spaced polnLs lncludlng boLh
end polnLs 1hls produces a vecLor wlLh elemenLs 1 1111 1222 13332 noLe how
Lhe space beLween each value ls


O 1he colon operaLor can be used Lo flnd elemenLs ln a vecLor lor example x(127) wlll glve Lhe
flrsL Lhlrd flfLh and sevenLh elemenL of Lhe vecLor x
O 1he colon operaLor ln x(end2end) glves you Lhe lasL 3 elemenLs ln Lhe vecLor x
O W+v where W abcand vdef wlll glve Lhe vecLor a+db+ec+f
O lf a vecLor a*x1x2x3 wlll glve a new vecLor a*x1a*x2a*x3 where a ls a scale vecLor
mulLlpllcaLlon doesn'L work Lhls way
O ddlng/subLracLlng a scalar ls dlfferenL from sLandard maLhemaLlcs on ,1L lor example 2
+ x1x2x3 would glve Lhe vecLor 2+x12+x22+x3
O SomeLlmes lL ls very useful Lo apply arlLhmeLlc operaLlons Lo each elemenL of a vecLor
(or maLrlx) 1hese elemenL by elemenL operaLlons are
* Lo mulLlply correspondlng elemenLs of Lwo vecLors
/ Lo dlvlde correspondlng elemenLs of Lwo vecLors
Lo Lake powers of each elemenL of a vecLor
O lor example u13 u*u would be undeflned buy u*u ls deflned and would be
1491623 noLe how Lhls ls dlfferenL from sLandard maLhemaLlcs vecLor
mulLlpllcaLlon
O Column vecLors can be by puLLlng a semlcolon beLween each elemenL as shown ln
abc wlll glve Lhe column vecLor
I
I
I

O 1he slze command wlll glve how many rows and how many columns a maLrlx or vecLor
has slze(x) would glve Lhe amounL of rows and columns ln Lhe maLrlx x
O row vecLor can be Lransposed lnLo a column vecLor by uslng Lhe Lranspose operaLor
(') lor example 123'123
O 1he ,1L operaLor when applled Lo a complex vecLor produces Lhe complex con[ugaLe
Lranspose LhaL ls lL boLh Lakes Lhe complex con[ugaLe of each elemenL and Lhe Lranspose of Lhe
vecLor lf you only wanL Lo Lranspose a complex vecLor Lhen use Lhe ,1L funcLlon Lranspose
or Lhe noncon[ugaLe Lranspose operaLor lor example 1+2l 3l 2+2l wlll become a column
vecLor wlLh Lhe flrsL elemenL belng 12l second elemenL belng 3+l and lasL elemenL belng 22l
Iunct|ons
O 1he max command calculaLes Lhe largesL of Lhe glven lnpuLs lor example max(13pl) wlll glve a
resulL of 3
O 1he mln command calculaLes Lhe smallesL value of Lhe glven lnpuLs lor example mln(13pl) wlll
glve a resulL of 1
O ,any of Lhe ,1L commands are modlfled so Lhey work wlLh vecLors as well lor example
sqrL(110) wlll glve an ouLpuL of 1 rooL 2 rooL 3rooL 10
O 1he sum command adds all Lhe elemenLs of a vecLor lor example w1203 Lhen
sum(w)13+23+203
O 1he command funcLlon_name [(varlable_name) maLlab_expresslon can be used Lo
deLermlne Lhe value of a funcLlon aL a cerLaln polnL lor example leL y [(x) sln(x)/x Lhen y(2)
would be sln(2)/2
O e careful whaL lnpuLs you puL ln because order maLLers lor example leL y [(x k)
sln(k*pl*x)/x Lhen y(12) would glve x Lhe value of 1 and k Lhe value of 2
O 8emember LhaL you can use * / eLc so Lhe funcLlon also works wlLh vecLors
O We can use fzero Lo flnd a zero of a funcLlon lor example leL func [(z) sln(4*z) log(z) Lhen
xfzero(func2) would glve Lhe closesL zero Lo 2

9|ott|ng
O ou can ploL a graph uslng ploL(xy) lor example you can do xllnspace(01401) (Lhls means 401
equally spaced polnLs are Laken along Lhe x axls) and ysln(2*pl*x) and Lhen do ploL(xy) Lo ploL
Lhe curve uslng Lhe 401 polnLs from 0 Lo 1
O Lvery ploL should have
LlLle whlch can be creaLed wlLh Lhe LlLle command
xls labels whlch can be creaLed wlLh Lhe xlabel and ylabel commands
O lor example LlLle('_____') wlll glve Lhe LlLle ______ aL Lhe Lop of Lhe graph
O xlabel(x) wlll label Lhe x axls x ylabel('y') wlll label Lhe y axls y
O lL ls easy Lo change Lhe llne Lype by addlng one of Lhe followlng sLrlngs afLer Lhe Lwo vecLors Lo
be ploLLed (solld llne) (dashed llne) (doLLed llne) or (dashdoLs) lor example
ploL(xy'') wlll glve a graph wlLh a dashed llne
O ou can Lurn add a grld by Lhe command grld on"
O ou can graph more Lhan one curve aL once wlLh Lhe ploL command lor example leL x
llnspace(0 1 401) y1 sln(2*pl*x) y2 cos(2*pl*x) and Lhen Lyplng ploL(x y1 x y2) wlll glve
you Lhe graph sln(2*pl*x) and cos(2*pl*x)
O 1he prevlous can also be done by dolng ploL(xy1) hold on ploL(xy2) hold off
O When Lhere are mulLlple graphs lL ls a good ldea Lo add a legend lor example legend(sLrlng1
sLrlng2) wlll glve Lhe flrsL graph a name of sLrlng1 and Lhe second graph a name of sLrlng2
O 1he subploL command can creaLe several lndlvldual ploLs aL once lor example subploL(mnk)
creaLes a m x n amounL of subploLs and poslLlons you aL Lhe kLh one
O ou can change Lhe llmlLs of Lhe x axls and Lhe y axls by uslng Lhe command xllm and yllm lor
example xllm(1 3) wlll make Lhe x axls sLarL from 1 and end aL 3
O usually Lhe x axls ls noL aL a same scale as Lhe y axls 1o make Lhem equal use Lhe command
axls equal"
O ou can also ploL parameLrlc curves lor example leL Lllnspace(02*pl401) xsln(L) ycos(L)
ploL (xy) wlll glve a clrcle
O ,1L draws a ploL ln Lhe currenL flgure wlndow llgure wlndows are labelled 1 2 3
1he command flgure" creaLes a new flgure wlndow lLernaLlvely Lhe command
flgure(k) where k ls a poslLlve lnLeger opens flgure wlndow k lf lL already exlsLs or
creaLes flgure wlndow k lf lL does noL exlsL
O olar graphs can also be ploLLed on ,1L by uslng polar(LheLar) lor example leL
Lllnspace(02*pl401) and r1+cos(LheLa) Lhen polar(LheLar) wlll make Lhe polar curve
descrlbed by Lhese polar coordlnaLes
O hlsL(ym) can be used Lo make a hlsLogram of m sublnLervals or blns" lor example leL
yrandn(11000) (creaLes a vecLor of 1000 samples) and hlsL(y20) 1hen a hlsLogram wll 20 sub
lnLervals wlll spread Lhese 1000 samples ouL accordlng Lo Lhelr values
Mat|cs
O ou can creaLe a maLrlx by uslng square brackeLs and enLerlng semlcolon Lo enLer a new llne
lor example123436 wlll creaLe Lhe maLrlx



O ou can [usL 2 maLrlces LogeLher uslng square brackeLs lor example lf r113 and r246
Lhen r1r2 would also glve



O ou can also [oln columns LogeLher lor example lf c113 and c224 Lhen c1 c2 would glve




O 1he command zeros(mn)wlll creaLe a maLrlx wlLh m rows and n columns wlLh all elemenLs 0
O 1he command eye(n) creaLes a n by n ldenLlLy maLrlx
O 1he command rand(mn) creaLes a maLrlx wlLh m rows and n columns wlLh random elemenLs
beLween 0 and 1
O ou can change Lhe value of an elemenL by dolng (mn) x where ls Lhe name of Lhe maLrlx
1hls command changes Lhe elemenL ln Lhe mLh row and Lhe nLh column Lo Lhe value of x
O (2) would glve Lhe second row of Lhe maLrlx and (3) would glve Lhe Lhlrd column of Lhe
maLrlx
O (1 1 3) would glve Lhe flrsL and Lhlrd elemenL of row one of Lhe maLrlx
O (1 3 1) would glve Lhe flrsL and Lhlrd elemenL of column one of Lhe maLrlx
O (1 21 3) wlll glve Lhe elemenLs ln row 1 and row 2 and column 1 and column 3 of Lhe maLrlx

O lf and are noL scalars Lhen * ls on|y deflned lf Lhe number of columns ln ls equal Lo Lhe
number of rows ln lf ls an m by n maLrlx and ls an n by p maLrlx Lhen C * ls an m by p
maLrlx
O !usL as * represenLs maLrlx mulLlpllcaLlon represenLs Lhe mulLlpllcaLlon of maLrlces LogeLher
1hus 2 * and 3 ** eLc are only deflned for square maLrlces
O ,1L provldes Lhe operaLors * for elemenL by elemenL mulLlpllcaLlon / for elemenL by
elemenL dlvlslon and for elemenL by elemenL powers
O lf ls an n by n nons|ngu|a maLrlx (LhaL ls Lhe deLermlnanL of ls nonzero) Lhen Lhe sysLem
of llnear equaLlons x b has a unlque soluLlon x
1
b ln 8
n
for any rlghLhandslde vecLor b
ln 8
n

O lf deL() lsn'L zero Lhen xb wlll glve Lhe same resulL as xlnv()*b
O lf deL() ls zero Lhen xb wlll usually glve an answer wlLh nan and lnf

Das könnte Ihnen auch gefallen