Sie sind auf Seite 1von 60

A BRIEF LIST OF MATLAB COMMANDS

Some Basic Commands (Note command syntax is case-sensitive!

mat!a" +'it exit (#o (#os c!ea%

!oads t#e $%o&%am mat!a" into yo'% (o%)s$ace* +'its mat!a", %et'%nin& yo' to t#e o$e%atin& system* same as +'it* !ists a!! o- t#e va%ia"!es in yo'% mat!a" (o%)s$ace* !ist t#e va%ia"!es and desc%i"es t#ei% mat%ix si.e* de!etes a!! mat%ices -%om active (o%)s$ace*

c!ea% x de!etes t#e mat%ix x -%om active (o%)s$ace* *** t#e e!!i$sis de-inin& a !ine contin'ation is t#%ee s'ccessive $e%iods* save saves a!! t#e mat%ices de-ined in t#e c'%%ent session into t#e -i!e, mat!a"*mat* !oad !oads contents o- mat!a"*mat into c'%%ent (o%)s$ace*

save -i!ename saves t#e contents o- (o%)s$ace into -i!ename*mat save -i!ename x y . saves t#e mat%ices x, y and . into t#e -i!e tit!ed -i!ename*mat* !oad -i!ename !oads t#e contents o- -i!ename into c'%%ent (o%)s$ace/ t#e -i!e can "e a "ina%y (*mat -i!e o% an ASCII -i!e* ! t#e ! $%ecedin& any 'nix command ca'ses t#e 'nix

command to "e exec'ted -%om mat!a"*

Commands 0se-'! in 1!ottin&*

$!ot(x,y c%eates an Ca%tesian $!ot o- t#e vecto%s x 2 y* $!ot(y c%eates a $!ot o- y vs* t#e n'me%ica! va!'es o- t#e e!ements in t#e y-vecto%* semi!o&x(x,y $!ots !o&(x vs y* semi!o&y(x,y $!ots x vs !o&(y !o&!o&(x,y &%id $!ots !o&(x vs !o&(y *

c%eates a &%id on t#e &%a$#ics $!ot*

tit!e(3text3 $!aces a tit!e at to$ o- &%a$#ics $!ot* x!a"e!(3text3 (%ites 3text3 "eneat# t#e x-axis o- a $!ot* y!a"e!(3text3 (%ites 3text3 "eside t#e y-axis o- a $!ot* text(x,y,3text3 (%ites 3text3 at t#e !ocation (x,y *

text(x,y,3text3,3sc3 (%ites 3text3 at $oint x,y ass'min& !o(e% !e-t co%ne% is (4,4 and '$$e% %i&#t co%ne% is (5,5 * &text(3text3 (%ites text acco%din& to $!acement o- mo'se #o!d on maintains t#e c'%%ent $!ot in t#e &%a$#ics (indo( (#i!e exec'tin& s'"se+'ent $!ottin& #o!d o-- t'%ns OFF t#e 3#o!d on3 o$tion* $o!a%(t#eta,% c%eates a $o!a% $!ot o- t#e vecto%s % 2 t#eta (#e%e t#eta is in %adians* commands*

"a%(x

c%eates a "a% &%a$# o- t#e vecto% x* (Note a!so t#e command stai%s(y *

"a%(x,y c%eates a "a%-&%a$# o- t#e e!ements o- t#e vecto% y, !ocatin& t#e "a%s acco%din& to t#e vecto% e!ements o- 3x3* (Note a!so t#e command stai%s(x,y * #ist(x c%eates a #isto&%am* T#is di--e%s -%om t#e "a%&%a$# in t#at -%e+'ency is $!otted on t#e ve%tica! axis* mes#(. c%eates a s'%-ace in xy. s$ace (#e%e . is a mat%ix

o- t#e va!'es o- t#e -'nction .(x,y * . can "e inte%$%eted to "e t#e #ei&#t o- t#e s'%-ace a"ove some xy %e-e%ence $!ane* s'%-(. simi!a% to mes#(. , on!y s'%-ace e!ements de$ict t#e s'%-ace %at#e% t#an a mes# &%id* conto'%(. d%a(s a conto'% ma$ in xy s$ace o- t#e -'nction

o% s'%-ace .* mes#c(. d%a(s t#e s'%-ace . (it# a conto'% $!ot "eneat# it* mes#&%id 67,89:mes#&%id(x,y t%ans-o%ms t#e domain s$eci-ied "y vecto%s x and y into a%%ays 7 and 8 t#at can "e 'sed in eva!'atin& -'nctions -o% ;D mes#<s'%- $!ots* $%int sends t#e contents o- &%a$#ics (indo( to $%inte%* (%ites t#e contents o- c'%%ent

$%int -i!ename -d$s

&%a$#ics to 3-i!ename3 in $ostsc%i$t -o%mat*

E+'ation Fittin&

$o!y-it(x,y,n %et'%ns t#e coe--icients o- t#e n-de&%ee $o!ynomia! -o% t#e vecto%s x and y* n m'st "e at !east 5 !a%&e% t#an t#e !en&t# o- t#e vecto%s x and y* I- n=5 : !en&t#(x t#e %es'!t is an inte%$o!atin& $o!ynomia!* In=5 > !en&t#(x t#e %es'!t is a !east-s+'a%es $o!ynomia! -it* T#e coe--icients a%e sto%ed in o%de% (it# t#at ot#e #i&#est o%de% te%m -i%st and t#e !o(est o%de% !ast* $o!yva!(c,x ca!c'!ates t#e va!'es o- t#e $o!ynomia! (#ose

coe--icients a%e sto%ed in c, ca!c'!atin& -o% eve%y va!'e o- t#e vecto% x*

Data Ana!ysis Commands

max(x

%et'%ns t#e maxim'm va!'e o- t#e e!ements in a

vecto% o% i- x is a mat%ix, %et'%ns a %o( vecto% (#ose e!ements a%e t#e maxim'm va!'es -%om eac# %es$ective co!'mn o- t#e mat%ix* min (x mean(x %et'%ns t#e minim'm o- x (see max(x -o% detai!s * %et'%ns t#e mean va!'e o- t#e e!ements o- a vecto%

o% i- x is a mat%ix, %et'%ns a %o( vecto% (#ose e!ements a%e t#e mean va!'e o- t#e e!ements -%om eac# co!'mn o- t#e mat%ix*

median(x same as mean(x , on!y %et'%ns t#e median va!'e* s'm(x %et'%ns t#e s'm o- t#e e!ements o- a vecto% o% i- x is a mat%ix, %et'%ns t#e s'm o- t#e e!ements -%om eac# %es$ective co!'mn o- t#e mat%ix* $%od(x same as s'm(x , on!y %et'%ns t#e $%od'ct o-

e!ements* std(x %et'%ns t#e standa%d deviation o- t#e e!ements o- a vecto% o% i- x is a mat%ix, a %o( vecto% (#ose e!ements a%e t#e standa%d deviations o- eac# co!'mn o- t#e mat%ix* so%t(x so%ts t#e va!'es in t#e vecto% x o% t#e co!'mns oa mat%ix and $!aces t#em in ascendin& o%de%* Note t#at t#is command (i!! dest%oy any association t#at may exist "et(een t#e e!ements in a %o( o- mat%ix x* #ist(x $!ots a #isto&%am o- t#e e!ements o- vecto%, x* Ten "ins a%e sca!ed "ased on t#e max and min va!'es* #ist(x,n $!ots a #isto&%am (it# 3n3 "ins sca!ed "et(een t#e max and min va!'es o- t#e e!ements* #ist((x(?,@ $!ots a #isto&%am o- t#e e!ements o- t#e @nd

co!'mn -%om t#e mat%ix x* -!i$!%(x %eve%ses t#e o%de% o- a vecto%* I- x is a mat%ix, t#is %eve%se t#e o%de% o- t#e co!'mns in t#e mat%ix* -!i$'d(x %eve%ses t#e o%de% o- a mat%ix in t#e sense oexc#an&in& o% %eve%sin& t#e o%de% o- t#e mat%ix %o(s* T#is (i!! not %eve%se a %o( vecto%!

%es#a$e(A,m,n

%es#a$es t#e mat%ix A into an mxn mat%ix

-%om e!ement (5,5 (o%)in& co!'mn-(ise*

S1ECIAL MATRICES

.e%os(n c%eates an nxn mat%ix (#ose e!ements a%e .e%o* .e%os(m,n ones(n c%eates a m-%o(, n-co!'mn mat%ix o- .e%os*

c%eates a n x n s+'a%e mat%ix (#ose e!ements a%e 53s

ones(m,n 3 c%eates a mxn mat%ix (#ose e!ements a%e 53s* ones(A c%eates an m x n mat%ix o- 53s, (#e%e m and n a%e

"ased on t#e si.e o- an existin& mat%ix, A* .e%os(A c%eates an mxn mat%ix o- 43s, (#e%e m and n a%e "ased on t#e si.e o- t#e existin& mat%ix, A* eye(n c%eates t#e nxn identity mat%ix (it# 53s on t#e dia&ona!*

Misce!!aneo's Commands

!en&t#(x %et'%ns t#e n'm"e% e!ements in a vecto%* si.e(x %and %andn %et'%ns t#e si.e m(%o(s and n(co!'mns o- mat%ix x* %et'%ns a %andom n'm"e% "et(een 4 and 5* %et'%ns a %andom n'm"e% se!ected -%om a no%ma! dist%i"'tion (it# a mean o- 4 and va%iance o- 5* %and(A %et'%ns a mat%ix o- si.e A o- %andom n'm"e%s*

ALAEBRAIC O1ERATIONS IN MATLAB

Sca!a% Ca!c'!ations* = B < D E addition s'"t%action m'!ti$!ication %i&#t division (a<" means a C " !e-t division (aD" means " C a ex$onentiation

T#e $%ecedence o% o%de% o- t#e ca!c'!ations inc!'ded in a sin&!e !ine o- code -o!!o(s t#e "e!o( o%de%? 1%ecedence 5 @ O$e%ation

$a%ent#eses ex$onentiation, !e-t to %i&#t

; F

m'!ti$!ication and division, !e-t %i&#t addition and s'"t%action, !e-t %i&#t

MATRI7 ALAEBRA In mat%ix m'!ti$!ication, t#e e!ements o- t#e $%od'ct, C, ot(o mat%ices ABB is ca!c'!ated -%om

CiG : H (Ai) B B)G

Is'mmation ove% t#e do'"!e index )J

To -o%m t#is s'm, t#e n'm"e% o- co!'mns o- t#e -i%st o% !e-t mat%ix (A m'st "e e+'a! to t#e n'm"e% o- %o(s in t#e second o% %i&#t mat%ix (B * T#e %es'!tin& $%od'ct, mat%ix C, #as an o%de% -o% (#ic# t#e n'm"e% o- %o(s e+'a!s t#e n'm"e% o- %o(s o- t#e -i%st (!e-t mat%ix (A and t#e $%od'ct (C #as a n'm"e% o- co!'mns e+'a! to t#e n'm"e% o- co!'mns in t#e second (%i&#t mat%ix (B * It is c!ea% t#at ABB IS NOT NECESSARIL8 EK0AL TO BBA!

T#e 1ROD0CT OF A SCALAR AND A MATRI7 is a mat%ix in (#ic# eve%y e!ement o- t#e mat%ix #as "een m'!ti$!ied "y t#e sca!a%*

ARRA8 1ROD0CTS

Sometimes it is desi%ed to sim$!y m'!ti$!y o% divide eac# e!ement o- an mat%ix "y t#e co%%es$ondin& e!ement o- anot#e%

mat%ix* T#ese a%e ca!!ed 3a%%ay o$e%ationsL in 3mat!a"3* A%%ay o% e!ement-"y-e!ement o$e%ations a%e exec'ted (#en t#e o$e%ato% is $%eceded "y a 3*3 ($e%iod * T#'s

a *B "

m'!ti$!ies eac# e!ement o- a "y t#e %es$ective e!ement o- "

a *< "

divides eac# e!ement o- a "y t#e %es$ective e!ement o- "

a *D "

divides eac# e!ement o- " "y t#e %es$ective e!ement o- a

a *E "

%aise eac# e!ement o- a "y t#e %es$ective " e!ement

TRANS1OSE OF A MATRI7

x3

T#e t%ans$ose o- a mat%ix is o"tained "y inte%c#an&in& t#e %o(s and co!'mns* T#e 3mat!a"3 o$e%ato% t#at c%eates t#e t%ans$ose is t#e sin&!e +'otation ma%), 3*

INNER 1ROD0CT OF TMO NECTORS

T#e inne% $%od'ct o- t(o %o( vecto%s A5 and A@ is A5BA@3* T#e inne% $%od'ct o- t(o co!'mn vecto%s O and P is O3BP*

O0TER 1ROD0CT OF TMO NECTORS

I- t(o %o( vecto%s exist, A5 and A@, t#e o'te% $%od'ct is sim$!y

A53 B A@

INote A53 is nx5 and A@ is 5xnJ

and t#e %es'!t is a s+'a%e mat%ix in cont%ast to t#e sca!a% %es'!t -o% t#e inne% $%od'ct* DON3T CONF0SE TOE O0TER 1ROD0CT MITO TOE NECTOR 1ROD0CT IN MECOANICS! I- t#e t(o vecto%s a%e co!'mn vecto%s, t#e o'te% $%od'ct m'st "e -o%med "y t#e $%od'ct o- one vecto% times t#e t%ans$ose o- t#e second!

SOL0TION TO SIM0LTANEO0S EK0ATIONS

0sin& t#e Mat%ix Inve%se

inv(a

%et'%ns t#e inve%se o- t#e mat%ix a* I- ax:" is a mat%ix e+'ation and a is t#e coe--icient mat%ix, t#e so!'tion x is x:inv(a B"*

0sin& Bac) S'"stit'tion

aD"

%et'%ns a co!'mn vecto% so!'tion -o% t#e mat%ix e+'ation ax:" (#e%e a is a coe--icient mat%ix*

"<a

%et'%ns a %o( vecto% so!'tion -o% t#e mat%ix e+'ation xa:" (#e%e a is a coe--icient mat%ix*

Some "asic commands yo' (i!! need?

mat!a" +'it exit (#o (#os

!oads t#e $%o&%am mat!a" into yo'% (o%)s$ace +'its mat!a", %et'%nin& yo' to t#e o$e%atin& system same as +'it !ists a!! o- t#e va%ia"!es in yo'% mat!a" (o%)s$ace !ist t#e va%ia"!es and desc%i"es t#ei% mat%ix si.e

NOTE - M#en 'sin& t#e (o%)stations, c!ic)in& on 01 ARROM (i!! %eca!! $%evio's commands* I- yo' ma)e a mista)e, t#e DELETE )ey OR t#e "ac)s$ace )ey may "e 'sed to co%%ect t#e e%%o%/ #o(eve%, one ot#ese t(o )eys may "e ino$e%a"!e on $a%tic'!a% systems*

3mat!a"3 'ses va%ia"!es t#at a%e de-ined to "e mat%ices* A mat%ix is a co!!ection o- n'me%ica! va!'es t#at a%e o%&ani.ed into a s$eci-ic con-i&'%ation o- %o(s and co!'mns* T#e n'm"e% o- %o(s and co!'mns can "e any n'm"e%, -o% exam$!e, ; %o(s and F co!'mns de-ine a ; x F mat%ix (#ic# #as 5@ e!ements in tota!* A sca!a% is %e$%esented "y a 5 x 5 mat%ix in mat!a"* A vecto% o- n dimensions

o% e!ements can "e %e$%esented "y a n x 5 mat%ix, in (#ic# case it is ca!!ed a co!'mn vecto%, o% a vecto% can "e %e$%esented "y a 5 x n mat%ix, in (#ic# case it is ca!!ed a %o( vecto% o- n e!ements* T#e mat%ix name can "e any &%o'$ o- !ette%s and n'm"e%s '$ to 5Q, "'t a!(ays "e&innin& (it# a !ette%* T#'s 3x53 can "e a va%ia"!e name, "'t 35x3 is i!!e&a!* 3s'$e%ca!a-%a&i!esticex$ea!!adotio's3 can "e a va%ia"!e name/ #o(eve%, on!y t#e -i%st 5Q c#a%acte%s (i!! "e sto%ed! 0nde%stand t#at 3mat!a"3 is Lcase sensitiveL, t#at is, it t%eats t#e name 3C3 and 3c3 as t(o di--e%ent va%ia"!es* Simi!a%!y, 3MID3 and 3Mid3 a%e t%eated as t(o di--e%ent va%ia"!es* Oe%e a%e exam$!es o- mat%ices t#at co'!d "e de-ined in 3mat!a"3* Note t#at t#e set o- n'me%ica! va!'es o% e!ements o- t#e mat%ix a%e "o'nded "y "%ac)ets ******6 9*

c : R*SS o% c : 6R*SS9

c is a sca!a% o%

a 5 x 5 mat%ix

x : 6 ;*R, ;;*@@, @F*R 9

x is a %o( vecto% o%

5 x ; mat%ix

x5 : 6 @ R ;

x5 is co!'mn vecto% o% F x 5 mat%ix

-59

A:65 @ F @ -@ @ 4 ; R R F Q9

A is a F x ; mat%ix

An individ'a! e!ement o- a mat%ix can "e s$eci-ied (it# t#e notation A(i,G o% Ai,G -o% t#e &ene%a!i.ed e!ement, o% "y A(F,5 :R -o% a s$eci-ic e!ement*

M#en 3mat!a"3 $%ints a mat%ix on t#e monito%, it (i!! "e o%&ani.ed acco%din& to t#e si.e s$eci-ication o- t#e mat%ix, (it# eac# %o( a$$ea%in& on a 'ni+'e %o( o- t#e monito% sc%een and (it# eac# co!'mn a!i&ned ve%tica!!y and %i&#t-G'sti-ied*

T#e n'me%ica! va!'es t#at a%e assi&ned to t#e individ'a! e!ements o- a mat%ix can "e ente%ed into t#e va%ia"!e assi&nment in a n'm"e% o- (ays* T#e sim$!est (ay is "y di%ect )ey"oa%d ent%y/ #o(eve%, !a%&e data sets may "e mo%e convenient!y ente%ed t#%o'&# t#e 'se osto%ed -i!es o% "y &ene%atin& t#e e!ement va!'es 'sin& mat!a" ex$%essions* Fi%st, (e (i!! !oo) at t#e 'se o- t#e )ey"oa%d -o% di%ect ent%y*

TE8BOARD DEFINITION OR ENTR8 FOR A MATRI7

A mat%ix can "e de-ined "y a n'm"e% o- mat!a" ex$%essions* Exam$!es a%e !isted "e!o( -o% a 5 x ; %o( vecto%, x, (#ose e!ements a%e x(5 : @, x(@ : F and x(; : -5*

x : 6 @ F -5 9

o% x:6@ F -59

o%

x : 6 @,F,-5 9

(A )eyst%o)e 3ente%3 -o!!o(s eac# o- t#e a"ove mat!a" statements* Notice t#at "%ac)ets m'st "e 'sed to o$en and c!ose t#e set on'm"e%s, and notice t#at commas o% "!an)s may "e 'sed as de!imite%s "et(een t#e -ie!ds de-inin& t#e e!ements o- t#e mat%ix* B!an)s 'sed a%o'nd t#e : si&n and t#e "%ac)ets a%e s'$e%-!'o's/ #o(eve%, t#ey sometimes ma)e t#e statement mo%e %eada"!e*

A @xF mat%ix, y, (#ose e!ements a%e y(5,5 :4, y(5,@ : y(5,; : @, y(5,F : ;, y(@,5 : R, y(@,@ : -;, y(@,; : S and y(@,F : F can "e de-ined

y:64@@; R -; S F 9 o% y : 6 4 @ @ ; / R -; S F 9

T#e semico!on L/L is 'sed to di--e%entiate t#e mat%ix %o(s (#en t#ey a$$ea% on a sin&!e !ine -o% data ent%y*

T#e e!ements o- a mat%ix can "e de-ined (it# a!&e"%aic ex$%essions $!aced at t#e a$$%o$%iate !ocation o- t#e e!ement* T#'s

a : 6 sin($i<@ s+%t(@ ;=F S<; ex$(@ 9

de-ines t#e mat%ix

a : 6 5*4444 5*F5F@ U*4444 @*4444 U*;VQ5 9

A mat%ix can "e de-ined "y a'&mentin& $%evio's!y de-ined mat%ices* Reca!!in& t#e mat%ix, x, de-ined ea%!ie%

x5 : 6 x R V 9 c%eates t#e %es'!t

x5 : 6 @ F -5 R V 9

T#e ex$%ession

x(R : V

c%eates

x : 6 @ F -5 4 V 9

Notice t#at t#e va!'e L4L is s'"stit'ted -o% x(F (#ic# #as not "een ex$!icit!y de-ined*

Reca!!in& t#e de-inition o- mat%ix, y, a"ove, t#e ex$%essions

c:6F R S ;9 . : 6 y/c 9

c%eates

.:64 @ @ ; R -; S F F R S ;9

Note t#at eve%y time a mat%ix is de-ined and an 3ente%3 )eyst%o)e is exec'ted, mat!a" ec#oes "ac) t#e %es'!t* TO CANCEL TOIS ECOO, TOE MATLAB COMMAND LINE CAN INCL0DE A SEMICOLON AT TOE END OF TOE LINE BEFORE TOE TE8STROTE 3ENTER3*

.:6y/c9/

LINE CONTIN0ATION

Occasiona!!y, a !ine is so !on& t#at it can not "e ex$%essed in t#e V4 s$aces avai!a"!e on a !ine, in (#ic# case a !ine contin'ation is needed* In mat!a", t#e e!!i$sis de-inin& a !ine contin'ation is t#%ee s'ccessive $e%iods, as in L***L* T#'s

F = R = ; *** = 5 = 54 = @ *** =R

&ives t#e %es'!t

ans : ;4

Notice t#at in t#is sim$!e a%it#metic o$e%ation, no mat%ix (as de-ined* M#en s'c# an o$e%ation is exec'ted in mat!a", t#e %es'!t is assi&ned to t#e mat%ix tit!ed LansL* A s'"se+'ent o$e%ation (it#o't an assi&nment to a s$eci-ic mat%ix name (i!! %e$!ace t#e %es'!ts in 3ans3 "y t#e %es'!t o- t#e next o$e%ation* In t#e a"ove, 3ans3 is a 5x5 mat%ix, "'t it need not "e so in &ene%a!*

BEFORE 8O0 K0IT TOIS SESSION !!!!!

I- t#is is yo'% -i%st !esson 'sin& mat!a", exec'te t#e mat!a" commands 3(#o3 and (#os3 "e-o%e yo' 3+'it3* Note t#at eac# o- t#ese

commands !ists t#e mat%ices yo' #ave de-ined in t#is session on t#e com$'te%* T#e command 3(#os3 a!so te!!s yo' t#e $%o$e%ties o- eac# mat%ix, inc!'din& t#e n'm"e% o- e!ements, t#e %o( and co!'mn si.e (%o( x co!'mn and (#et#e% t#e e!ements a%e com$!ex o% %ea!*

IM1ORTANT! I- yo' exec'te t#e mat!a" command 3save3 "e-o%e yo' +'it, a!! o- t#e mat%ices t#at #ave "een de-ined (i!! "e saved in a -i!e tit!ed mat!a"*mat sto%ed in yo'% (o%)s$ace* S#o'!d yo' desi%e to save s$eci-ic mat%ices d'%in& any session, t#e command 3save3 -o!!o(ed "y t#e name o- t#e mat%ix can "e exec'ted* Mo%e detai! on #o( to save and %eca!! yo'% mat%ices is disc'ssed in Lesson @*

1RACTICE 1ROBLEMS

Dete%mine t#e si.e and %es'!t -o% t#e -o!!o(in& mat%ices* S'"se+'ent!y, ca%%y o't t#e o$e%ations on mat!a" t#at de-ine t#e mat%ices, and c#ec) yo'% %es'!ts 'sin& t#e 3(#os3 statement*

5* a : 65,4,4,4,4,59

@* " : 6@/F/S/549

;* c : 6R ; R/ S @ -;9

F* d: 6; F R U Q 54 9

R* e : 6; R 54 4/ 4 4 *** 4 ;/ ; Q Q V 9

S* t : 6F @F Q9 + : 6t 4 t9

U* x : 6 ; S 9 y : 6d/x9 . : 6x/d9

V* % : 6 c/ x,R9

Q* v : 6 c(@,5 / " 9

54* a(@,5 : -; (NOTE? Reca!! mat%ix LaL (as de-ined in (5 a"ove* Ne( commands in t#is !esson?

save

saves a!! t#e mat%ices de-ined in t#e c'%%ent

session into t#e -i!e, mat!a"*mat, !ocated in t#e di%ecto%y -%om (#ic# yo' exec'ted mat!a"*

!oad

!oads contents o- mat!a"*mat into c'%%ent (o%)s$ace

save -i!ename x y . save t#e mat%ices x, y and . into t#e -i!e tit!ed -i!ename*mat*

!oad -i!ename !oads t#e contents o- -i!ename into c'%%ent (o%)s$ace/ t#e -i!e can "e a "ina%y (*mat -i!e o% an ASCII -i!e*

c!ea% x e%ases t#e mat%ix 3x3 -%om yo'% (o%)s$ace

c!ea%

e%ases ALL mat%ices -%om yo'% (o%)s$ace

NOTE - M#en 'sin& 1ROMATLAB on a (o%)station, -i!es a%e sto%ed in t#e di%ecto%y -%om (#ic# yo' invo)ed t#e 3mat!a"3 command* M#en 'sin& t#e (o%)station, c%eate a mat!a" s'"di%ecto%y tit!ed 3mat!a"3 o% some simi!a% name* T#e%ea-te%, sto%e a!! -i!es and cond'ct a!! mat!a" sessions in t#at s'"di%ecto%y*

ASCII FILES

An ASCII -i!e is a -i!e containin& c#a%acte%s in ASCII -o%mat, a -o%mat t#at is inde$endent o- 3mat!a"3 o% any ot#e% exec'ta"!e $%o&%am* 0sin& ASCII -o%mat, yo' can "'i!d a -i!e 'sin& a sc%een edito% o% a (o%d$%ocessin& $%o&%am, -o% exam$!e, t#at can "e %ead and 'nde%stood "y 3mat!a"3* T#e -i!e can "e %ead into 3mat!a"3 'sin& t#e L!oadL command desc%i"ed a"ove*

0sin& a text edito% o% 'sin& a (o%d$%ocesso% t#at is ca$a"!e o(%itin& a -i!e in ASCII -o%mat, yo' sim$!y $%e$a%e a mat%ix -i!e -o% (#ic# EACO ROM OF TOE MATRI7 IS A 0NIK0E LINE IN TOE FILE, (it# t#e e!ements in t#e %o( se$a%ated "y "!an)s* An exam$!e is t#e ; x ; mat%ix

@ ; S ; -5 4 U 4 -@

I- t#ese e!ements a%e -o%matted as desc%i"ed a"ove and sto%ed in a -i!ename tit!ed, -o% exam$!e, x*dat, t#e ; x ; mat%ix 3x3 can "e !oaded into 3mat!a"3 "y t#e command

!oad x*dat

O$en t#e Text Edito% (indo( on yo'% (o%)station* B'i!d a ;x;

mat%ix in t#e edito% t#at -o!!o(s t#e -o%mat ex$!ained a"ove* Sto%e t#is in yo'% mat!a" di%ecto%y 'sin& t#e command

save W<mat!a"<x*dat

T#e s'--ix, *dat, is not necessa%y/ #o(eve%, it is st%on&!y %ecommended #e%e to distin&'is# t#e -i!e -%om ot#e% data -i!es, s'c# as t#e *mat -i!es (#ic# (i!! "e desc%i"ed "e!o(* O- co'%se iyo' de-ine t#e -i!e (it# t#e *dat o% any ot#e% s'--ix, yo' m'st 'se t#at s'--ix (#en do(n!oadin& t#e -i!e to 3mat!a"3 (it# t#e 3!oad3 command* Remem"e%, t#e -i!e m'st "e sto%ed in t#e di%ecto%y in (#ic# yo' a%e exec'tin& mat!a"* In t#e a"ove exam$!e, it is ass'med t#at t#is di%ecto%y is tit!ed 3mat!a"3*

No( &o to a (indo( in (#ic# mat!a" is o$ened* Me desi%e to !oad t#e mat%ix x into mat!a"* Me mi&#t (onde% i- t#e -i!e x*dat is act'a!!y sto%ed in o'% mat!a" di%ecto%y* To %evie( (#at -i!es a%e sto%ed t#e%ein, t#e 'nix command 3!s3 can "e evo)ed in mat!a" "y $%ecedin& t#e command (it# an exc!amation ma%), ! * Ty$e t#e command

! !s

Mat!a" (i!! !ist a!! o- t#e -i!es in yo'% di%ecto%y* 8o' s#o'!d

-ind one tit!ed Lx*datL*

No(, ty$e t#e command

!oad x*dat

T#e ;x; mat%ix de-ined a"ove is no( do(n-!oaded into yo'% (o%)in& s$ace in mat!a"* To ens'%e t#at is so, c#ec) yo'% va%ia"!es "y ty$in& 3(#o3 o% 3(#os3*

FILES B0ILT B8 MATLAB****TOE *mat FILE

I- at any time d'%in& a mat!a" session yo' (is# to sto%e a mat%ix t#at #as "een de-ined in t#e (o%)s$ace, t#e command

save -i!ename

(i!! c%eate a -i!e in yo'% di%ecto%y t#at is tit!ed -i!ename*mat* T#e -i!e (i!! "e in "ina%y -o%mat, 'nde%standa"!e on!y "y t#e 3mat!a"3 $%o&%am* Note t#at 3mat!a"3 a$$ends t#e *mat s'--ix and t#is can "e omitted "y t#e 'se% (#en desc%i"in& t#e -i!ename*

I- t#e mat%ix 3x3 #as "een de-ined in t#e (o%)s$ace, it can "e sto%ed in yo'% di%ecto%y in "ina%y mat!a" -o%mat (it# t#e command

save x

T#e -i!ename need not "e t#e same as t#e mat%ix name* T#e -i!e named, -o% exam$!e, 3st'--3 can "e a -i!e t#at contains t#e mat%ix 3x3* Any n'm"e% o- mat%ices can "e sto%ed 'nde% t#e -i!ename* T#'s t#e command st%in&

save st'-- x y .

(i!! sto%e t#e mat%ices x, y and . in t#e -i!e tit!ed 3st'--3* T#e -i!e (i!! a'tomatica!!y #ave t#e s'--ix *mat added to t#e -i!ename* I-, d'%in& a session, yo' ty$e t#e command 3save3 (it# no ot#e% st%in&, a!! o- t#e c'%%ent mat%ices de-ined in yo'% (o%)s$ace (i!! "e sto%ed in t#e -i!e 3mat!a"*mat3*

T#e !oad command (#en a$$!ied to *mat -i!es -o!!o(s t#e same -o%mat as disc'ssed a"ove -o% ASCII -i!es/ #o(eve%, yo' can omit t#e -i!e s'--ix 3*mat3 (#en !oadin& *mat -i!es to yo'% (o%)s$ace*

COLON O1ERATOR

T#e co!on o$e%ato% 3 ? 3 is 'nde%stood "y 3mat!a"3 to $e%-o%m s$ecia! and 'se-'! o$e%ations* I- t(o inte&e% n'm"e%s a%e se$a%ated "y a co!on, 3mat!a"3 (i!! &ene%ate a!! o- t#e inte&e%s "et(een

t#ese t(o inte&e%s*

a : 5?V

&ene%ates t#e %o( vecto%, a : 6 5 @ ; F R S U V 9*

I- t#%ee n'm"e%s, inte&e% o% non-inte&e%, a%e se$a%ated "y t(o co!ons, t#e midd!e n'm"e% is inte%$%eted to "e a L%an&eL and t#e -i%st and t#i%d a%e inte%$%eted to "e L!imitsL* T#'s

" : 4*4 ? *@ ? 5*4

&ene%ates t#e %o( vecto% " : 6 4*4 *@ *F *S *V 5*4 9

T#e co!on o$e%ato% can "e 'sed to c%eate a vecto% -%om a mat%ix* T#'s i-

x:6@ S V 4 5 U -@ R -S 9

T#e command

y : x(?,5

c%eates t#e co!'mn vecto%

y:6 @ 4 -@ 9

and yy : x(?,@

c%eates yy : 6 S 5 R9

T#e command

. : x(5,?

c%eates t#e %o( vecto%

.:6@ S V9

T#e co!on o$e%ato% is 'se-'! in ext%actin& sma!!e% mat%ices -%om !a%&e% mat%ices* I- t#e F x ; mat%ix c is de-ined "y

c : 6 -5 4 4 5 5 4 5 -5 4 4 4 @9 T#en

d5 : c(?,@?;

c%eates a mat%ix -o% (#ic# a!! e!ements o- t#e %o(s -%om t#e @nd and t#i%d co!'mns a%e 'sed* T#e %es'!t is a F x @ mat%ix

d5 : 6 4 4 5 4 -5 4 4 @9

T#e command

d@ : c(;?F,5?@

c%eates a @ x @ mat%ix in (#ic# t#e %o(s a%e de-ined "y t#e ;%d and Ft# %o( o- c and t#e co!'mns a%e de-ined "y t#e 5st and @nd co!'mns o- t#e mat%ix, c*

d@ : 6 5 -5 4 49

0SINA TOE CLEAR COMMANDS

Be-o%e +'ittin& t#is session o- 3mat!a"3, note t#e 'se o- t#e commands 3c!ea%3 and 3c!c3* Note t#at 3c!c3 sim$!y c!ea%s t#e sc%een, "'t does not c!ea% o% e%ase any mat%ices t#at #ave "een de-ined* T#e command 3c!ea%3 e%ase o% %emoves mat%ices -%om yo'% (o%)s$ace* 0se t#is command (it# ca%e* NOTE TOE COMMAND 3CLEAR3 MITOO0T AN8 MODIF8INA STRINA MILL ERASE ALL MATRICES IN 8O0R MORTS1ACE*

1ROBLEMS

De-ine t#e R x F mat%ix, &*

& : 6 4*S 5*R @*; -4*R V*@ 4*R -4*5 -@*4 R*U V*@ Q*4 5*R 4*R 4*R @*F 4*R 5*@ -@*; -F*R 4*R 9

Dete%mine t#e content and si.e o- t#e -o!!o(in& mat%ices and c#ec) yo'% %es'!ts -o% content and si.e 'sin& 3mat!a"3*

5* a : &(?,@

@* " : &(F,?

;* c : 654?5R9

F* d : 6F?Q/5?S9

R* e : 6-R,R9

S* -: 65*4?-*@?4*49

U* t5 : &(F?R,5?;

V* t@ : &(5?@?R,? Ne( commands in t#is !esson?

$!ot(x,y c%eates a Ca%tesian $!ot o- t#e vecto%s x 2 y

$!ot(y

c%eates a $!ot o- y vs* t#e n'me%ica! va!'es o- t#e e!ements in t#e y-vecto%*

semi!o&x(x,y $!ots !o&(x vs y

semi!o&y(x,y $!ots x vs !o&(y

!o&!o&(x,y

$!ots !o&(x vs !o&(y

&%id

c%eates a &%id on t#e &%a$#ics $!ot

tit!e(3text3 $!aces a tit!e at to$ o- &%a$#ics $!ot

x!a"e!(3text3 (%ites 3text3 "eneat# t#e x-axis o- a $!ot

y!a"e!(3text3 (%ites 3text3 "eside t#e y-axis o- a $!ot

text(x,y,3text3

(%ites 3text3 at t#e !ocation (x,y

text(x,y,3text3,3sc3 (%ites 3text3 at $oint x,y ass'min& !o(e% !e-t co%ne% is (4,4 and '$$e% %i&#t co%ne% is (5,5 *

$o!a%(t#eta,% c%eates a $o!a% $!ot o- t#e vecto%s % 2 t#eta (#e%e t#eta is in %adians*

"a%(x

c%eates a "a% &%a$# o- t#e vecto% x* (Note a!so

t#e command stai%s(x *

"a%(x,y c%eates a "a%-&%a$# o- t#e e!ements o- t#e vecto% y, !ocatin& t#e "a%s acco%din& to t#e vecto% e!ements o- 3x3* (Note a!so t#e command stai%s(x,y *

CARTESIAN OR 7-8 1LOTS

One o- 3mat!a"3 most $o(e%-'! -eat'%es is t#e a"i!ity to c%eate &%a$#ic $!ots* Oe%e (e int%od'ce t#e e!ementa%y ideas -o% sim$!y $%esentin& a &%a$#ic $!ot o- t(o vecto%s* Mo%e com$!icated and $o(e%-'! ideas (it# &%a$#ics can "e -o'nd in t#e 3mat!a"3 doc'mentation*

A Ca%tesian o% o%t#o&ona! x,y $!ot is "ased on $!ottin& t#e x,y data $ai%s -%om t#e s$eci-ied vecto%s* C!ea%!y, t#e vecto%s x and y m'st #ave t#e same n'm"e% o- e!ements* Ima&ine t#at yo' (is# to $!ot t#e -'nction ex -o% va!'es o- x -%om 4 to @* x : 4?*5?@/ y : ex$(x / $!ot(x,y

NOTE? T#e 'se o- se!ected -'nctions s'c# as ex$( and sin( (i!! "e

'sed in t#ese t'to%ia!s (it#o't ex$!anation i- t#ey ta)e on an 'nam"i&'o's meanin& consistent (it# $ast ex$e%ience* Oe%e it is o"se%ved t#at o$e%atin& on a mat%ix (it# t#ese -'nctions sim$!y c%eates a mat%ix in (#ic# t#e e!ements a%e "ased on a$$!yin& t#e -'nction to eac# co%%es$ondin& e!ement o- t#e a%&'ment*

O- co'%se t#e sym"o!s x,y a%e a%"it%a%y* I- (e (anted to $!ot tem$e%at'%e on t#e o%dinate and time on t#e a"scissa, and vecto%s -o% tem$e%at'%e and time (e%e !oaded in 3mat!a"3, t#e command (o'!d "e

$!ot(time,tem$e%at'%e

Notice t#at t#e command $!ot(x,y o$ens a &%a$#ics (indo(* I- yo' no( exec'te t#e command 3&%id3, t#e &%a$#ics (indo( is %ed%a(n* (Note yo' move t#e c'%so% to t#e command (indo( "e-o%e ty$in& ne( commands* To avoid %ed%a(in& t#e (indo(, yo' may 'se t#e !ine contin'ation e!!i$sis* Conside% $!ot(x,y ,*** &%id,*** tit!e(3Ex$onentia! F'nction3 ,*** x!a"e!(3x3 ,*** y!a"e!(3ex$(x 3 , text(*S,*F,3 y : ex$(x 3,3sc3

Note t#at i- yo' ma)e a mista)e in ty$in& a se%ies o- !ines ocode, s'c# as t#e a"ove, t#e 'se o- !ine contin'ation can "e -%'st%atin&* In a -'t'%e !esson, (e (i!! !ea%n #o( to c%eate "atc# -i!es (ca!!ed 3*m3 -i!es -o% exec'tin& a se%ies o- 3mat!a"3 commands* T#is a$$%oac# &ives yo' "ette% o$$o%t'nity to %et'%n to t#e command st%in& and edit e%%o%s t#at #ave "een c%eated*

Oavin& de-ined t#e vecto%s x and y, const%'ct semi!o& and !o&!o& $!ots 'sin& t#ese o% ot#e% vecto%s yo' may (is# to c%eate* Note in $a%tic'!a% (#at occ'%s (#en a !o&a%it#mic sca!e is se!ected -o% a vecto% t#at #as ne&ative o% .e%o e!ements* Oe%e, t#e vecto% x #as a .e%o e!ement (x(5 :4 * T#e !o&a%it#m o- .e%o o% any ne&ative n'm"e% is 'nde-ined and t#e x,y data $ai% -o% (#ic# a .e%o o% ne&ative n'm"e% occ'%s is disca%ded and a (a%nin& messa&e $%ovided*

T%y t#e commands $!ot(x and $!ot(y to ens'%e yo' 'nde%stand #o( t#ey di--e% -%om $!ot(x,y *

Notice t#at 3mat!a"3 d%a(s a st%ai&#t !ine "et(een t#e data$ai%s* I- yo' desi%e to see a %e!ative!y smoot# c'%ve d%a(n -o% a %a$id!y c#an&in& -'nction, yo' m'st inc!'de a n'm"e% o- data $oints* Fo% exam$!e, conside% t#e t%i&onomet%ic -'nction, sin(x5 (x5 is se!ected as t#e a%&'ment #e%e to distin&'is# it -%om t#e vecto% 3x3 t#at (as de-ined ea%!ie%*

1!ot sin(x5 ove% t#e !imits 4 X: x5 X: $i* Fi%st de-ine x5 (it# R e!ements, x5 : 4 ? $i<F ? $i y5 : sin(x5 $!ot(x5,y5

No(, %e$eat t#is a-te% de-inin& a ne( vecto% -o% x5 and y5 (it# @5 e!ements* (Note t#e 'se o- t#e semico!on #e%e to $%event t#e $%intin& and sc%o!!in& on t#e monito% sc%een o- a vecto% o% mat%ix (it# a !a%&e n'm"e% o- e!ements! x5 : 4 ? *4RB$i ? $i / y5 :sin(x5 / $!ot(x5,y5

1OLAR 1LOTS

1o!a% $!ots a%e const%'cted m'c# t#e same (ay as a%e Ca%tesian x-y $!ots/ #o(eve%, t#e a%&'ments a%e t#e an&!e 3t#eta3 in %adians meas'%ed CCM -%om t#e #o%i.onta! ($ositive-x axis, and t#e !en&t# o- t#e %adi's vecto% extended -%om t#e o%i&in a!on& t#is an&!e* 1o!a% $!ots do not a!!o( t#e !a"e!in& o- axes/ #o(eve%, notice t#at t#e sca!e -o% t#e %adi's vecto% is $%esented a!on& t#e ve%tica! and

(#en t#e 3&%id3 command is 'sed t#e an&!es-&%id is $%esented in 5Rde&%ee se&ments* T#e 3tit!e3 command and t#e 3text3 commands a%e -'nctiona! (it# $o!a% $!ots* an&!e : 4?*5B$i?;B$i/ %adi's : ex$(an&!e<@4 / $o!a%(an&!e,%adi's ,*** tit!e(3An Exam$!e 1o!a% 1!ot3 ,*** &%id

Note t#at t#e an&!es may exceed one %evo!'tion o- @B$i*

BAR ARA1OS

To o"se%ve #o( 3mat!a"3 c%eates a "a%&%a$#, %et'%n to t#e vecto%s x,y t#at (e%e de-ined ea%!ie%* C%eate "a% and stai% &%a$#s 'sin& t#ese o% ot#e% vecto%s yo' may de-ine* O- co'%se t#e 3tit!e3 and 3text3 commands can "e 'sed (it# "a% and stai% &%a$#s*

"a%(x,y and "a%(y stai% (x,y and stai%(y

M0LTI1LE 1LOTS

Mo%e t#an a sin&!e &%a$# can "e $%esented on one &%a$#ic $!ot* One common (ay to accom$!is# t#is is #o!d t#e &%a$#ics (indo( o$en (it# t#e 3#o!d3 command and exec'te a s'"se+'ent $!ottin& command* x5:4?*4RB$i?$i/ y5:sin(x5 / $!ot(x5,y5 #o!d y@:cos(x5 / $!ot(x5,y@

T#e L#o!dL command (i!! %emain active 'nti! yo' t'%n it o-- (it# t#e command 3#o!d o--3*

8o' can c%eate m'!ti$!e &%a$#s "y 'sin& m'!ti$!e a%&'ments* In addition to t#e vecto%s x,y c%eated ea%!ie%, c%eate t#e vecto%s a," and $!ot "ot# vecto% sets sim'!taneo's!y as -o!!o(s* a : 5 ? *5 ? ;/ " : 54Bex$(-a / $!ot(x,y,a,"

M'!ti$!e $!ots can "e accom$!is#ed a!so "y 'sin& mat%ices %at#e% t#an sim$!e vecto%s in t#e a%&'ment* I- t#e a%&'ments ot#e 3$!ot3 command a%e mat%ices, t#e COL0MNS o- y a%e $!otted on

t#e o%dinate a&ainst t#e COL0MNS o- x on t#e a"scissa* Note t#at x and y m'st "e o- t#e same o%de%! I- y is a mat%ix and x is a vecto%, t#e %o(s o% co!'mns o- y a%e $!otted a&ainst t#e e!ements o- x* In t#is instance, t#e n'm"e% o- %o(s OR co!'mns in t#e mat%ix m'st co%%es$ond to t#e n'm"e% o- e!ements in 3x3* T#e mat%ix 3x3 can "e a %o( o% a co!'mn vecto%!

Reca!! t#e %o( vecto%s 3x3 and 3y3 de-ined ea%!ie%* A'&ment t#e %o( vecto% 3y3 to c%eate t#e @-%o( mat%ix, yy* yy:6y/ex$(5*@Bx 9/ $!ot(x,yy

1LOTTINA DATA 1OINTS 2 OTOER FANC8 ST0FF

Mat!a" connects a st%ai&#t !ine "et(een t#e data $ai%s desc%i"ed "y t#e vecto%s 'sed in t#e 3$%int3 command* 8o' may (is# to $%esent data $oints and omit any connectin& !ines "et(een t#ese $oints* Data $oints can "e desc%i"ed "y a va%iety o- c#a%acte%s ( * , = , B , o and x * T#e -o!!o(in& command $!ots t#e x,y data as a Lc'%veL o- connected st%ai&#t !ines and in addition $!aces an 3o3 c#a%acte% at eac# o- t#e x5,y5 data $ai%s*

$!ot(x,y,x5,y5,3o3

Lines can "e co!o%ed and t#ey can "e "%o)en to ma)e distinctions amon& mo%e t#an one !ine* Co!o%ed !ines a%e e--ective on t#e co!o% monito% and co!o% $%inte%s o% $!otte%s* Co!o%s a%e 'se!ess on t#e common $%inte%s 'sed on t#is net(o%)* Co!o%s a%e denoted in 3mat!a"3 "y t#e sym"o!s %(%ed , &(&%een , "("!'e , (((#ite and i(invisi"!e * T#e -o!!o(in& command $!ots t#e x,y data in %ed so!id !ine and t#e %,s data in "%o)en &%een !ine*

$!ot(x,y,3%3,%,s,3--&3

1RINTINA ARA1OIC 1LOTS

Exec'tin& t#e 3$%int3 command (i!! send t#e contents o- t#e c'%%ent &%a$#ics (ido( to t#e !oca! $%inte%*

8o' may (is# to save in a &%a$#ics -i!e, a $!ot yo' #ave c%eated* To do so, sim$!y a$$end to t#e 3$%int3 command t#e name o- t#e -i!e* T#e command

$%int -i!ename

(i!! sto%e t#e contents o- t#e &%a$#ics (indo( in t#e -i!e tit!ed 3-i!ename*$s3 in a -o%mat ca!!ed $ostsc%i$t* 8o' need not inc!'de

t#e *$s s'--ix, as mat!a" (i!! do t#is* M#en yo' !ist t#e -i!es in yo'% mat!a" di%ecto%y, it is convenient to identi-y any &%a$#ics -i!es "y sim$!y !oo)in& -o% t#e -i!es (it# t#e *$s s'--ix* Iyo' desi%e to $%int one o- t#ese $ostsc%i$t -i!es, yo' can convenient!y Ld%a& and d%o$L t#e -i!e -%om t#e -i!e-mana&e% (indo( into t#e $%inte% icon* Commands int%od'ced in t#is !esson?

max(x

%et'%ns t#e maxim'm va!'e o- t#e e!ements in a

vecto% o% i- x is a mat%ix, %et'%ns a %o( vecto% (#ose e!ements a%e t#e maxim'm va!'es -%om eac# %es$ective co!'mn o- t#e mat%ix*

min (x

%et'%ns t#e minim'm o- x (see max(x -o% detai!s *

mean(x

%et'%ns t#e mean va!'e o- t#e e!ements o- a vecto%

o% i- x is a mat%ix, %et'%ns a %o( vecto% (#ose e!ements a%e t#e mean va!'e o- t#e e!ements -%om eac# co!'mn o- t#e mat%ix*

median(x same as mean(x , on!y %et'%ns t#e median va!'e*

s'm(x

%et'%ns t#e s'm o- t#e e!ements o- a vecto% o% i- x is a mat%ix, %et'%ns t#e s'm o- t#e e!ements -%om eac# %es$ective co!'mn o- t#e mat%ix*

$%od(x

same as s'm(x , on!y %et'%ns t#e $%od'ct o-

e!ements*

std(x

%et'%ns t#e standa%d deviation o- t#e e!ements o- a vecto% o% i- x is a mat%ix, a %o( vecto% (#ose e!ements a%e t#e standa%d deviations o- eac# co!'mn o- t#e mat%ix*

so%t(x

so%ts t#e va!'es in t#e vecto% x o% t#e co!'mns oa mat%ix and $!aces t#em in ascendin& o%de%* Note t#at t#is command (i!! dest%oy any association t#at may exist "et(een t#e e!ements in a %o( o- mat%ix x*

#ist(x

$!ots a #isto&%am o- t#e e!ements o- vecto%, x* Ten "ins a%e sca!ed "ased on t#e max and min va!'es*

#ist(x,n $!ots a #isto&%am (it# 3n3 "ins sca!ed "et(een t#e max and min va!'es o- t#e e!ements*

#ist((x(?,@

$!ots a #isto&%am o- t#e e!ements o- t#e @nd

co!'mn -%om t#e mat%ix x*

T#e 3mat!a"3 commands int%od'ced in t#is !esson $e%-o%m

sim$!e statistica! ca!c'!ations t#at a%e most!y se!--ex$!anato%y* A sim$!e se%ies o- exam$!es a%e i!!'st%ated "e!o(* Note t#at 3mat!a"3 t%eats eac# COL0MN OF A MATRI7 as a 'ni+'e set o- LdataL, #o(eve%, vecto%s can "e %o( o% co!'mn -o%mat* Be&in t#e exe%cise "y c%eatin& a 5@x; mat%ix t#at %e$%esents a time #isto%y o- t(o stoc#astic tem$e%at'%e meas'%ements*

Load t#ese data into a mat%ix ca!!ed 3timtem$*dat3 'sin& an edito% to "'i!d an ASCII -i!e*

Time(sec 4*4 5*4 @*4 ;*4 F*4 R*4 S*4 U*4 V*4 Q*4 54*4 55*4

Tem$-T5(T ;4S ;4R ;5@ ;4Q ;4V @QQ ;55 ;4; ;4S ;4; ;4S ;4F 5@R 5@5 5@; 5@@ 5@F 5@Q 5@@ 5@@ 5@; 5@U 5@F 5@;

Tem$-T@(T

Exec'te t#e commands at t#e "e&innin& o- t#e !esson a"ove and

o"se%ve t#e %es'!ts* Note t#at (#en t#e a%&'ment is 3timtem$3, a mat%ix, t#e %es'!t is a 5x; vecto%* Fo% exam$!e, t#e command

M : max(timtem$ &ives M : 55 ;5@ 5@Q

I- t#e a%&'ment is a sin&!e co!'mn -%om t#e mat%ix, t#e command identi-ies t#e $a%tic'!a% co!'mn desi%ed* T#e command

M@ : max(timtem$(?,@ &ives M@ : ;5@

I- t#e va%iance o- a set o- data in a co!'mn o- t#e mat%ix is desi%ed, t#e standa%d deviation is s+'a%ed* T#e command

T5Yva% : (std(timtem$(?,@ E@ &ives T5Yva% : 5;*@U@U

I- t#e standa%d deviation o- t#e mat%ix o- data is -o'nd 'sin&

STDDEN : std(timtem$

&ives STDDEN : ;*S4RS ;*SF;@ @*;45@

Note t#at t#e command NAR : STDDENE@

is not acce$ta"!e/ #o(eve%, t#e command

NAR : STDDEN*E@

is acce$ta"!e, c%eatin& t#e %es'!ts,

NAR : 5;*4444 5;*@U@U R*@QRR 0SINA m-FILES - SCRATCO and F0NCTION FILES

Sometimes it is convenient to (%ite a n'm"e% o- !ines o3mat!a"3 code "e-o%e exec'tin& t#e commands* Me #ave seen #o( t#is can "e accom$!is#ed 'sin& t#e !ine contin'ation e!!i$sis/ #o(eve%, it (as noted in t#is a$$%oac# t#at any mista)e in t#e code %e+'i%ed t#e enti%e st%in& to "e ente%ed a&ain* 0sin& an m--i!e (e can (%ite a n'm"e% o- !ines o- 3mat!a"3 code and sto%e it in a -i!e (#ose name (e se!ect (it# t#e s'--ix 3*m3 added* S'"se+'ent!y t#e command st%in& o% -i!e content can "e exec'ted "y invo)in& t#e name o- t#e -i!e (#i!e in 3mat!a"3* T#is a$$!ication is ca!!ed a SCRATCO FILE*

On occasion it is convenient to ex$%ess a -'nction in 3mat!a"3 %at#e% t#an ca!c'!atin& o% de-inin& a $a%tic'!a% mat%ix* T#e many 3mat!a"3 sto%ed -'nctions s'c# as sin(x and !o&(x a%e exam$!es o-'nctions* Me can (%ite -'nctions o- o'% de-inition to eva!'ate $a%amete%s o- o'% $a%tic'!a% inte%est* T#is a$$!ication o- m--i!es is ca!!ed F0NCTION FILES*

SCRATCO FILES

A sc%atc# -i!e m'st "e $%e$a%ed in a text edito% in ASCII -o%mat and sto%ed in t#e di%ecto%y -%om (#ic# yo' invo)ed t#e command to do(n!oad 3mat!a"3* T#e name can "e any !e&itimate -i!e name (it# t#e 3*m3 s'--ix*

As an exam$!e, s'$$ose (e (is# to $%e$a%e a x-y $!ot o- t#e -'nction

y : e-x<54 sin(x

4 x Z 54 *

To accom$!is# t#is 'sin& a sc%atc# L*m--i!eL, (e (i!! ca!! t#e -i!e 3ex$!ot*m3* O$en t#e -i!e in a text edito% and ty$e t#e code "e!o(* (Note t#e 'se o- t#e 3[3 in !ine 5 "e!o( to c%eate a comment* Any text o% commands ty$ed on a !ine a-te% t#e3[3 (i!! "e

t%eated as a comment and i&no%ed in t#e exec'ta"!e code* [ A sc%atc# m--i!e to $!ot ex$(-x<54 sin(x x : 6 4?*@?54 9/ y : ex$(-x<54 *B sin(x / $!ot(x,y ,*** tit!e(3E71ONENTIAL DAM1ED SINE F0NCTION3 ,*** x!a"e!(3x3 ,*** y!a"e!(3y3 ,*** text(*S,*U,3y : ex$(-x<54 Bsin(x 3,3sc3

Sto%e t#is -i!e 'nde% t#e name 3ex$!ot*m in yo'% 3mat!a"3 di%ecto%y* No( (#en yo' a%e in 3mat!a"3, any time yo' ty$e t#e command 3ex$!ot3 t#e x-y $!ot o- t#e dam$ed ex$onentia! sine -'nction (i!! a$$ea%*

F0NCTION FILES

S'$$ose t#at yo' (is# to #ave in yo'% 3mat!a"3 (o%)s$ace a -'nction t#at ca!c'!ates t#e sine o- t#e an&!e (#en t#e a%&'ment is in de&%ees* T#e mat!a" -'nction sin(x %e+'i%es t#at x "e in %adians* A -'nction can "e (%itten t#at 'se t#e 3mat!a"3 sin(x -'nction, (#e%e x is in %adians, to accom$!is# t#e o"Gective oca!c'!atin& t#e sine o- an a%&'ment ex$%essed in de&%ees* A&ain, as in t#e case o- t#e sc%atc# -i!e, (e m'st $%e$a%e t#e -i!e in ASCII -o%mat 'sin& a text edito%, and (e m'st add t#e s'--ix 3*m3

to t#e -i!e* OERE TOE NAME OF TOE FILE M0ST BE TOE NAME OF TOE F0NCTION*

T#e -o!!o(in& code (i!! accom$!is# o'% o"Gective* Note t#at t#e -i%st !ine m'st a!(ays "e&in (it# t#e (o%d L-'nctionL -o!!o(ed "y t#e name o- t#e -'nction ex$%essed as L y : -'nction-nameL* Oe%e t#e -'nction name is Lsind(x L* T#is is t#e name "y (#ic# (e (i!! ca!! -o% t#e -'nction once it is sto%ed*

-'nction y : sind(x [ T#is -'nction ca!c'!ates t#e sine (#en t#e a%&'ment is de&%ees [ Note t#at a%%ay m'!ti$!ication and division a!!o(s t#is to [ o$e%ate on sca!a%s, vecto%s and mat%ices* y : sin( x *B $i *< 5V4

A&ain, note t#e %'!e in (%itin& t#e -'nction is to ex$%ess in t#e -i%st !ine o- t#e -i!e t#e (o%d 3-'nction3, -o!!o(ed "y y : -'nction ca!!, #e%e 3sind3 (it# t#e -'nction a%&'ment in $a%ent#eses, 3x3 is t#e -'nction ca!!* T#'s,

-'nction y:sind(x

No( eve%y time (e ty$e sind(x in 3mat!a"3, it (i!! %et'%n t#e va!'e o- t#e sine -'nction ca!c'!ated 'nde% t#e ass'm$tion t#at x is in de&%ees* O- co'%se any mat%ix o% ex$%ession invo!vin& a mat%ix can "e (%itten in t#e a%&'ment* ALAEBRAIC O1ERATIONS IN MATLAB

Sca!a% Ca!c'!ations* T#e common a%it#metic o$e%ato%s 'sed in s$%eads#eets and $%o&%ammin& !an&'a&es s'c# as BASIC a%e 'sed in 3mat!a"3* In addition a distinction is made "et(een %i&#t and !e-t division* T#e a%it#metic o$e%ato%s a%e

= B < D E

addition s'"t%action m'!ti$!ication %i&#t division (a<" means a C " !e-t division (aD" means " C a ex$onentiation

M#en a sin&!e !ine o- code inc!'des mo%e t#an one o- t#ese o$e%ato%s t#e $%ecedence o% o%de% o- t#e ca!c'!ations -o!!o(s t#e "e!o( o%de%?

1%ecedence 5 @

O$e%ation

$a%ent#eses ex$onentiation, !e-t to %i&#t

; F

m'!ti$!ication and division, !e-t %i&#t addition and s'"t%action, !e-t %i&#t

T#ese %'!es a%e a$$!ied to sca!a% +'antities (i*e*, 5x5 mat%ices in t#e o%dina%y manne%* (Be!o( (e (i!! discove% t#at nonsca!a% mat%ices %e+'i%e additiona! %'!es -o% t#e a$$!ication o- t#ese o$e%ato%s!! Fo% exam$!e,

;BF ans:5@

exec'ted in 3mat!a"3 &ives

F<R

exec'ted in 3mat!a"3 &ives

ans:*V444

FDR

exec'ted in 3mat!a"3 &ives

ans:5*@R44

x : $i<@/ y : sin(x y:5

exec'ted in 3mat!a"3 &ives

. : 4/ ( : ex$(FB. <R .: *@444

exec'ted in 3mat!a"L &ives

Note t#at many $%o&%amme%s (i!! $%e-e% to (%ite t#e ex$%ession -o%

( a"ove in t#e -o%mat ( : (ex$(FBx <R (#ic# &ives t#e same %es'!t and is sometimes !ess con-'sin& (#en t#e st%in& o- a%it#metic o$e%ations is !on&* 0sin& 3mat!a"3, ca%%y o't some sim$!e a%it#metic o$e%ations (it# sca!a%s yo' de-ine* In doin& so 'ti!i.e t#e 3mat!a"3 -'nctions s+%t(x , a"s(s , sin(x , asin(x , atan(x , atan@(x , !o&(x , and !o&54(x as (e!! as ex$(x * Many ot#e% -'nctions a%e avai!a"!e in 3mat!a"3 and can "e -o'nd in t#e doc'mentation*

Mat%ix Ca!c'!ations* Beca'se mat%ices a%e made '$ o- a n'm"e% o- e!ements and not a sin&!e n'm"e% (exce$t -o% t#e 5x5 sca!a% mat%ix , t#e o%dina%y %'!es o- comm'tative, associative and dist%i"'tive o$e%ations in a%it#metic do not a!(ays -o!!o(* Mo%eove%, a n'm"e% o- im$o%tant "'t common-sense %'!es (i!! $%evai! in mat%ix a!&e"%a and 3mat!a"3 (#en dea!in& (it# nonsca!a% +'antities*

Addition and S'"t%action o- Mat%ices* On!y mat%ices o- t#e SAME ORDER can "e added o% s'"t%acted* M#en t(o mat%ices o- t#e same o%de% a%e added o% s'"t%acted in mat%ix a!&e"%a, t#e individ'a! e!ements a%e added o% s'"t%acted* T#'s t#e dist%i"'tive %'!e a$$!ies*

A=B: B=A

and A - B : B - A

I- C : A = B t#en eac# e!ement CiG : AiG = BiG*

De-ine A and B as -o!!o(s?

A:65 @ ;/ ; ; ;/ R ; 59 B:6@ -; F/@ -@ @/ 4 F 49

T#en note t#at

C:A= B &ives C:

and C : B = A

; -5 U R 5 R R U 5

No( de-ine t#e %o( vecto%

x: 6; R U9

and t#e co!'mn vecto%

y : 6F/ -5/ -;9

Note t#at t#e o$e%ation

.:x=y

is not va!id! It is not va!id "eca'se t#e t(o mat%ices do not #ave t#e same o%de%* (x is a 5x; mat%ix and y is a ;x5 mat%ix* Addin& any n'm"e% o- 5x5 mat%ices o% sca!a%s is $e%missi"!e and -o!!o(s t#e o%dina%y %'!es o- a%it#metic "eca'se t#e 5x5 mat%ix is a sca!a%* Addin& t(o vecto%s is $e%missi"!e so !on& as eac# is a %o( vecto% (5xn mat%ix o% co!'mn vecto% (nx5 mat%ix * O- co'%se any n'm"e% o- vecto%s can "e added o% s'"t%acted, t#e %es'!t "ein& t#e a%it#metic s'm o- t#e individ'a! e!ements in t#e co!'mn o% %o( vecto%s* S+'a%e mat%ices can a!(ays "e added o% s'"t%acted so !on& as t#ey a%e o- t#e same o%de%* A FxF s+'a%e mat%ix can not "e added to a ;x; s+'a%e mat%ix, "eca'se t#ey a%e not o- t#e same o%de%, a!t#o'&# "ot# mat%ices a%e s+'a%e*

M'!ti$!ication o- Mat%ices* Mat%ix m'!ti$!ication, t#o'&# st%ai&#t-o%(a%d in de-inition, is mo%e com$!ex t#an a%it#metic m'!ti$!ication "eca'se eac# mat%ix contains a n'm"e% o- e!ements* Reca!! t#at (it# vecto% m'!ti$!ication, t#e existence o- a n'm"e% o- e!ements in t#e vecto% %es'!ted in t(o conce$ts om'!ti$!ication, t#e sca!a% $%od'ct and t#e vecto% $%od'ct* Mat%ix m'!ti$!ication #as its a%%ay o- s$ecia! %'!es as (e!!*

In mat%ix m'!ti$!ication, t#e e!ements o- t#e $%od'ct, C, ot(o mat%ices ABB a%e ca!c'!ated -%om

CiG : H Ai) B B)G

To -o%m t#is s'm, t#e n'm"e% o- co!'mns o- t#e -i%st o% !e-t mat%ix (A m'st "e e+'a! to t#e n'm"e% o- %o(s in t#e second o% %i&#t mat%ix (B * T#e %es'!tin& $%od'ct, mat%ix C, #as an o%de% -o% (#ic# t#e n'm"e% o- %o(s e+'a!s t#e n'm"e% o- %o(s o- t#e -i%st (!e-t mat%ix (A and t#e $%od'ct (C #as a n'm"e% o- co!'mns e+'a! to t#e n'm"e% o- co!'mns in t#e second (%i&#t mat%ix (B * It is c!ea% t#at ABB IS NOT NECESSARIL8 EK0AL TO BBA! It is a!so c!ea% t#at ABB and BBA on!y exist -o% s+'a%e mat%ices!

Conside% t#e sim$!e $%od'ct o- t(o s+'a%e @x@ mat%ices*

a : 6 5 @/ ; F9/ " : 6 V U/ S R9/

Ca!!in& t#e $%od'ct c : aB"

c55 : a55B"55 = a5@B"@5 c5@ : a55B"5@ = a5@B"@@

c@5 : a@5B"55 = a@@B"@5 c@@ : a@5B"5@ = a@@B"@@

Ca%%y o't t#e ca!c'!ations "y #and and ve%i-y t#e %es'!t 'sin& 3mat!a"3* Next, conside% t#e -o!!o(in& mat%ix $%od'ct o- a ;x@ mat%ix 7 and a @xF mat%ix 8*

7 : 6@ ; / F -5 / 4 U9/ 8 : 6R -S U @ / 5 @ ; S9/

Fi%st, note t#at t#e mat%ix $%od'ct 7B8 exists "eca'se 7 #as t#e same n'm"e% o- co!'mns (@ as 8 #as %o(s (@ * (Note t#at 8B7 does NOT exist! I- t#e $%od'ct o- 7B8 is ca!!ed C, t#e mat%ix C m'st "e a ;xF mat%ix* A&ain, ca%%y o't t#e ca!c'!ations "y #and and ve%i-y t#e %es'!t 'sin& 3mat!a"3*

Note t#at t#e 1ROD0CT OF A SCALAR AND A MATRI7 is a mat%ix in (#ic# eve%y e!ement o- t#e mat%ix #as "een m'!ti$!ied "y t#e sca!a%* Ne%i-y t#is "y %eca!!in& t#e mat%ix 7 de-ined a"ove, and ca%%y o't t#e $%od'ct ;B7 on 3mat!a"3* (Note t#at t#is can "e (%itten 7B; as (e!! as ;B7, "eca'se +'antity 3;3 is sca!a%*

ARRA8 1ROD0CTS

Reca!! t#at addition and s'"t%action o- mat%ices invo!ved

addition o% s'"t%action o- t#e individ'a! e!ements o- t#e mat%ices* Sometimes it is desi%ed to sim$!y m'!ti$!y o% divide eac# e!ement o- an mat%ix "y t#e co%%es$ondin& e!ement o- anot#e% mat%ix* T#ese a%e ca!!ed 3a%%ay o$e%ationsL in 3mat!a"3* A%%ay o% e!ement-"ye!ement o$e%ations a%e exec'ted (#en t#e o$e%ato% is $%eceded "y a 3*3 ($e%iod * T#'s

a *B "

m'!ti$!ies eac# e!ement o- a "y t#e %es$ective e!ement o- "

a *< "

divides eac# e!ement o- a "y t#e %es$ective e!ement o- "

a *D "

divides eac# e!ement o- " "y t#e %es$ective e!ement o- a

a *E "

%aise eac# e!ement o- a "y t#e %es$ective " e!ement

Fo% exam$!e, i- mat%ices A and O a%e de-ined

A : 6 5 ; R/ @ F S9/ O : 6-F 4 ;/ 5 Q V9/

A *B O : 6 -F 4 5R @ ;S FV 9

TRANS1OSE OF A MATRI7

T#e t%ans$ose o- a mat%ix is o"tained "y inte%c#an&in& t#e %o(s and co!'mns* T#e 3mat!a"3 o$e%ato% t#at c%eates t#e t%ans$ose is t#e sin&!e +'otation ma%), 3* Reca!!in& t#e mat%ix A

A3 : 6 5 @ ; F R S9

Note t#at t#e t%ans$ose o- a m x n mat%ix c%eates a n x m mat%ix* One o- t#e most 'se-'! o$e%ations invo!vin& t#e t%ans$ose is t#at o- c%eatin& a co!'mn vecto% -%om a %o( vecto%, o% a %o( vecto% -%om a co!'mn vecto%* INNER (SCALAR 1ROD0CT OF TMO NECTORS

T#e sca!a% o% inne% $%od'ct o- t(o %o( vecto%s, A5 and A@ is -o'nd as -o!!o(s* C%eate t#e %o( vecto%s -o% t#is exam$!e "y decom$osin& t#e mat%ix A de-ined a"ove*

A5 : A(5,? A@ : A(@,?

T#en t#e inne% $%od'ct o- t#e 5x; %o( vecto% A5 and t#e 5x; %o( vecto% A@ is

A5 B A@3 : FF

Ne%i-y t#is %es'!t "y ca%%yin& o't t#e o$e%ations on 3mat!a"3*

I- t#e t(o vecto%s a%e eac# co!'mn vecto%s, t#en t#e inne% $%od'ct m'st "e -o%med "y t#e mat%ix $%od'ct o- t#e t%ans$ose o- a co!'mn vecto% times a co!'mn vecto%, t#'s c%eatin& an o$e%ation in (#ic# a 5 x n mat%ix is m'!ti$!ied (it# a n x 5 mat%ix*

In s'mma%y, note t#at t#e inne% $%od'ct m'st a!(ays "e t#e $%od'ct o- a %o( vecto% times a co!'mn vecto%*

O0TER 1ROD0CT OF TMO NECTORS

I- t(o %o( vecto%s exist, A5 and A@ as de-ined a"ove, t#e o'te% $%od'ct is sim$!y

A53 B A@

INote A53 is ;x5 and A@ is 5x;J

and t#e %es'!t is a s+'a%e mat%ix in cont%ast to t#e sca!a% %es'!t -o% t#e inne% $%od'ct* DON3T CONF0SE TOE O0TER 1ROD0CT MITO TOE NECTOR 1ROD0CT IN MECOANICS! I- t#e t(o vecto%s a%e co!'mn vecto%s, t#e o'te% $%od'ct m'st "e -o%med "y t#e $%od'ct o- one vecto% times t#e t%ans$ose o- t#e second!

OTOER O1ERATIONS ON MATRICES

As noted a"ove, many -'nctions t#at exist can "e a$$!ied di%ect!y to a mat%ix "y sim$!y a!!o(in& t#e -'nction to o$e%ate on eac# e!ement o- t#e mat%ix a%%ay* T#is is t%'e -o% t#e t%i&onomet%ic -'nctions and t#ei% inve%se* It is t%'e a!so -o% t#e ex$onentia! -'nction, ex, ex$( , and t#e !o&a%it#mic -'nctions, !o&( and !o&54( *

Ex$onentia! o$e%ations ('sin& E on mat%ices a%e +'ite di--e%ent -%om t#ei% 'se (it# sca!a%s* I- M is a s+'a%e mat%ix ME@ im$!ies MBM (#ic# is +'ite di--e%ent -%om M*BM* Be ce%tain oyo'% intent "e-o%e %aisin& a mat%ix to an ex$onentia! $o(e%* Oco'%se ME@ on!y exists i- M is a s+'a%e mat%ix* S1ECIAL MATRICES

A n'm"e% o- s$ecia! -'nctions exist in 3mat!a"3 to c%eate s$ecia! o% 'n's'a! mat%ices* Fo% exam$!e, mat%ices (it# e!ement va!'es o- .e%o o% 5 a%e sometimes 'se-'!*

.e%os(F

c%eates a s+'a%e mat%ix (F x F (#ose e!ements a%e .e%o*

.e%os(;,@

c%eates a ; %o(, @ co!'mn mat%ix o- .e%os*

Simi!a%!y t#e commands ones(F c%eates a F x F s+'a%e mat%ix (#ose e!ements a%e 53s and 3ones(;,@ 3 c%eates a ;x@ mat%ix (#ose e!ements a%e 53s*

I- a m x n mat%ix, say A, a!%eady exists, t#e command 3ones(A 3 c%eates an m x n mat%ix o- 53s* T#e command 3.e%os(A 3 c%eates an mxn mat%ix o- 43s* Note t#at t#ese commands do not a!te% t#e $%evio's!y de-ined mat%ix A, (#ic# is on!y a "asis -o% t#e si.e o- t#e mat%ix c%eated "y commands .e%os( and ones( *

T#e identity mat%ix is a s+'a%e mat%ix (it# 53s on t#e dia&ona! and 43s o-- t#e dia&ona!* T#'s a FxF identity mat%ix, a, is

a:65 4 4 4 4544 4454 4 4 4 59

T#is mat%ix can "e c%eated (it# t#e 3eye3 -'nction* T#'s,

a : eye(F

T#e 3eye3 -'nction (i!! c%eate non-s+'a%e mat%ices* T#'s

eye(;,@ c%eates 5 4 4 5 4 4 and eye(@,; c%eates

544 454

1RACTICE

5* T#e -i%st -o'% te%ms o- t#e -o'%ie% se%ies -o% t#e s+'a%e (ave (#ose am$!it'de is R and (#ose $e%iod is @\ is

y : (@4<\ 6sinx = (5<; sin;x = (5<R sinRx = (5<U sinUx 9

Ca!c'!ate t#is se%ies, te%m "y te%m, and $!ot t#e %es'!ts -o% eac# $a%tia! s'm*

Das könnte Ihnen auch gefallen