# Integrating non uniform grid data from an accelerometer

Is there a better method than the trapezoidal rule as outlined here?

P.S. not familiar with the site, sorry if this has the wrong tag.

• If this doesn't get an answer here, it might receive a better answer on cs.stackexchange.com . It should also be asked on the Q&A forum rather than the meta forum. I will migrate it to the main site – robjohn Mar 27 '13 at 19:49
• @mathisnotmyforte: Why can't you use the Trapezoidal Rule? Anyway, the site also lists several alternates like Rectangle method, Simpson's rule, Romberg's method, Newton–Cotes formulas and Gaussian quadrature. Is there something peculiar with what you are trying to solve that is troubling? – Amzoti Mar 28 '13 at 1:40
• Amzoti, I'm trying to integrate data collected from an android accelerometer. Since there is no way to collect it at equal intervals, I have to use the Trapezoidal rule for non uniform grids; however the downside of this approach is that it's not as accurate as I would ideally want it to be. As for the other formulas you mentioned, I was under the impression that they were for uniformed grids only (?). – mathisnotmyforte Mar 28 '13 at 6:18

I'd have to understand the nature of the data and how you expect that data to behave, but in principle, you could use a modified Simpson's Rule. The difference here is that you have to perform a quadratic interpolation for every triplet of points. That is, given a triplet of data $(x_{2 i-1},y_{2 i-1}), (x_{2 i},y_{2 i}), (x_{2 i+1},y_{2 i+1})$, where $i \in \{1,2,\ldots,N/2\}$ and $N$ is the number of data points, set
$$f_i(x) = a_i + b_i (x-x_{2 i}) + c_i (x-x_{2 i})^2$$
Plug in the triplet of data and solve for $a_i$, $b_i$, and $c_i$. Then integrate the resulting expression for $f_i(x)$ over $[x_{2 i-1},x_{2 i+1}]$:
$$\int_{x_{2 i-1}}^{x_{2 i+1}} dx \: f_i(x) = \frac{x_{2 i-1}-x_{2 i+1}}{6 (x_{2 i}-x_{2 i-1}) (x_{2 i}-x_{2 i+1})} \left[\left (-3 x_{2 i}^2 (y_{2 i-1}+y_{2 i+1})-2 x_{2 i-1} (x_{2 i+1} (y_{2 i}+y_{2 i-1}+y_{2 i+1})-x_{2 i} (y_{2 i-1}+2 y_{2 i+1}))\right) \\ \left (+2 x_{2 i} x_{2 i+1} (2 y_{2 i-1}+y_{2 i+1})+x_{2 i-1}^2 (y_{2 i}-y_{2 i+1})+x_{2 i+1}^2 (y_{2 i}-y_{2 i-1})\right)\right]$$