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.
I've found a solution here: https://stackoverflow.com/questions/28661269/python-no-way-to-make-fast-float-from-none-error/28661486#28661486
I need to leave the
t
and plot justf
function without a parameter. Also min and max numbers should be in the range of0 <= t < T
: