Previous ECE Exam-1

Embed Size (px)

Citation preview

  • 8/14/2019 Previous ECE Exam-1

    1/7

    an effor, wite "errof'.,, '1t)A. cat(1,A,c)

    B. A. /C

    D=

    qo0 t l

    ' l

    G-a9+Lb'1 a=-

  • 8/14/2019 Previous ECE Exam-1

    2/7

    2. (15 pts total)Suppose hat matrix I is previouslydefined. fhe follo$,ing cornmandhas alreadybee.n ntered nMATLAB: [m nl : size(.,l);trll he spaccsprouided,rvrite the MATLAB commalds to do the follovring. Use only MATLAE's implier.{Xoops(array opcrations & functions|-no expliclt ioopsare permitted.Considereachcaseseparately.a. Delete hc 4'h column of A

    ,r/'

    b. Assuminghat he first row of A containsfle "x-" coordinatesnd hesccondow of A

  • 8/14/2019 Previous ECE Exam-1

    3/7

    3. (20pts otal)Useonly MATLAB's impliecloops arrayoperations functionsFno explicit oopsarepermitted n eitherpartsbelow!a.(l0pts).Writea i:nctionnamedAavg that hasone nputparamcter amcdA which s antmxn matrix. The irnctionshould eturn hrce terns-The irst item s a rov,vectornarned a.Eachelemcntof ca should lethe average f the clcmentsn thecorrcspondingcglumn9r {, after"dropping" he smallest alue,That s, ca[] will bc theaverage f thc rernaining alues n colurnn1of A afler droppinghe smallest alue n column 1. ca[2]will be he average f thc remaining aluesn colunm2 of Aafler dropping he smallest alue n columl 2, etc.The matrix A mu.st otbechzmgedy this calculation!Thc secondtem is a column eclornarned a- Eachelement f ra should e he average f thc elementsn tlrecorrespondingow of A' afler "dropping" le largest alue.That s, ra[l] rvill tre heaverage f t}e remaining aluesnrow I of A afler dropping the largestvalue n row 1. ra[2] will be the averageof theremainingvalues n row 2 of A :rJlerdroppinghe argest alue n row 2, etc.ThernatrixA mustnot be changed y this calculation!The hird itemrehrrneds a scalarnamed which s the average f all of theelements f thearrayI un+iot\lcrI yA/ yj

    . ' t -

    r)A-- l-nrud 'arra'1-- f '^ ;q)

    rf t= l?,7)t=F,4,t

    F,nl=ury,Cft))Ca(4,

    = SurnCn)-Y,'ntn) Q-t) ', o

    L) c,L, l= Aav!(x\h)A1) K

  • 8/14/2019 Previous ECE Exam-1

    4/7

    4. (15pts)Supposehat he unction ile mmfun.mand he script ile main.mas ndicated eloware n thecurrentdirectory. If main.m b "run",what wouldyou expect o see n thecommandwindow?main.m

    clear; c lc;a:9; n b:1-2; r 'c:8i / d:L2i 'd isp([a b c d] )- -rL ^1-* -t , .^ ta I'Lor al :mmrun \at D) i . - , /d:d+a;disp([a b c d] )

    mmfun.mfunct ion Ic, d] :mmfun (a.b)i f a>bc:b;d:a te]sei f a==be:anZid=b^Z;elsec:a;d:b;en ddicn/ l -r 1- ' n Al \slvrrLs r v sJ/

    Indicate command window output on the left below; put any "scratch" work on the right!commandwindow scratchq

    'lalt L

    tr{L(IL

    tqq

    9 lz/vy /trlg rsb

    d= lZ

    t+ l tcl t f

    h=-tz C=3=- rn-fund,b): tnry,'l:un(2,72)

    $;= tz ' = lL,Lf[g '= l7z = lt l t1l z tLlL+tLl t [= SG

  • 8/14/2019 Previous ECE Exam-1

    5/7

    5- I 5pts) You are hinking aboutbuying that new BMW thatyou'vehadyour eyeon for a while. you decide o letMATLAB help you out with your decision by letting it "roll the dice" for you. Write a script file that will generate arandomnumber100timesandusetlosevaluestodecidewhetherornotiobuvthecar+You will need o use he rand(lrl) unctionwhereN will be equal o 1.Calling rand(I) will produce randomnumberbetween0 and l. Setup an explicit loop to producea randomnumber100 imesand assign his yalue o x. You will needto test hevalueof x and ncrementoneof tlneecountersas ollows:if (x < .33), hen ncrementhecounter aiotlrerwise,f (.33: .66), ncrementhe countgfi.After testingall 100 andomvaluesyouwill need o inspect he threecounterso determinewhetheror not you sholld buytlte car.Iffai has he highestcountofall ofthe countershendisplay ForgetAbout t!"ff wny has he highestcount of all of thecountershen display Wait until nextyear.if gfi has he highestcount of all ofthe countershen display"Gofor it! "You cal assumehat all of the countervalueswill be different.

    N= t)nAmVU=fl )A1 C);w^I =tr \1q*r=cJ)Nhrtt nLlru\bTt

    f . - r ly,= U / wnde)J)u,tmblv= uh^bwl:

    n-I t - -

    t+

    ,-dRro)t^dfov 1',ltn9+\0)au)

    .ub)r l ;, btr+r)

    r , l '=Wt u)rt i9+lCountorsj natr(coun'lors)= fotdrl( 'futg*arr,utl ')

    tfuttI wwYbunlers)z \'oLy

    [a, lat +tdtttl @.tn)h3n1 runt1

    {-lil- .r"cil -\y, = 5l '

    I ( t [ r r )y= ,a' l )

    oLa-rd^A!' watf nl,{\fl+'Vi;;"JCtrspt l (ho0' r f )

  • 8/14/2019 Previous ECE Exam-1

    6/7

    {"a) 4u\6.(25pts)Supposehat f(x,r,c) is a functionof threevariablesand g(x) is a functionof a singlevariable.Forparticularvalues of r and c, the functions aregraphedbelolv as they vary with x:

    f( x, r, c)g(x)

    'l {trrd.h'r-torc4Pti4Junc{rorrlrur[= lla*u,,, )

    N(.N"/,+tnl,tlD, = f zero@oLlxel,,c ,fitta-=?Ltad(e-fo/ x/

    r,c))c), r,c)- quarl(Eg,D,)

    xof the unction s: function val] = f(x,r,c).Likewise a firnction namedg to calculate g(x) has already beenwritten and saved n the file g.m. The first line(header)ofthis function is: function [val]:g(x).Give the commands hat you couldput in a script file to do eachof the following. If additional function files arerequired, indicatehow they would be namedand the commands hat they would contain.UseMatlab'sfunction-functions,as appropriateand not array functions.I . (3pts)Thevaluesof r and c are on the first two lines of a plain text datafile namedgood.dat (onevalue for ron the first line and one value for c on the secondine). Read hesevalues and assign hem to variablesnamed

    i q(1' ! -3 = b'/"Delw-a nul tuwttion

    Junctronqj] : qt g\q1= 1o) -3)

    lhfi.rnxvol= fzeYl(@4t,s) l&ttP rat)

    Nv--I xtral, i uol|= { zero@+ l,- z,o' t' r' c),

    I vat ' -l^'sc'\"/,tsp(Prfal',u4

    3. (6pts)Find& display themaximum value of the firnction f(x,r,c) and the value of x where he marimum occursJunr+ton=i\( x, tL)

    ) =- l ( r r , ,c) ;Pagel of9

  • 8/14/2019 Previous ECE Exam-1

    7/7

    4. (l0pts)Find and display he value of the area of the regionbounded,by he positive vertical axis,the functionf(x,r,c), the firnctiong(x) and he positivex axis.

    Page8 of8