Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

9/7/2015

Lecture6

Lecture6
MultipleInputFunctions

Youcandefineafunctiontohavemorethanoneinput.Thisisthesyntax:

functionr=func1(x,y)

Rememberthatthenameofthefunctionmustmatchthenameofthefile(witha.maddedat
theend).Therefore,nospaces,operatorsetc.inthenameofthefunction.

Exercise:
Makeafunctionforwhichtheinputisxandyandtheoutputisx^y.Fromthe
commandline,checkthefollowinginputs:
>powerfunc(2,3)powerfunc(3,2)
x=2y=3powerfunc(x,y)powerfunc(y,x)
Youcandefinemorethanonefunctioninsideafunctionfile:
func2.m:

functiony=func2(x)
y=helper(x)

functionr=helper(q)
r=q^2

Inthisway,thefunctionsinsidethefilearevisibletoalltheotherfunctionsinthefile.
However,onlythefirstcanbecalledfromoutsidethefile.

MoreonLogic
WarmUpExercises:
x=[1528901],y=[5226002].Evaluateandunderstand
thefollowing:
x>y
y>x
x==y
x<=y
x|y
x&y
http://ocw.mit.edu/ans7870/resources/farjoun/Lecture6.html

1/3

9/7/2015

Lecture6

x&~y
((x>y)|(y>x))
x<5
x(y<5)
x=[1:10],y=[3156829470].Evaluateandunderstandthe
following:
(x>3)&(y<5)
x(x>5)
x(y>5)
y(x<=4)
x((x<2)|(x>=8))
y((x<2)|(x>=8))
(remember,allnonzerovaluesaretrue)

Exercises:
Forx=[3159121012961]:
Setto0thepositiveelementsofx.
Setto3themultiplesof3.
with0
without0
Multiplyby5theevenelementsofx
Createyfromtheelementsofxthatare>10.
Setto0theelementslessthantheaverage.
Settothedistancefromtheaveragetheelementsgreaterthantheaverage.
Createrandcsuchthat:
(11111)
(22222)
r=(33333)c=r'
(44444)
(55555)
Usingrandc,create
(10000)(10101)
(11000)(01010)
(11100)and(10101)
(11110)(01010)
(11111)(10101)
Thinkaboutideasforthefinalproject.
Ideasmentionedinclass:
Chaos
Logisticequation
MandelbrotSet
Combinatorics
8queensproblem
Dynamics
BrownianMotion
VisualIllusion
http://ocw.mit.edu/ans7870/resources/farjoun/Lecture6.html

2/3

9/7/2015

Lecture6

Autostereogram
Interploation
Useasplinetorecreateyournameincursive.

http://ocw.mit.edu/ans7870/resources/farjoun/Lecture6.html

3/3

You might also like