I need to plot following piecewise constant function is Sage:
def f(t):
T = 2.0 * pi
if t > 0 and t < T / 2.0:
return 1.0
elif t == T / 2.0:
return 0
elif t > T / 2.0 and t < T:
return -1.0
t = var('t')
p = plot(f(t), (t, 0, 10))
show(p)
But show(p) gives an error:
no way to make fast_float from None
The problem is that there is no default returned value in f(t), so the function returns None if t <= 0 or t >= T.
The original formula is this one and I can't modify it (so I can't add some default value): $$ f(t)=\begin{cases}1, & 0<t<T/2,\\0, & t=T/2,\\-1, & T/2<t<T\end{cases} $$
Can somebody help to plot this function? Seems like I need to draw it only in 0 < t < T interval, but I am out of ideas how to do it.