Message Boards Message Boards

0
|
3533 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Getting the values of the Interpolation output?

Posted 3 years ago

Hi,

How do I get the output of the interpolation as a list?

 data = {3.4`, 5.4`, 1.4`, 8.`, "NaN", "NaN", "NaN", 10.2`, 
  "NaN", 15.4`, 0.`, 6.7`, 0.2`, 2.`}


ListLinePlot[data]

 int = 
 Interpolation[
  Select[Transpose[{Range[Length[data]], data}], NumericQ[Last[#]] &],
   InterpolationOrder -> 1]


 Plot[int[\[FormalX]], {\[FormalX], 1., 14.}]
POSTED BY: Alex Teymouri
3 Replies
Posted 3 years ago

They are not the same because data is not passed to Interpolation. The Select eliminates NaN values including the last two. That accounts for the difference in length. Try the following and you will see a warning about extrapolation.

dataNEW = Table[int[x], {x, 1, 26}]
POSTED BY: Rohit Namjoshi

Dear Rohit,

I noticed that this method can't be used when we have missing data at the end of the main list. The Length of data and dataNEW is not the same. Is there any way to use interpolation and extrapolation for a list simultaneously?

data = {0.`, 0.`, 0.`, 0.`, 0.`, 0.`, 0.`, 0.`, 0.`, 0.`, 0.`, 5.8`, 
   0.`, 0.8`, 0.`, 0.`, "NaN", "NaN", "NaN", 7.7`, 6.2`, 0.`, 0.`, 
   0.`, "NaN", "NaN"};

ListLinePlot[data, PlotRange -> All]

int = Interpolation[
  Select[Transpose[{Range[Length[data]], data}], NumericQ[Last[#]] &],
   InterpolationOrder -> 1]

dataNEW = Table[int[x], {x, 1, 24}]

Length /@ {data, dataNEW}
POSTED BY: M.A. Ghorbani
Posted 3 years ago

Hi Alex,

Maybe I am misunderstanding your question, bit isn't it just

Table[int[x], {x, 1, 14}]

ListLinePlot[{Table[int[x], {x, 1, 14}], data},
 PlotStyle -> {Directive[Blue], Automatic},
 Mesh -> All]

enter image description here

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract