Hi,
I have some experimental data (vectors x,y) and I've estimated the area under the curve via the trapezoid method (A = trapz(y,x))
The question is, how can I determine the error of this calculation? Is there a Matlab function that can estimate it?
Thanks a lot..
No products are associated with this question.
Thanks, the thing is, I don't really have a continues data function. My data is discrete. I only have 350 data points (x,y) with intervals of dx = 0.5, so I can't change my samplings.
In that case, then why not regard the error as zero? One of the infinitely many continuous functions that connect your x,y points is the one that connects them piece-wise linearly, and trapz(y,x) is its exact, error-free integral. If there's nothing stopping you from assuming your discrete samples came from this piece-wise linear function, then voila, you're done, and your area calculation was perfect!
As Matt J has indicated with his reference to
http://en.wikipedia.org/wiki/Trapezoidal_rule#Error_analysis
the error can be estimated in terms of the second derivative of your data function and the widths of your trapezoidal intervals. You can estimate the second derivative in terms of the typical second finite differences in the data divided by the square of the interval widths.
Well, that depends on how closely-spaced your intervals are in relation to the magnitude of higher derivatives. As an example I computed the integral of sin(x) from 0 to pi where the exact answer would be 2. Admittedly with matlab doing the computations the data is very precise and therefore the second differences are accurate. I divided that range into first 6 intervals and then 100 intervals. Here are the results:
6 intervals actual error by trapz - 0.04590276668629 est. error, 2nd diff. - 0.04363323129986
100 intervals actual error by trapz - 0.00016449611255687 est. error, 2nd diff. - 0.00016446634993921
In each case the estimated error is fairly accurate percentage-wise. However in the second case the data has to be very accurate to achieve this with second differencing.
The remedy when data is not sufficiently accurate is to widen the span of the area used to estimate the second derivative using appropriate filters such as those obtained from the second derivative of a normal density distribution with appropriately selected standard deviation.
That is a different question from that of the accuracy of the error estimation. My point above was that estimating the trapz error with second differences is particularly sensitive to noise in data and in such cases the estimates can be made more accurate by increasing the span of points used to estimate second derivatives. If you look at the curve of the second derivative of a normal distribution, you will see how a filter can be designed to cover a span of several points in making such an estimate.
As to the question of comparing trapz with other possible methods of integration for discrete data, if the data is noisy probably trapz is the best method to use, precisely because its error depends only on the second derivative. For accurate, smooth data, other methods using higher order approximation are superior in accuracy. You will find several of these in the File Exchange.
0 Comments