0

I'm trying to set up an InterpolatingFunction, that would be a step function. I have a series of x and f values. I took an example from the Mathematica documentation (under InterpolationOrder) and it doesn't work the way I expected. The example itself shows what I expected. But making a function out of that data does not do what I expect.

data = {{0, 0}, {1, 2}, {3, 4}, {4, 2}, {6, 0}};
ListLinePlot[data, InterpolationOrder -> 0] 

This produced picture of a step function showing what I expected. However when I used that same data and made a function I got something unexpected.

f=Interpolation[data, InterpolationOrder->0]
f[0] gave me 2, not 0
f[1] also gave me 2 (which I expected)
f[1.1] gave me 4

Am I doing something wrong? I want f[x] to be 2 for 1 <= x < 3

EDIT The answer from ArgentoSapiens in How can the behavior of InterpolationOrder->0 be controlled? fixes my problem.

Mitchell Kaplan
  • 3,696
  • 22
  • 34

0 Answers0