Docsity

Practice Midterm 01, Exams of Software Engineering

Toggle sidebar
bg1
Page 1 of 7 E7 Spring 2009 Midterm I SID:_________________
1
UNIVERSITY OF CALIFORNIA, BERKELEY
Department of Civil and Environmental Engineering
Practice Midterm 01
50 minutes – 50 pts
Question Points Grade
1 4
2 5
3 6
4 16
5 7
6 12
Total 50
Notes
(a) Write your name and your SID on the top right corner of EVERY page (including the first page)
(b) Full credit will be awarded only if the correct answer is given in the box provided. Partial credit may be
awarded with respect to the work you show outside the boxes
(c) You may not leave the exam room before the exam ends
(d) No calculator / computer is allowed
(e) You may have one sheet of notes written on both sides
Your PRINTED FULL NAME + signature
____________________________________________________________
Please circle your LAB Section:
11
M-W 6-8
Etcheverry
12
M-W 10-12
Etcheverry
13
M-W 2-4
Etcheverry
14
M-W 4-6
Etcheverry
15
Tu-Th 8-10
Etcheverry
16
Tu-Th 10-12
Etcheverry
17
Tu-Th 12-2
Etcheverry
18
Tu-Th 2-4
Etcheverry
19
Tu-Th 4-6
Etcheverry
20
M-W 8-10
Etcheverry
21
M-W 10-12
Wheeler
22
Tu-Th 6-8
Etcheverry
23
Tu-Th 6-8
Wheeler
24
M-W 6-8
Wheeler
pf3
pf4
pf5
pf8

Partial preview of the text

Download Practice Midterm 01 and more Exams Software Engineering in PDF only on Docsity!

Page 1 of 7 E7 Spring 2009 Midterm I SID:_________________

UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering

Practice Midterm 01

50 minutes – 50 pts

Question Points Grade

1 4

2 5

3 6

4 16

5 7

(^6) 12

Total 50

Notes (a) Write your name and your SID on the top right corner of EVERY page (including the first page) (b) Full credit will be awarded only if the correct answer is given in the box provided. Partial credit may be awarded with respect to the work you show outside the boxes (c) You may not leave the exam room before the exam ends (d) No calculator / computer is allowed (e) You may have one sheet of notes written on both sides

Your PRINTED FULL NAME + signature

____________________________________________________________

Please circle your LAB Section:

M-W 6-

Etcheverry

M-W 10-

Etcheverry

M-W 2-

Etcheverry

M-W 4-

Etcheverry

Tu-Th 8-

Etcheverry

Tu-Th 10-

Etcheverry

Tu-Th 12-

Etcheverry

Tu-Th 2-

Etcheverry

Tu-Th 4-

Etcheverry

M-W 8-

Etcheverry

M-W 10-

Wheeler

Tu-Th 6-

Etcheverry

Tu-Th 6-

Wheeler

M-W 6-

Wheeler

UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008

Question 1

Consider the following equation:

2

1 2

r

mm

F = G

Where G is a constant equal to 6.673x10 -11, and m1, m2, and r are all arrays of size n by 1. Circle the answer to the following questions about writing this equation in MatLab.

(a) What is the correct way to calculate the array F?

A) F = Gm1m2/r^ B) F = Gm1.m2/rr C) F = Gm1.m2./r^ D) F = Gm1.m2./r.^* E) F = G(m1.m2)./r.*r

(b) Now assume that F is calculated in the command window. What is true about the dimensions (size) of F?

A) F will be a column vector B) F will be a row array C) F will be a scalar value D) F will be a square matrix E) Not enough information to tell

(c) Assuming that G, m1, m2, and r are scalar numbers, then class of F is:

A) char B) string C) double D) struct E) cell

(d) If G, m1, m2, and r are now only scalar numbers, then the following code will correctly calculate the value of F:

F = Gm1m2/r^

TRUE FALSE

UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008

Question 3

The following MATLAB commands are saved in a script file called examQuestion3a.m and examQuestion3b.m What is the value of x when the script file examQuestion3a.m is executed? What is the value of n and counter when examQuestion3b.m is executed? Do not worry about the exact format of the output.

Script file examQuestion3a.m

x = 0; for i = 1: for j = 1: if i == j x = x + 1; end end end

x = 1000

Script file examQuestion3b.m

n = 256; counter = 1;

while n ~= 1 if rem(counter,2) == 0 n = n/2; else n = n/4; end

counter = counter + 1 end

n = 1

counter = 6

UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008

Question 4

Consider the following 5 lines of MatLab code entered in the MATLAB command window:

X = [7 7 7 7]; Y = 6:9; W = 3; Z = 2; V = 8;

What is the output when the following commands are typed in sequence from the MATLAB command window? Do not worry about the exact format of the output.

V ~= X

ans = 1 1 1 1

>> V == Y

ans = 0 0 1 0

>> X+Y/

ans = 10.0000 10.5000 11.0000 11.

>> V/Z*W

ans = 12

>> 4*W/Z^2+

ans = 5

>> Z*[1:2:6]

ans = 2 6 10

a = [W,Z,V,Z] [a’,X’]

UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008

Question 5

  1. Consider the following parametric functions:

sin( ) cos(^ ) 2 cos( 4 ) sin^5

t

x t e t t

cos( ) cos(^ ) 2 cos( 4 ) sin^5

t

y t e t t

Create a function in MatLab called myButterfly which accepts an array of numbers (t) as input. The corresponding array of X and Y coordinates should be the output, as described by the equations above. The declaration line of the function should look like:

function [X,Y] = myButterfly(t)

Write the remainder of the myButterfly.m here:

function [X,Y] = myButterfly(t)

X = sin(t).(exp(cos(t)) – 2cos(4*t) – sin(7/12).^5);

Y = cos(t).(exp(cos(t)) – 2cos(4*t) – sin(7/12).^5);

Plot your function for t = 0 to 12π with an increment of 0.01π. No additional plotting parameters are needed (e.g. axis, grid, line style, plot color). This plot should go in the bottom right corner of a [2 x 2] subplot. You may use up to 3 lines of code.

[X,Y] = myButterfly(t);

subplot(2,2,4), plot(X,Y)

UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008

Question 6

Consider the following arrays defined in MatLab’s workspace:

W ⎥

Z

Retrieve the following sub-matrices from W and Z in a single line of MATLAB code:

Retrieve or create from W the following sub-arrays:

W([2,4],[1,3])

[ 0 0 0 0 0 0 ] >> W([5,9:10,13:15])

[ 1 1 ] >> W([1,end])

Retrieve or create from Z the following sub-arrays:

[ 6 0 5 9 7 2 ] >> Z(6:1)

[Z(2,3:-1:1);Z(1,:)]

Retrieve or create from W and Z the following sub-arrays:

[Z(:,1:2), W(2:3,2:3)]