# How to interpolate my results at discrete steps? [closed]

I have the results

{{{0, 10, 10}, {0.114129, 9, 10}, {0.115385, 11, 10}, {0.118755, 11, 9},
{0.160154, 10, 9}, {0.193103, 9, 9}, {0.194063, 8, 10}, {0.208447, 8, 9}
{0.235062, 7, 9}, {0.243287, 6, 9}, {0.248032, 5, 9}, {0.358482, 7, 9},
{0.393213, 7, 8}, {0.405397, 7, 7}, {0.461576, 6, 7}, {0.523134, 6, 6},
{0.635241, 6, 8}, {0.726211, 5, 8}, {0.829014, 4, 8}, {0.903913, 4, 7},
{1.32181, 6, 7}, {1.59651, 6, 6}, {1.64345, 6, 8}, {1.64803, 5, 8},
{1.65241, 5, 7}, {1.80486, 4, 7}, {1.97205,4, 6}, {2.78093, 4, 5},
{2.94957,4, 6}, {2.98843, 4, 6}, {3.1374,3, 6}, {3.44895, 2, 6},
{3.98122,2, 8}, {4.24663, 2, 10}, {4.45249, 2, 9}, {4.59911, 2, 9},
{5.14028, 3, 10}, {5.1964, 3, 12}, {5.20448, 3, 12}, {5.34628, 2, 13},
{5.39089, 2, 15}, {5.47021, 2, 16}, {5.49031, 2, 18}, {5.68693, 2, 18},
{5.90643, 3, 18}, {5.95821, 3, 17}, {6.04493, 4, 17}, {6.07941, 4, 16},
{6.18949, 4, 15}, {6.20035, 4, 14}, {6.31346, 4, 13}, {6.35271, 3, 13},
{6.58122, 3, 12}, {6.72382, 3, 11}, {6.74931, 3, 10}, {6.9862, 4, 11},
{7.11951,4, 10}, {7.17143, 3, 10}, {7.21791, 2, 11}, {7.33074, 2, 12},
{7.40083, 2, 11}, {7.43524, 4, 11}, {7.55296, 4, 10}, {7.62666, 3, 10},
{7.84643, 3, 9}, {8.0184, 3, 8}, {8.06468, 2, 8}, {8.11406, 2, 9},
{8.14889, 1, 9}, {8.27048, 0, 9}, {8.47532,0, 11}, {8.69576, 0, 13},
{8.97068, 1, 14}, {9.02658, 2, 14}, {9.08941, 2, 13}, {9.33396, 2, 13},
{9.50241, 2, 12}, {9.81107, 2, 13}, {9.86563, 2, 15}, {10.0441, 2, 14}},

{{0, 10, 10}, {0.00157025, 10, 9}, {0.0123142, 9, 9}, {0.0798253, 9, 8},
{0.0989871, 9, 7}, {0.159716, 8, 7}, {0.233333, 8, 6}, {0.284473, 9, 7},
{0.428241, 8, 7}, {0.566031, 8, 6}, {0.580869, 7, 6}, {0.59721, 6, 7},
{0.606727, 5, 7}, {0.650175,5, 6}, {0.784228, 5, 8}, {0.910743, 4, 8},
{1.04667, 4, 7}, {1.05059, 5, 7}, {1.11214, 4, 7}, {1.11664, 4, 6},
{1.11731, 6,6}, {1.34928, 5, 6}, {1.40728, 4, 6}, {1.51868, 4, 8},
{1.61049,4, 7}, {1.74908, 3, 7}, {1.79889, 3, 6}, {1.84876, 5, 6},
{2.18662,4, 6}, {3.0228, 4, 5}, {3.0609, 3, 5}, {3.10427, 3, 4},
{3.3269, 3, 6}, {3.38352, 3, 5}, {3.42096, 4, 5}, {3.57648, 3, 6},
{3.6044, 3, 8}, {3.82802, 3, 10}, {3.89249, 2, 10}, {4.03572, 4, 10},
{4.14792, 3, 10}, {4.29539, 3, 9}, {4.62608, 5, 9}, {4.67712, 7, 9},
{4.70763, 7, 8}, {4.8375, 6, 9}, {4.87401, 6, 8}, {4.99582, 6, 7},
{5.00558, 5, 7}, {5.03584, 5, 8}, {5.17234, 5, 7}, {5.26621,4, 8},
{5.49947, 4, 7}, {5.53808, 4, 6}, {5.63194, 4, 6}, {5.66884, 3, 6},
{5.79289, 3, 5}, {5.79674, 5, 5}, {5.93102, 5,4}, {6.04469, 5, 3},
{6.2474, 7, 3}, {6.32087, 8, 4}, {6.34615, 10, 4}, {6.45538, 9, 4},
{6.49163, 10, 5}, {6.49456, 9, 5}, {6.64491, 9, 4}, {6.72716, 10, 5},
{6.8513, 10, 4}, {6.86975, 9, 4}, {6.91351, 9, 3}, {7.48925, 8, 3},
{7.53343, 7, 3}, {7.7141, 9, 3}, {7.74821, 8, 3}, {7.82409, 10, 3},
{7.92441, 9, 3}, {8.03961, 8, 3}, {8.13332, 10, 3}, {8.2045, 9, 3},
{8.62925, 8, 3}, {8.7584, 7, 3}, {9.01221, 7, 2}, {9.18724, 9, 2},
{9.34235, 8, 2}, {9.44694, 7, 2}, {9.65845, 7, 4}, {9.67498, 6, 4},
{9.69573, 8, 4}, {9.76277, 10, 4}, {9.77852, 9, 4}, {9.80974, 8, 4},
{9.85812, 7, 4}, {9.91486, 9, 4}, {10.0656, 9, 6}},

{{0, 10, 10}, {0.0786173, 10, 9}, {0.159432, 9, 9}, {0.241794, 8, 10},
{0.285418, 7, 10}, {0.364088, 7, 9}, {0.393744, 7, 8}, {0.41457, 7, 7},
{0.437014, 7, 6}, {0.437701, 8, 5}, {0.596505,10, 5}, {0.846736, 10, 4},
{1.18815, 10, 3}, {1.34252, 9, 3}, {1.48486, 11, 3}, {1.55601, 13, 3},
{1.59653, 15, 3}, {1.66382, 14, 3}, {1.71571, 13, 3}, {1.83316, 14, 2},
{1.88043, 16, 2}, {1.88406, 18, 2}, {1.94665, 18, 1}, {2.50657, 17, 1},
{2.64969, 16, 1}, {2.70897, 18, 1}, {2.82536, 17, 1}, {3.12088, 19, 1},
{3.34407, 18, 1}, {3.40552, 19, 2}, {3.50199, 18, 2}, {3.60667, 17, 2},
{3.62172, 16, 2}, {3.64203, 15, 2}, {3.74326, 14, 2}, {3.76458, 13, 2},
{3.84473, 12, 2}, {3.88209, 11, 2}, {3.90626, 10, 2}, {3.97077, 9, 2},
{3.99447, 8, 2}, {4.10467, 8, 1}, {4.1746, 9, 2}, {4.17579, 8, 2},
{4.1864, 7, 2}, {4.74247, 8, 1}, {5.21633, 7, 1}, {5.91447, 6, 1},
{6.69129, 7, 0}, {7.45429, 9, 0}, {7.59871, 10, 1}, {7.6605, 9, 1},
{7.76442, 8, 1}, {7.93861, 9, 2}, {8.24453, 10, 3}, {8.39746, 10, 2},
{8.40362, 9, 2}, {8.4071, 10, 3}, {8.62252, 9, 3}, {8.77215, 9, 5},
{8.7814, 11,5}, {8.82388, 11, 4}, {8.86246, 10, 4}, {9.03635, 10, 3},
{9.06071, 9, 3}, {9.43662, 8, 3}, {9.50551, 7, 3}, {9.60883, 6,3},
{9.83946, 5, 3}, {9.92444, 4, 3}, {9.93336, 4, 5}, {9.93849, 4, 4},
{10.0484, 6, 4}}}


