Message Boards Message Boards

GROUPS:

[✓] Implement a flat right interpolation?

Posted 1 month ago
276 Views
|
3 Replies
|
1 Total Likes
|

Hello, Ii am using Interpolation function with my table and I would like to implement a flat right interpolation; looking at the InterpolationOrder->0 it seems it does a flat left interpolation. Is there any method available to perform the flat right? thank you best regards

3 Replies

Wouldn't that just mean moving all your y values by one to the right?

valso=Transpose[{Range[10],Sin[0.3Range[10]]}];
fi=Interpolation[valso,InterpolationOrder->0]
vals=Transpose[{Range[10],RotateRight[Sin[0.3Range[10]]]}];
fi2=Interpolation[vals,InterpolationOrder->0]
Show[{Plot[{fi[x],fi2[x]},{x,1,10}],ListPlot[valso]}]

One way is to negate your x axis, interpolate to get f[x], and then use f[-x].

Example:

valList = {{0, 1}, {1, 3}, {2, 5}, {3, 2}, {4, 0}, {5, -1}};
if = Interpolation[valList, InterpolationOrder -> 0];

Plot[if[x], {x, 0, 5}]

enter image description here

But what (I think) you want is this.

if2 = Interpolation[Map[{-1, 1}*# &, valList], 
   InterpolationOrder -> 0];

Plot[if2[-x], {x, 0, 5}]

enter image description here

Thank you It works P

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