6.01 Midterm 1: Spring 2010: Solutions
6.01 Midterm 1: Spring 2010: Solutions
6.01 Midterm 1: Spring 2010: Solutions
Write the values of the following expressions. Write None when there is no value; write Error when an error results and explain briey why its an error. Assume that these expressions are evaluated one after another (all of the left column rst, then right column).
test = A(5) test = B(5)
None
None
test.take(2)
test.take(2)
Error
test.give(6)
test.give(6)
11
(0, 3)
test.howmuch()
test.howmuch()
(0, 11)
(6, 0, 3)
nameOfSmartest: returns the name attribute of the student with the highest IQ funOfBest: takes a procedure fun and a procedure feature as input, and returns the result of applying procedure fun to the student for whom the procedure feature yields the highest value
For the rst two problems below, assume that these methods have been implemented.
Here is a student body:
2. Write a Python expression that will compute the name of the person who has the greatest value of IQ + height in aardvarkU (not just for the example student body above). You can dene additional procedures if you need them.
aardvarkU.funOfBest(lambda x: x.name, lambda x: x.iq + x.height)
3. Implement the nameOfSmartest method. For full credit, use util.argmax (dened below) or the funOfBest method. If l is a list of items and f is a procedure that maps an item into a numeric score, then util.argmax(l, f) returns the element of l that has the highest score.
def nameOfSmartest(self): return util.argmax(self.students, lambda x: x.iq).name # or def nameOfSmartest(self): return funOfBest(lambda x: x.name, lambda x: x.iq)
Midterm 1 Solutions Spring 10 4. Implement the funOfBest method. For full credit, use util.argmax.
def funOfBest(self, fun, feature): return fun(util.argmax(self.students, feature))
3 SM to DE (15 Points)
Here is the denition of a class of state machines:
class Thing(SM):
startState = [0, 0, 0, 0]
def getNextValues(self, state, inp):
result = state[0] * 2 + state[2] * 3
newState = [state[1], result, state[3], inp]
return (newState, result)
2. The state machine above describes the behavior of an LTI system starting at rest. Write a difference equation that describes the same system as the state machine. y[n] = 2 * y[n-2] + 3 * x[n - 2]
4 Diagnosis (8 points)
What, if anything, is wrong with each of the following state machine denitions? The syntax is correct (that is, they are all legal Python programs), so that is not a problem. Write a phrase or a single sentence if something is wrong or nothing if nothing is wrong. 1.
class M1(SM):
startState = 0
def getNextValues(self, state, inp):
return inp + state
2.
class M2(SM): startState = 0 def getNextValues(self, state, inp): return (inp+state, (state, state))
This is ne.
4.
class M4(SM):
startState = -1
def __init__(self, v):
self.value = v def getNextValues(self, state, inp): if state > inp: self.value = self.value + state result = self.value * 2 return (state, result)
k1
+ R
k2 R R
Assume that the system starts at rest, that is, all the signals are zero at time zero. Assume also that the variables k1 and k2 are already dened. Recall that sm.Gain takes a gain as an argument, sm.Delay takes an initial output value as an argument and each of sm.Cascade, sm.FeedbackAdd, and sm.FeedbackSubtract, takes two state machines as arguments. Use indentation to highlight the structure of your answer.
FeedbackSubtract(Cascade(Cascade(Gain(k1), R()), FeedbackSubtract(Gain(k2), Cascade(R(),R()))), R())
10
the output of the system it describes will diverge or not, the output of the system it describes (a) will always be positive, (b) will alternate between positive and negative, or (c) will have a different pattern of oscillation
1.
positive/alternate/oscillate 2.
positive/alternate/oscillate
11
Delay
k1
=
Delay
k2
T I
c (1 k1 R)(1 + k2 R)
12
2. Let the system start at rest (all signals are zero). Suppose I[0] = 100 and I[n] = 0 for n > 0. Here are plots of T [n] as a function of n for this system for c = 1 and different values of k1 and k2 .
200
200
150
150
100
100
50
50
10
15
10
15
50
50
a
200
200
150
150
100
100
50
50
10
15
10
15
50
50
c
200
200
150
150
100
100
50
50
10
15
10
15
50
50
b. Which of the plots above corresponds to k1 = 1 and k2 = 0.5 ? Circle all correct answers: a b c d e f none
Midterm 1 Solutions Spring 10 3. Let k1 = 0.5, k2 = 3, and c = 1. Determine the poles of H, or none if there are no poles. Poles at 0.5 and -3
13
14
Delay
k1
Delay
k2
Circle all of the following systems that are equivalent (for some setting of the gains in the triangles) to the original system.
e System b has the same system function. System e has the same poles.
We required b to be circled, and considered e to be correct whether circled or not.
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.