These triplets of results represents {time, amount in population1, amount in population2}, from a simulation that I repeated 3 times to get 3 realisations. As you can see, the times in my results are continuous, however, I wish to change them to discrete times, specifically (0, 0.01, 0.02, ..., 10), so I can compare each of the realisations.

So to make things a bit clearer the first few results of the first realisation would be

{0, 10, 10}, {0.01, 10, 10}, {0.02, 10, 10}, ...., {0.11, 10, 10},
{0.12, 11, 9}, {0.13, 11, 9}, and so on


How would I do this for all 3 realisations at once?

• – David G. Stork Mar 23 '18 at 12:37
• @george2079 yes, still struggling tbh – Mlo27 Mar 23 '18 at 15:16
• If I understand properly you really have two independent populations so you need to break the data into pop1={{0,10},{1.4,9},..{5,8}} and interpolate that.. – george2079 Mar 23 '18 at 15:27
• Yeah I have already split my populations up, but I struggling to actually interpolate the data. @george2079 – Mlo27 Mar 23 '18 at 15:31
• you need to show what you are doing. The default cubic interpolation gives pretty poor results by the way for so few points, you probably want InterpolationOrder -> 1 – george2079 Mar 23 '18 at 15:43

I believe you're looking for this:

popseries = {{0, 10, 10}, {1.4, 9, 11}, {2.5, 8, 12}, {3.1, 9, 11}, {5, 8, 12}}

populations[t_] := Select[popseries,
Function[u, u[[1]] <= t]
][[-1]][[{2, 3}]]

Table[Prepend[populations[t], t], {t, 0, 5}]


{{0, 10, 10}, {1, 10, 10}, {2, 9, 11}, {3, 8, 12}, {4, 9, 11}, {5, 8, 12}}

       data = Flatten[{{data[[All, All, {1, 2}]]}, {data[[All,
All, {1, 3}]]}}, 2];

iFun = Table[
Interpolation[data[[i]], InterpolationOrder -> 1], {i,
Length@data}];
τ = 0.1;
range = Table[Range[0, data[[i, -1, 1]], τ], {i, Length@data}];
data = Table[
Transpose@{range[[i]], Floor@iFun[[i]]@range[[i]]}, {i,
Length@data}];

ListLinePlot[data, Mesh -> Full, MeshStyle -> {Red, PointSize[0.005]},
InterpolationOrder -> 0, PlotTheme -> "Detailed", Frame -> True]


You can change $\tau$ whatever time step you need.

You can remove InterpolationOrder -> 0 in ListLinePlot[] to get

BTW, it is not a good idea to store data as {time, amount in population1, amount in population2}, instead store it as {time1, amount in population1}, {time2 ,amount in population1},...,{time_n ,amount in population1} and do the same thing for pop2.