I'm trying to make a piecewise function that will have period $12$. That is, it repeats every $12$ units across the $x$-axis.
I managed to do one cycle successfully with
plot(piecewise(0<=t and t<2, 4,2<=t and t<12,0), t=0..13);
But I'm not sure how to do it periodically. I thought about using modular arithmetic in the conditions and setting up something like
H(t)=piecewise(0<=modp1(f(t),12) and modp1(f(t),12)<2, 4,2<=modp1(f(t),12) and modp1(f(t),12)<12,0);
but this clearly doesn't work.
Some direction or advice would be appreciated.
Create a trigonometric polynomial P(t), of period 12, that approximates the characteristic function of [2,12]. Use enough terms to ensure P(t)>=1/2 on [2,12].
Then you can define your piecewise periodic function
$H(t) = piecewise(P(t)<1/2, 4 , P(t) \geq 1/2,0)$