I defined a periodic piece wise function y[x_]
with some discrete steps with Piecewise
command and two lists xv
and yv
, which are the end points and values of the pieces, respectively. y[x_]
is shown below.
Then I do a shifted and linearly combined version from y[x_]
, e.g., ys = y[x] - 1/2 y[x - 120] - 1/2 y[x + 120]
. ys[x_]
is shown below.
My question is, how to "read" from the synthesized function ys
the information of the end points and values of all pieces? For the example given, I would like two lists to be produced in the form of xsv = {-180, -150, -90, -30, 30, 90, 150, 180}
and ysv = {-2, -1, 1, 2, 1, -1, -2}
.
The code for this process is
xv = {-180, -90, 90, 180};
yv = {-1, 1, -1};
y[x_] := Piecewise[Table[{yv[[i]], xv[[i]] < Mod[x, 360, -180] < xv[[i + 1]]}, {i, Length[yv]}]];
Plot[y[x], {x, -180, 180}, Exclusions -> None]
ys = y[x] - 1/2 y[x - 120] - 1/2 y[x + 120];
Plot[ys, {x, -180, 180}, Exclusions -> None]