I want to create a piecewise function that repeats after t=T
.
Clear[t, T, s];
T = 5;
s[t_] := \[Piecewise] {
{t, 0 < t <= 1},
{1, 1 < t <= 2},
{-t + 3, 2 < t <= 3},
{0, 3 < t <= T}
}
To make it periodic, I add the following:
s[t_] := s[t - T] /; t > T
Plot[{s[t], Evaluate@D[s[t], t]}, {t, 0, 12}, Exclusions -> None]
It plots alright, but the derivative of s[t]
stops at the end of T
.
Question What is the correct way of defining and plotting the derivative and integral of a periodic waveform defined using the Piecewise
function?
Thanks in advance for your help and suggestions.
Plot[{s[t], D[s[x], x] /. x -> Mod[t, T]}, {t, 0, 12}]
? $\endgroup$Mod
. kglr's solution (in the comments) is to find the derivative for the base case and plot it usingMod
for different ranges. Nasser's solution is suitable for teaching canonical use ofPiecewise
. It defines a base function and then defines a periodic function based on it, perhaps usingT
as a parameter. Ted Ersek's solution shows the Gibb's phenomenon that alludes to MMa's use ofSeries
being used in the background. My thanks to all the respondents. $\endgroup$