Python Programming Homework Help
Python Programming Homework Help
class F:
x = 0
y = 10
def i n i t ( s e l f , y ):
self.x = y
def a1(self, y):
self.x = max(self.x, y)
return se lf.x
def a2(self):
self.x = max(self.x, sel f.y)
return sel f.x
class G(F):
def b(self):
self.y = sel f.x * self.x
return self.y
Write the values of the following expressions (enter None when there is
no value; write Error when an error results and explain briefly why
it’s an error). Assume these expressions are evalu ated one after the
other (in each column).
2 Signals
Given a signal x, we want to construct a signal y such that:
for 0 � a � 1.
Part a. Define a Signal subclass that represents this signal, given an
instance of the Signal class representing x and the value of a.
Construct the new signal, given a signal instance x, and a variable a,
as follows:
y = MySig(x, a)
class
MySig(sig.Signal):
def init (self, x, a):
self.x = x
self.a = a
def
sample(self,
Part b.n):
Given a signal instance x, and a variable a, write an expression
return
involving sig.PolyR that constructs an equivalent signal. To construct a
self.a*self.x.
polynomial use poly.Polynomial.
sample(n-1)
+ (1- poly.Polynomial([1-a, a, 0]))
sig.PolyR(x,
self.a)*self.x
Part c. .sample(n-2)
Write a Python procedure settleTime that is given:
class
FindNumbers(sm.SM
): startState = ’’
def getNextValues(self,
state, inp): if inp == ’ ’:
if state.isdigit():
return (’’, state)
else:
return (’’, None)
else:
return
(state+inp, ’x’)
4 Difference Equations
Newton’s law of cooling states that:
The change in an object’s temperature from one time step to the next
is proportional to the dif ference (on the earlier step) between the
temperature of the object and the temperature of the environment, as
well as to the length of the time step.
Let
Part b. Let k1 = 1 and k2 = −2. Assume that the system starts “at rest” (all
signals are zero) and that th input signal X is the unit sample signal.
Determine y[0] through y[3].
Part c. Let k1 = 1 and k2 = −2, determine the poles
of H.
Enter poles or none if there are poles: 2, -2 no
Part d. For each of the systems below indicate whether the system is
equivalent to this one: (Remember that there can be multiple
“equivalent” representations for a system.) If you write clearly the
system function for these systems, we may be able to give you partial
credit.
Equivalent to H (yes/no)? No
Equivalent to H (yes/no)? No
6 System Behaviors
Part a. Find the poles for the following
system functions:
0. Poles: 5 ± 0.5j
Part d. Which (if any) of the poles lead to the following unit sample
response?