Yeah, that's exactly what i've done...
Code:
def f(t, T):
if 0 < t < T/2.0:
value = 1.0
elif T/2.0 < t < float(T):
value = -1.0
elif abs(t - T/2.0) < 1e-6:
value = 0.0
else:
value = 0.0
return value
# i know that i can use the numpy module...
# but for this problem, it's supposed that we don't know yet ;)
def makelist(start, stop, inc):
val = start
tmp = []
while val <= (stop + inc):
tmp.append(val)
val += inc
return tmp
for t in makelist(0, 2.5, 0.1):
print '%5.2f\t%5.2f' % (t, f(t, 2))
The result of this is
HTML Code:
0.00 0.00
0.10 1.00
0.20 1.00
0.30 1.00
0.40 1.00
0.50 1.00
0.60 1.00
0.70 1.00
0.80 1.00
0.90 1.00
1.00 1.00 # supposed to be 0.0!
1.10 -1.00
1.20 -1.00
1.30 -1.00
1.40 -1.00
1.50 -1.00
1.60 -1.00
1.70 -1.00
1.80 -1.00
1.90 -1.00
2.00 0.00
2.10 0.00
2.20 0.00
2.30 0.00
2.40 0.00
2.50 0.00
What i'm missing?
Bookmarks