Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

tmin=1;
tmax=6;
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

share|improve this question
    
Your variables tmin and tmax are not defined, can you edit your post so that these have values? –  tom Aug 13 '13 at 12:49
add comment

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

share|improve this answer
    
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? –  user9022 Aug 13 '13 at 13:02
2  
@user9022 InterpolationOrder -> 0 –  rm -rf Aug 13 '13 at 13:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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