# Get the set of points from constant function

I have a function f defined by points:

finput = {{0, 1/5}, {1/5, 1/5}, {1/2, 1}, {1, 0}};
ListLinePlot[finput, PlotRange -> {{0, 1}, {0, 1}}] Then I create a piecewise linear function from it

pcw[pts_, otherwise_: - 1] :=
Module[{ptsPairs, line, x},
line[p_] :=
Module[{p1 = p, p2 = p[], m, b},
m = (p2[] - p1[])/(p2 - p1);
b = p1[] - p1 m;
{mx + b, p1 <= x <= p2}];
ptsPairs = Partition[pts, 2, 1];
ptsPairs = Select[ptsPairs, # != #[]&];
Piecewise[line /@ ptsPairs /. x -> #, otherwise]&]

f = pcw[finput];


Now I would like to find patterns of the function, but the problem is to find patterns of the part, where the function is constant.

Normally I use Solve to get the set of points. But it doesn't work for this case so I am trying to use Reduce

Reduce[f[x] == 1/5, x]


But I get as result this inequality:

0 <= x <= 1/5 || x == 9/10

My question is, is there any possibility to get set of points containing these points from inequalities? It means to get as result:

{0,1/5,9/10}

• I’m not sure the answer you want is the actually the right answer. The Reduce[ ] function has it right, returning an interval for the one portion. Not seeing how {0, 1/5, 9/10} corresponds to the interval portion. – MikeY Dec 29 '18 at 15:41

I think an interpolation function of order 1 might be what you are looking for.

pts = {{0, 1/5}, {1/5, 1/5}, {1/2, 1}, {1, 0}};
f = Interpolation[pts, InterpolationOrder -> 1];
Plot[f[x], {x, 0, 1}] Then

f /@ Range[0, 1, 1/10]


{1/5, 1/5, 1/5, 7/15, 11/15, 1, 4/5, 3/5, 2/5, 1/5, 0}

Try

Cases[  0 <= x <= 1/5 || x == 9/10   , z_?NumericQ -> z, Infinity]
(*{0, 1/5, 9/10}*)


to get the numbers in your condition.

• Thank you, I have one more question, if I am looking for patterns for example of the set {11/15,1}, then using Reduce I get: x==2/5||x==19/30,x==1/2 and using Cases I get: {2/5,19/30,1/2} but I would like to get a set containing results for 11/15 and 1 in brackets like this {{2/5,19/30},{1/2}}. Do you thing its possible? – Nikol Š Dec 29 '18 at 12:51