# Obtaining points with equal spacing from interpolated data

Beginning with five ordered pairs I made an interpolation, obtaining an a polynomial expression.

I got several other points with equal spacing from the polynomial expression. Are there any commands more specific to doing this operation?

Here is my code.

data = {{0, 0}, {12, 25}, {27, 52}, {33, 45}, {42, 31}};
eq = Fit[data, {1, x, x^2, x^3, x^4}, x];
xPoint = Range[0, 50, 2];
yPoint = Table[eq, {x, xPoint}];
positions = Transpose[{xPoint, yPoint}];
ListPlot[positions]

• – LCarvalho Sep 24 '16 at 20:36

You can start by simplifying the code:

data = {{0, 0}, {12, 25}, {27, 52}, {33, 45}, {42, 31}};

eq = Fit[data, {1, x, x^2, x^3, x^4}, x];

ListPlot[Transpose[{Range[0, 50, 2],
Table[eq, {x, Range[0, 50, 2]}]}]]

• You haven't defined xPoint. – C. E. Sep 24 '16 at 21:17
• Now yes is helpful. Unfortunately came too late. – JPeter Sep 26 '16 at 19:39

I am assuming you want the interpolated points for further processing, because there is little reason to make the interpolation otherwise. I would proceed as follows:

1. I get the fitted polynomial as function f. I use Block to protect the variable x from any previous assignment.

data = {{0, 0}, {12, 25}, {27, 52}, {33, 45}, {42, 31}};
Block[{x}, f[x_] = Fit[data, {1, x, x^2, x^3, x^4}, x]];

2. I compute the points directly in a table.

pts = Table[{i, f[i]}, {i, 0, 50, 2}];

3. I plot the interpolated points along with the data to check my work.

ListPlot[pts, Prolog -> {Red, AbsolutePointSize, Point[data]}] The extrapolation of the data beyond 42 is suspect.

• Extrapolation was on purpose – JPeter Sep 24 '16 at 22:01
• @user43142. I don't doubt it, but the extrapolation is simply not trustworthy unless you have some reason beyond the five data points to expect the sharp upward turn beyond 42. – m_goldberg Sep 24 '16 at 22:07

Table is enough:

Table[{x, eq}, {x, 1, 50, 2}] // ListPlot If your intention is to plot the points then you can also use Mesh:

data = {{0, 0}, {12, 25}, {27, 52}, {33, 45}, {42, 31}};
eq = Fit[data, {1, x, x^2, x^3, x^4}, x];

pl = Plot[
Evaluate[eq], {x, 0, 50},
PlotStyle -> None,
MeshStyle -> Directive[PointSize[Medium], ColorData],
Mesh -> 25
] You can also retrieve the actual points like this:

Cases[Normal[pl], Point[pts_] :> pts, Infinity]


although this is a roundabout way to get the points, not really simpler than what you used. However, as described here, this could be the way to go if you want to generate points that are equally spaced along the curve rather than equally spaced on the x axis.