# Periodic piecewise functions?

Posted 3 years ago
5183 Views
|
7 Replies
|
0 Total Likes
|
 How would one create a piecewise periodic function (without using recursions)?For example I'd like to make this function Piecewise[{{x, 0 <= x <= Pi}, {x - 2 Pi, Pi < x < 2 Pi}}] repeat itself to infinity...
7 Replies
Sort By:
Posted 3 years ago
 Something like this? f[x_] := Switch[Mod[x, 2 Pi] <= Pi, True, 0, False, x - 2 Pi] Plot[f[x], {x, -Pi, 4 Pi}, PlotStyle -> Thick] 
Posted 3 years ago
 This seems to be on the good track....I don't want it to climb up the y-axis though... :/
Posted 3 years ago
 But that is the expression you posted -- perhaps this? f[x_] := Switch[Mod[x, 2 Pi] <= Pi, True, 0, False, Mod[x, 2 Pi] - Pi] Plot[f[x], {x, -Pi, 4 Pi}, PlotStyle -> Thick] 
Posted 3 years ago
 Hint: Think Mod[x, 2 Pi]That should be enough.
Posted 3 years ago
 This gives the "sawtooth" wave: Which is not what i was hoping for.
 That's what David had in mind Clear[nPeriodic] nPeriodic[x_?NumericQ] := Piecewise[{{Mod[x, 2 Pi], 0 <= Mod[x, 2 Pi] <= Pi}, {Mod[x, 2 Pi] - 2 Pi, Pi < Mod[x, 2 Pi] < 2 Pi}}]