2
$\begingroup$

I have the following test data, and I need to interpolate over these data. I attempted to use Interpolation. However, the interpolated data are not smooth enough. Is there any better way to interpolate my data?

a = Table[DATA[[i, 1]], {i, 1, 35}];
b = Table[DATA[[i, 2]], {i, 1, 35}]; 
xx = Interpolation[Transpose[{a, b}], InterpolationOrder -> 1];

{{1., 0.}, {1.3432, 57.4713}, {1.39448, 344.828}, {1.41026, 
  459.77}, {1.43195, 574.713}, {1.45168, 632.184}, {1.4714, 
  747.126}, {1.49901, 747.126}, {1.53057, 862.069}, {1.54832, 
  977.011}, {1.57791, 919.54}, {1.59763, 1034.48}, {1.61933, 
  1091.95}, {1.63708, 1149.43}, {1.6568, 1379.31}, {1.67258, 
  1551.72}, {1.69428, 1839.08}, {1.71992, 2126.44}, {1.73964, 
  2471.26}, {1.78107, 3103.45}, {1.7929, 3850.57}, {1.80868, 
  4540.23}, {1.81854, 5344.83}, {1.83235, 6206.9}, {1.84221, 
  7011.49}, {1.86193, 8045.98}, {1.87179, 10057.5}, {1.87771, 
  10747.1}, {1.88363, 11781.6}, {1.89546, 12988.5}, {1.89941, 
  14712.6}, {1.90335, 15517.2}, {1.9073, 16034.5}, {1.90927, 
  16781.6}, {1.91124, 17528.7}}
$\endgroup$
  • $\begingroup$ How are you using Interplation? $\endgroup$ – user21 Jun 7 '17 at 14:36
  • $\begingroup$ a = Table[DATA[[i, 1]], {i, 1, 35}]; b = Table[DATA[[i, 2]], {i, 1, 35}]; xx = Interpolation[Transpose[{a, b}], InterpolationOrder -> 1]; $\endgroup$ – user49047 Jun 7 '17 at 14:40
  • $\begingroup$ Please add this information to your post. Also add a comment about what it is that you got as a result and what you would have expected. $\endgroup$ – user21 Jun 7 '17 at 14:41
  • $\begingroup$ Interpolation will go through all the points, is that what you want? Or do you want a regression, i.e. a best fit to a model function? $\endgroup$ – Marius Ladegård Meyer Jun 7 '17 at 14:49
  • $\begingroup$ yes i need it to go thorough all the points as smooth as possible. $\endgroup$ – user49047 Jun 7 '17 at 14:56
3
$\begingroup$

this is fit (not interpolation) using a piecewise cubic function:

data = {{1.3432, 57.4713}, {1.39448, 344.828}, {1.41026, 
   459.77}, {1.43195, 574.713}, {1.45168, 632.184}, {1.4714, 
   747.126}, {1.49901, 747.126}, {1.53057, 862.069}, {1.54832, 
   977.011}, {1.57791, 919.54}, {1.59763, 1034.48}, {1.61933, 
   1091.95}, {1.63708, 1149.43}, {1.6568, 1379.31}, {1.67258, 
   1551.72}, {1.69428, 1839.08}, {1.71992, 2126.44}, {1.73964, 
   2471.26}, {1.78107, 3103.45}, {1.7929, 3850.57}, {1.80868, 
   4540.23}, {1.81854, 5344.83}, {1.83235, 6206.9}, {1.84221, 
   7011.49}, {1.86193, 8045.98}, {1.87179, 10057.5}, {1.87771, 
   10747.1}, {1.88363, 11781.6}, {1.89546, 12988.5}, {1.89941, 
   14712.6}, {1.90335, 15517.2}, {1.9073, 16034.5}, {1.90927, 
   16781.6}, {1.91124, 17528.7}}
np = 20
unk = Transpose[{Subdivide[Sequence @@ data[[{1, -1}, 1]], np - 1], 
    Table[Symbol["yi" <> ToString[i]], {i, np}]}];
NMinimize[(Interpolation[unk][data[[All, 1]]] - data[[All, 2]])^2 // 
   Total, unk[[All, 2]]];
fit = Interpolation[unk /. %[[2]]];

Show[{
  ListPlot[data],
  Plot[fit[x], {x, data[[1, 1]], data[[-1, 1]]}, PlotRange -> All]}]

enter image description here

As you see it aims to be a smooth approximation without attempting to hit every one of the scattered points.

Note I dropped the very first point from the data as it was too far outlying and messed up the fit.

$\endgroup$
  • $\begingroup$ it looks promising after x=1.34 but still i am missing good chunk of the data from 1:1.34. lets say n=100;a= Table[1 + (1.91124 - 1)/n*i, {i, 0, n}]; b = Table[fit[x], {x, a}]; then you will see it needs to extrapolate between 1:1.34 which are some ridiculous values. $\endgroup$ – user49047 Jun 8 '17 at 9:24
  • $\begingroup$ so collect more data.. seriously just do a linear interploation between the first two points. $\endgroup$ – george2079 Jun 8 '17 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.