I have a list of data (measured per day) that I want to use as imput for another equation (say f). The problem is that the input I need for f needs to be a continuous function of time. Is it possible to change my data into a function? I would either like a function that is linear increasing or decreasing between the different timesteps (like the line you get when you use Joined in ListPlot) or a stepwise function that immediately jumps to another value the next day.

I tried using Interpolate but then when I measured 0, I get negative values which is not possible for my measured values.

Hope someone could help me.

Simplified example:

data = {{1, 3}, {2, 0}, {3, 0}, {4, 5}, {5, 7}, {6, 10}};
ListPlot[data, AxesLabel -> {"time(day)", "data(mm)"}, Joined -> True]

f = Interpolation[data];
Plot[Evaluate[f[t]], {t, tmin, tmax}]

If you evaluate this: the first plot is the result I would prefer for my function, the second plot is not what I want as the values drop below 0.

enter image description here

  • $\begingroup$ Your variables tmin and tmax are not defined, can you edit your post so that these have values? $\endgroup$
    – tom
    Commented Aug 13, 2013 at 12:49

1 Answer 1

data = {{1, 3}, {2, 0}, {3, 0}, {4, 5}, {5, 7}, {6, 10}};
f = Interpolation[data, InterpolationOrder -> 1];
GraphicsRow[{Plot[f[t], {t, 1, 6}, AxesOrigin -> {-1, -1}], 
             ListPlot[data, Joined -> True, AxesOrigin -> {-1, -1}]}]

Mathematica graphics

  • $\begingroup$ Thanks for your quick answer! So interpolation order 1 makes the function lineair. Is there also an option to make the interpolation stepwise or is this not possible? $\endgroup$
    – Wiebe
    Commented Aug 13, 2013 at 13:02
  • 2
    $\begingroup$ @user9022 InterpolationOrder -> 0 $\endgroup$
    – rm -rf
    Commented Aug 13, 2013 at 13:16

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.