2
$\begingroup$

This is probably a very silly question but I am trying to use Interpolation for the following data:

  data={{0.965251, 0.}, {3.0888, 0.}, {5.98456, 0.}, {9.26641, 0.}, {12.5483,
   0.}, {15.8301, 0.}, {18.1467, 0.}, {21.8147, 0.}, {26.2548, 
  0.}, {30.695, 1.12676}, {33.3977, 1.69014}, {36.8726, 
  2.53521}, {39.3822, 3.38028}, {42.8571, 3.94366}, {45.7529, 
  5.35211}, {48.8417, 6.76056}, {51.5444, 8.73239}, {54.0541, 
  10.9859}, {55.7915, 13.2394}, {58.1081, 16.9014}, {59.0734, 
  19.1549}, {61.0039, 22.8169}, {62.1622, 26.4789}, {63.3205, 
  30.4225}, {64.2857, 34.3662}, {65.0579, 38.3099}, {65.8301, 
  42.8169}, {66.7954, 47.8873}, {67.3745, 53.8028}, {68.3398, 
  60.5634}, {68.9189, 65.6338}, {69.112, 71.5493}, {69.6911, 
  78.0282}, {70.2703, 84.507}, {70.6564, 88.4507}, {70.6564, 
  92.3944}, {71.4286, 97.1831}, {72.5869, 100.563}, {73.7452, 
  98.3099}, {74.5174, 92.6761}, {74.7104, 87.3239}, {75.0965, 
  82.2535}, {75.2896, 77.4648}, {75.6757, 72.1127}, {76.0618, 
  63.3803}, {76.6409, 54.6479}, {77.027, 47.3239}, {77.4131, 
  40.}, {78.3784, 35.2113}, {78.5714, 29.8592}, {80.1158, 
  24.2254}, {81.4672, 22.2535}, {82.8185, 19.7183}, {84.3629, 
  18.8732}, {87.2587, 18.5915}, {91.6988, 18.8732}, {94.5946, 
  18.5915}, {98.2626, 18.3099}, {100., 18.3099}, {120., 18.3099}};

Interpolation[data]

but for some reason it does not Interpolated correctly. If I plot the data it looks fine. Can someone tell me why Interpolation doesn't correctly fit this data?

I get the following errro message:

InterpolatingFunction::dmval: Input value {0.00245143} lies outside the range of data in the interpolating function. Extrapolation will be used.

$\endgroup$
8
  • 1
    $\begingroup$ Probably has something to do with the error message, no? Or you don't get one? $\endgroup$
    – Michael E2
    Nov 22, 2020 at 1:15
  • $\begingroup$ @MichaelE2 yes! I just updated the question for you to see the error that I get $\endgroup$
    – John
    Nov 22, 2020 at 1:16
  • $\begingroup$ Hmm, I get "Interpolation::inddp: The point 70.6564` in dimension 1 is duplicated." $\endgroup$
    – Michael E2
    Nov 22, 2020 at 1:17
  • $\begingroup$ I was getting that too before. But the problem is that I don't really see any problem with the data that will make interpolation not to work $\endgroup$
    – John
    Nov 22, 2020 at 1:19
  • 1
    $\begingroup$ Sometimes Mathematica error messages are inscrutable, but here both are clear. Interpolation::inddp: The point 70.6564 in dimension 1 is duplicated. means you have two values for 70.6564 in data. Either nudge one by a small amount or drop one. InterpolatingFunction::dmval: Input value {0.00245143} lies outside the range of data in the interpolating function. Extrapolation will be used. is more a warning than an error: your data start at 0.965251 so when you ask for 0.00245143, Mathematica needs to extrapolate. It might work out fine, it might be catastrophically wrong. $\endgroup$
    – Chris K
    Nov 22, 2020 at 1:23

1 Answer 1

5
$\begingroup$

This is what happens when I drop the second value for 70.6564.

Show[
 ListPlot[data, PlotStyle -> Black],
 Plot[Evaluate@Interpolation[data][x], {x, 0, 120}, PlotRange -> All]
]

enter image description here

If those wiggles bother you, use linear interpolation instead:

Show[
 ListPlot[data, PlotStyle -> Black],
 Plot[Evaluate@Interpolation[data, InterpolationOrder -> 1][x], {x, 0, 120}, PlotRange -> All]
 ]

enter image description here

Or if you don't need the InterpolatingFunction to go exactly through the data, try this approach to regularised Interpolation.

$\endgroup$
1
  • 1
    $\begingroup$ Awesome! Christ thank you very much for your suggestion and also about the wiggles! This is what I wanted! I really appreciate it $\endgroup$
    – John
    Nov 22, 2020 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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