{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Engineering 7 - Fall 2008 - Horowitz_Frenklack - Midterm 1 Solutions

# Engineering 7 - Fall 2008 - Horowitz_Frenklack - Midterm 1 Solutions

This preview shows pages 1–8. 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 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: University of Caliﬁmxia. Berkeley Department of Mechanical Engineering Fail Semester 2008 ' Instructors: M ankiach. R. Horowitz 1. Suppose the. following slate-mam are executed. >> A = [1 4 3 8']; ._‘[; L’t- Z .>>B=[335;142]; a Write the results of the following commands. Write “Error” if an error is produced. ' 41 (a) >> A(end:-2:2[.) 3’ L1 D (b) >> 3(5) g— D (:2) >> B (3,2) Em; r 3 ((1) >> Elf-2 l]:[3 1]) ’Z \ QT ' (D % Y I H I (e) >> B(:,2)t :“2 + A([3.43) ./ A([1 211 '1 w. ”W a i r1 we! W . _ 53' r ' E7 Midterm l 2 University of Calijbrnia, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M Frenkiach, R. Horawiiz 2. Suppose the following statements are executed {1i 4 2E6]; >> A = \J '\ / >> B = [2. :§.—Q‘;61; ‘1 c. —1 [1, Write the results of the following commands. Write ‘ _ rror” if an error is produced- 0°06} ooal (a) >> v—(Iiéléﬁ .1 (A==B). ll-l~\ P . 1 ’2’, 1“ —|‘. (b) >> A([.1,3D. .> B(2,:3) 0 I Y“ (c) >> fitld (A=FB) Li \(L‘ 6H. L \_ 1 ,g o_ 1-. (cl) >> find{ (A>=B') 5: (A<'(B*2)) ) ’2— xr “ w E7 Midterm] 3 University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M Frenklach, R. Horowitz 3. Assume that the following MAILAB command has been executed to create the sz cell array named Mycelj >> Mycell = {'Good' , {'Morning',r 5, ‘Sunshine'};... [3:77]; [1 5 ; 2 411‘ {'Morning' , 5, 'SunShine' } 3 1 5 . 2 4 Pictorial diagram of Mycell ( a) Write the results of the following commands. Write “Error” if an error is produced. (1) >> class (Mycell (1,'1)) cell (2) >> class (MycellLl, 1}) C how (0 (3) >> class (Mycell{1,.2})i <1an (4)» M¥391,1{1r1},(.2) O (5) >> Mycellfltz]; {2} '5 (continues on next page) E7 Midterm l 4 University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz { 'Morning ' , 5, ' Sunshine '} 3 I 5 7 2 4 Pictorial diagram of MyCel l (b) Write a one-line MATLAB command to create a character array that contains 'Ggod Morning Sunshine} from .the contents of Mycell . >> E Mm“imEV’g-MTMIilﬂii'i)‘ ’, miliméﬁ] ( , (c) Write a one-line MATLAB command that will add a third row of ones to the array contained in the (2,2) element of Myce 11 >> M3CL“%_112% 1‘ E MﬁCKUSLZ,ZEE 0h€§(|)2)j 7 E7 Midterm 1 5 Univemity of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M Frenklach, R. Horowitz 4. The following MATLAB commands are executed to obtain the structure array Teamdata: >> Teamdata(l) .Team = 'Suﬁaeit‘ >> Teamdata(1)l._Timing = [102, 107] >> Teamdata(2) .Team = ‘E'antastic' >> Teamdata(2).Tim:i=ng = [100, 101, 99] Write the mults of the following commands. Write ‘Error‘ if an error is produced. A a) >> size (Teamdata) (912/ (b) >> classtTeamdatanJeam) @ . 51W / (0) >> Teamdata(l)_ .Team(en:? was (d) >> s ? [ Teamdata_,Team ] C9 SUPWEﬂ‘Fﬁ—(HC L/ (a) >> 5(7) @ 0“. \/ 15) >> Teamdata{l.)_ .Timing (2 )._ \/ @ E7 Midterm l ' 6 University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz 5. (a) Given a rectangle pictured below, write a function called rectangle, which calculates its area and perimeter length. This function should have a and b as its input arguments and return output arguments area and perimeter. M—ﬁle rectangle .m (b) Create an anonymous function that computes and returns the sun; of the m. of two scalar input arguments of class double. >> [email protected](*l¥) x"1+‘7"2\$'/ E7 Midterm 1 7 University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz 6. Given the function my_funct shown below function y = my_funct(x) if_x (:5 ‘= 1: +72;- x <212, =x—2; Ive/2: write the results of the following commands. Writ; “Error” if an error is produced. Va) >> my__funct.(3) g M >> my__funct (10f i? (2) >> my_funct (26) 1 3 E7 Midterm 1 8 University of California, Berkeley Departrgwnt of Mechanical Engineering Fall Semester 2008 Instructors: M Frenklach, R. Horowitz 7. (a) The function min_dist shown below determines the minimum value of D(x)=\/f2(x)+12 iutherange a<x<b‘ where f (x) is a user-deﬁned ﬁmction. min_dist utilizes the MATLAB function j fminbnd (see syntax below)‘. Complete the incomplete line of code in ﬁmction min_dist. function D = min_dist(fh,a,h) 95 fh is the handle to a single—valued vectorized function %a<x<.b @m 'wet weir‘z + x."135/ [xmim D] = fminbnd(Dh,a,b_); (b) Write a command that uses the ﬁmction min_e_list to compute the minimum value of D(x) deﬁned above, when :3 _ —3, b = 3 and the function f (x) is deﬁned by the veetorized ﬁmction my_fun, which is stored in the M—ﬁle myihfun . m . ml'h_é;g+(@mv_pijn) ‘31?) / '>> vvnvx.vnluc = l[xmin,fmin] = fminbndIfh,a,b) min is a minimizer of a single-valued vectorized ﬁmetion with handle 15 h in the interval a < x‘< b. fmin = fh (xnlin) . this a function handle. E7 Midterm 1 9 ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

Engineering 7 - Fall 2008 - Horowitz_Frenklack - Midterm 1 Solutions

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online