# Ploting a Piecewise function obtained from linear interpolation of points

I have no complains until Plot. g[x] seems good but Plot displays nothing. I need help. By advance Thanks

x[1] := 1; y[1] := 2;
x[2] := 2; y[2] := 3;
x[3] := 3; y[3] := 4;
x[4] := 4; y[4] := 1;
a = {x[1], y[1]};
b = {x[2], y[2]};
c = {x[3], y[3]};
d = {x[4], y[4]};
g[x_] := Piecewise[{
{Interpolation[{a, b}, InterpolationOrder -> 1], {a[[1]] <= x < b[[1]]}},
{Interpolation[{b, c}, InterpolationOrder -> 1], {b[[1]] <= x < c[[1]]}},
{Interpolation[{c, d}, InterpolationOrder -> 1], {c[[1]] <= x < d[[1]]}}}]
g[x]
Plot[g[x], {x, 1, 4}]

• Does g[x_] := Piecewise[{{Interpolation[{a, b}, InterpolationOrder -> 1][ x], a[[1]] <= x < b[[1]]}, {Interpolation[{b, c}, InterpolationOrder -> 1][x], b[[1]] <= x < c[[1]]}, {Interpolation[{c, d}, InterpolationOrder -> 1][x], c[[1]] <= x < d[[1]]}}] work?
– kglr
Jun 11, 2018 at 10:51
• Look at g[1] - as you can see, this is not correct Jun 11, 2018 at 10:52
• Why wouldn't you use g = Interpolation[{a,b,c,d}, InterpolationOrder->1] instead? Jun 11, 2018 at 13:52

g[x_] := Piecewise[{{Interpolation[{a, b}, InterpolationOrder->1]@x, a[[1]]<= x <b[[1]]},

Plot[Evaluate@g[x], {x, 1, 4}]