test 2 fall 05

# test 2 fall 05 - MATLAB Reference Section diagim —...

This preview shows pages 1–6. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MATLAB Reference Section: diagim} — returns the diagonal elements of are square matrix In termini — returns the value of e" factorial.th — returns the value of nt {accurate fer n s 21} sineim} — returns the lndices of the non-zero elements of the arraym lengthie} — returns the largest dimension of the array a magic in:- — creates an n x n 'magio square' array meta} — returns the value and index of the largest element in the array 3 manta} e returns the value and index of the smallest element in the array a media, 1:} - returns only the remainder when a is divided by h ones (rows, eels} — creates a rat-re )t eels arrayr in which every element is 1 sinttheta} — returns the sine of the angle theta {in radians} size tat — returns the dimensions of the array 3 semis} —~ returns the sum of all the elements in the array as zerestrews, eels} — creates a row: Jt eels array in which every element is e a, | — used to perform element—oy—element logical operations on pairs of multi-element vectors and arrays, as well as on pairs of scalar logical values as. i | — used to perform logical operations on pairs of scalar logical values. and enables efficient, ‘short—circuif evaluation {but cannot be used on pairs of multi-element vectors and arrays} CS 13?1 — Computing for Engineers Test 2 Version 1 Nov 2"”, 21305 1. Multiple Choice {20 pts) 1. 1Iliihich of the following is most commonly used in a recursive function? a. for b. white C'ﬁ‘WeTs'r—e'ifm 3 . switchlcase 2. The amplitude versus time graph of an audio clip is a sinusoidal wave. the want to plot the frequency versus the power. What is the first step to do this? a. Ffotate the plot by 91] degrees. b. Plot the square of the amplitudes. CE) Perform an fft {Fast FourierTransform] on the amplitude versus time data. d. Perform an ifft {inverse Fast Fourier Transform] on the amplitude versus tlme data. Ce; Perform an fit on the reciprocal of the square of the amplitude versus time data. 3. Which of the following is noftrue about the fat function: E Goes between a time domain signal to a power spectral density. at is a built-in Mattab function that performs a Fast Fourier Transform. 1.flrill change the number of data points for a sound and condense it at two points. . Can be reversed using ifft to give the exact same data. 4. Which of the following isfare true about dimread [can pick more than one} The input file has to be a text file. b. Uses a delimeter to differentiate behveen one number and another. \s\ Can read in any type of data (numbers. strings. etc.) Ftetums an array of data BONUS {2 pts}: Why do British man not button the last button of their cardigans? ECDEFGHIJ Page 3 of El es 131 - Computing for Engineers TestZVersion1 Nov 2nd, zoos 2. Plotting (20 pts) You are playing around with 3-D plotting and want to compare two functions and using rnssh versus surito plot. You decide to put the four graphs together in one subplot, as shown below: 2 f1lx,yi = 3x + 4y + 0.5*xy - x + y: 2 f2 = x + 3;? + sinixy} 1. it the range of both functions is between -1DEt and 10D. writs out all the code to generate .1 the valuesforfrlxgiandfelxwi. u . \{a‘ﬁ \/ U Lilli... aw] : mahﬂﬁd is”; r/ I 10-1: 3-“- W t ‘l-i-‘W‘l + -'Jls.asa.>tYV<a.ne + 1+an «F1 3 xx. *2. r W4": 3r 9m {axﬁ‘l‘s’i 2. Writs all the oode used to plot the graph that has an arrow pointing at it [including subplot. labels. and title}. _ I L 1 I: liggpqu, [-11:01 gout?r too} !"—}hti€('l:wrlm "LJ 1’"! . {label [‘w') Ck?" il. Fwd) subsist (if? i'ﬂl/ : 715st”) -- ] s22};st l w. m sin-Maw) W—— 3. Why,r is rneshgrid used before defining values for f1 and is? was and. Wastes a Mli'or'rt‘ﬁ all has; rams outs of. “PM. i-cliwsas-una' std-mu; all sat wows an that "-“M it it“ ’3 WM ‘3'” H” ﬁlm” i. B C D E F G H I Rhea-El. sash D": "HLL Pasta Page 4 of B CS 1371 - Computing for Engineers Test 2 Version 1 Nov 2””, zoos 3. Images (20 pts) Given the code below: so A = imeadi impeacipa’ it Answer the following questions. 1. Create a new image B that is the same as A. only upside-down. 13;: tet[Eth11'i'-t}:3 L) f. _/ 2. Give the command to display:r B in a ligure. ﬂow it. E”: d 3. create a new image, C, which is the same as A, except the green values are scaled so that the maximum green value is 15G. 1‘45 C:¢~[:;:tl)* n' 4. What data type constitutes an FtGE matrix? What is the range ot this data type? 3- 5+ {mar star-ii; v-tv u. i M E: . ./' Tom; 0525-: I L- 5. Circle the error in the code below and explain the mistake: omit "HM-u. - E11" I. {.1 [Li 3 “3| .3 [It 0] = sizetsﬂiﬂﬁ _h_ I _ I I HEWI; newc] = tfloorirﬂi. floortct’ﬂii; moi“ iialzrdk 13,-. Laos-manning I " '| i.:-'.* 5.:1. GEL“ i': I-.-.:‘ __-l_ f0]: k = 1:3 T ILI'JJIH}. ~. I__ 3} for 1 = hr - [Fme ﬂour-“'3. Sit-tel '-:."u.i'_'-': [nu-mil. for j = 1:13 l”:- F.-I:I.':L'T:1.‘p_llrltltgl [Hz-r if J”. mYAVerage = meantmeaniAt2*i-1:2*i, 2*j—l:2*j,k}n; “I “L M: = mYAVEragE; ".I- K- .I.|_|‘_:I and ‘LL Intuit“ hilt-at. fl mic-n 4-.“ o ,. t _ E91311 ' w»?- W- t" - JrLtM-E ear; I .{iutt-t on F- whim twrg with which-.1: a.-.'.«'..i:r-.'va slut sooEPoHIJivtwv- Page 5 of 3 CS 1331 - Computing for Engineers Test 2 ldersion 1 Not.Ir 2"“, 20% 4. Metrioes and iteration (20 pts) Write a function called largestEuen which takes in an array and reiums a vector containing a 1 or i]. depending on whether or not the largest number in the column is divisible by two. The only,r built-in Matlab iunotion you can use for this problem is modﬂ. Ex: >1 largestEveni[1 2 3 4;2 3 4 5: 3 4 5 6]} ans = 1 o l D I e} largestEVEHEEJJ E t ﬂ QKJt ans = {I [J - ' n {edition and, : Emotes. Edit-q {LIV-ill“ .i if: CJ -'-' size [.anle ell-is: Lottoﬂhfc); {if 1 '1: (,1. ~ “languid! 3 mm (I! - 3 é‘of i -“ liT' PI -_ bani: l:l II In Hirer-J mini .- ii Lmddﬂenvapnmd, 44‘] ' are = 13 end ﬁr} and BGDEFGHIJ Page 6 of B CS 13?1 — Computing for Engineers Test 2 Version 1 Nov 2’”, EDGE 5. Flecursion {20 pts} Write a recursive function called "power" which takes in two numbers and returns the first to the power of the second. Make sure vour function incorporates all three aspects of a recursive function. HiNTS: i. Fiecaii that raising any number to the power of zero is t 2. Your inputs wiii oniy be positive numbers 3. The oniv mathematicai operator you can use is iii-t"! Ex: is powert5.0} one = >> power{2.3i ans = :::- power [5 .2} 3.113 = 25 {motion on; : {mus-via . r.) 1i? - :1 0 arts. 3 it] Page "i of E!- ...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern