# Definite integral over set of data

I have a list of data (acceleration) and I want to compute the displacement (so I have to integrate twice). A small part of the data is shown below:

{{0.38, 0.04}, {0.4, 0.105}, {0.42, 0.114}, {0.44, 0.065}, {0.46, 0.044},
{0.48, 0.023}, {0.5, 0.021}, {0.52, 0.019}, {0.54, -0.039}, {0.56, -0.074},
{0.58, -0.011}, {0.6, 0.058}, {0.62, 0.028}, {0.64, -0.102}, {0.66, -0.113},
{0.68, -0.047}, {0.7, 0.049}, {0.72, 0.01}, {0.74, -0.04}, {0.76, -0.025},
{0.78, 0.058}, {0.8, 0.072}, {0.82, -0.065}, {0.84, -0.107}, {0.86,0.032},
{0.88, 0.169}, {0.9, 0.099}, {0.92, -0.048}, {0.94, -0.065}, {0.96, 0.036},
{0.98, 0.045}}


Lets say the data is the discrete form of a function $f(t)$ and the displacements data that I want to obtain are the discrete equivalent of $F(t)$.

The data can't be fitted as you can see into a a typical function so I have to use Interpolation. I want to evaluate the integral at certain points, basically I want to find out the value of $F(t)$ over certain values $t$, the same $t$ that I have in the original list of data. Using Integrate will only allow me to compute the area under $f(t)$ over a range, Integrate with Interpolation will not give me the definite integral of the function. What should I use in this case and what can be done?

Thank you.

## 3 Answers

Assuming the initial velocity is zero:

accdata = {{0.38, 0.04}, {0.4, 0.105}, {0.42, 0.114}, {0.44, 0.065},
{0.46, 0.044}, {0.48, 0.023}, {0.5, 0.021}, {0.52, 0.019}, {0.54, -0.039},
{0.56, -0.074}, {0.58, -0.011}, {0.6, 0.058}, {0.62, 0.028}, {0.64, -0.102},
{0.66, -0.113}, {0.68, -0.047}, {0.7, 0.049}, {0.72, 0.01}, {0.74, -0.04},
{0.76, -0.025}, {0.78, 0.058}, {0.8, 0.072}, {0.82, -0.065}, {0.84, -0.107},
{0.86, 0.032}, {0.88, 0.169}, {0.9, 0.099}, {0.92, -0.048}, {0.94, -0.065},
{0.96, 0.036}, {0.98, 0.045}};

pos = Derivative[-2][Interpolation[accdata, InterpolationOrder -> 1]][t] // Head
pos["ValuesOnGrid"]
(*
InterpolatingFunction[{{0.38, 0.98}}, <>]
{0., 0.0000123333, 0.0000629333, 0.000155267, 0.000275467,
0.000413267, 0.000561533, 0.0007182, 0.000878733, 0.0010252,
0.0011486, 0.001268, 0.001404, 0.00154453, 0.0016522, 0.0017198,
0.0017706, 0.001832, 0.00189667, 0.00194967, 0.0019972, 0.00206333,
0.0021482, 0.0022134, 0.00224787, 0.002295, 0.00239593, 0.00253133,
0.0026562, 0.00276293, 0.00287793}
*)


There is also the problem of whether the time strictly runs between the end points of the interval 0.38 <= t <= 0.98 and how much weight the endpoints should get in the integration.

data = {{0.38, 0.04}, {0.4, 0.105}, {0.42, 0.114}, {0.44, 0.065},
{0.46, 0.044}, {0.48, 0.023}, {0.5, 0.021}, {0.52,
0.019}, {0.54, -0.039}, {0.56, -0.074}, {0.58, -0.011}, {0.6,
0.058}, {0.62,
0.028}, {0.64, -0.102}, {0.66, -0.113}, {0.68, -0.047}, {0.7,
0.049}, {0.72, 0.01}, {0.74, -0.04}, {0.76, -0.025}, {0.78,
0.058}, {0.8, 0.072}, {0.82, -0.065}, {0.84, -0.107}, {0.86,
0.032}, {0.88, 0.169}, {0.9,
0.099}, {0.92, -0.048}, {0.94, -0.065}, {0.96, 0.036}, {0.98,
0.045}};

f = Interpolation[data];

times = data[[All, 1]];

{tmin, tmax} = MinMax[times];

fi = Interpolation[{#, Integrate[f[t], {t, tmin, #}]} & /@ times];

fii = Interpolation[{#, Integrate[fp[t], {t, tmin, #}]} & /@ times];

Plot[{fi[t], fii[t]}, {t, tmin, tmax},
PlotLegends -> Placed[{"Velocity", "Displacement"}, {.65, .7}]]


How about:

Transpose[{data[[;; , 1]], Accumulate[data[[;; , 2]]]}]


Yielding:

{{0.38, 0.04}, {0.4, 0.145}, {0.42, 0.259}, {0.44, 0.324}, {0.46,
0.368}, {0.48, 0.391}, {0.5, 0.412}, {0.52, 0.431}, {0.54,
0.392}, {0.56, 0.318}, {0.58, 0.307}, {0.6, 0.365}, {0.62,
0.393}, {0.64, 0.291}, {0.66, 0.178}, {0.68, 0.131}, {0.7,
0.18}, {0.72, 0.19}, {0.74, 0.15}, {0.76, 0.125}, {0.78,
0.183}, {0.8, 0.255}, {0.82, 0.19}, {0.84, 0.083}, {0.86,
0.115}, {0.88, 0.284}, {0.9, 0.383}, {0.92, 0.335}, {0.94,
0.27}, {0.96, 0.306}, {0.98, 0.351}}