Accurate Numerical Integration for unequally spaced data

7k Views Asked by At

I need to calculate numerical integration of unequally spaced data accurately. For equally spaced data, richardson extrapolation on romberg integral works quite well.

http://en.wikipedia.org/wiki/Romberg%27s_method#A_geometric_example

Besides I intend to use same on matlab, so any function implementing the same will be helpful.

2

There are 2 best solutions below

0
On

The trapezoid rule generalizes easily to unequally spaced data -- see Wikipedia.

A simple MATLAB function that takes the vectors $\textbf{x} = [x_1, x_2, \ldots, x_N]$ and $\textbf{y} = [f(x_1), f(x_2), \ldots, f(x_N)]$ is as follows:

function s = trapuneq(x, y)

% Input  - x: Vector of length N with the x-values of the data
%          y: Vector of length N with the y-values of the data
% Output - s: Approximation of the definite integral via the trapezoid rule

s = .5*sum((x(2:end) - x(1:end-1)).*(y(2:end) + y(1:end-1)));
0
On

I happened to see your question when doing an online search for this very issue. I have developed a FORTRAN code that computes such integrals by fitting parabolas to groups of three successive data points and accumulating areas under the parabolas across the data domain - sort of a generalized Simpson's rule. Seems quite accurate on both simulated and real data, the latter of which involved very rapidly-varying y(x). The only constraints are no degenerate points (i.e., no duplicate x-values), and the x-values must go in increasing order. Be happy to send the subroutine. My search was motivated by wondering if anybody had published such a routine; I was thinking it might make a contribution to a math education journal, but as I am a physicist I am not really familiar with that area of the literature. - Cameron Reed, Physics, Alma College, Michigan; [email protected]