Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
precise numerical integration

Subject: precise numerical integration

From: Marcio Barbalho

Date: 4 Jun, 2010 00:11:20

Message: 1 of 7

Hello dear friends...

I would to know if you know any other numerical integration method besides 'trapz' given x an y vectors:

Area = trapz(x,y)

my data are kind of randomic and I have obtained areas that are not so precise, numbers are not matching...So I was wondering if you could give some help on increasing the performance of matlab's numerical integrators.

Many thanks

Subject: precise numerical integration

From: us

Date: 4 Jun, 2010 01:17:20

Message: 2 of 7

"Marcio Barbalho" <marciobarbalho@live.com> wrote in message <hu9gb8$dvg$1@fred.mathworks.com>...
> Hello dear friends...
>
> I would to know if you know any other numerical integration method besides 'trapz' given x an y vectors:
>
> Area = trapz(x,y)
>
> my data are kind of randomic and I have obtained areas that are not so precise, numbers are not matching...So I was wondering if you could give some help on increasing the performance of matlab's numerical integrators.
>
> Many thanks

well...
not even ML has the magic wand that turns your bad data into good data...
unless, of course, you use one of its many powerful interpolators - which, however, will make things even worse...

us

Subject: precise numerical integration

From: Roger Stafford

Date: 4 Jun, 2010 01:54:04

Message: 3 of 7

"Marcio Barbalho" <marciobarbalho@live.com> wrote in message <hu9gb8$dvg$1@fred.mathworks.com>...
> Hello dear friends...
>
> I would to know if you know any other numerical integration method besides 'trapz' given x an y vectors:
>
> Area = trapz(x,y)
>
> my data are kind of randomic and I have obtained areas that are not so precise, numbers are not matching...So I was wondering if you could give some help on increasing the performance of matlab's numerical integrators.
>
> Many thanks

  It all depends on what you mean by "randomic". As Urs says, there is no magic wand to make good data out of bad. If your data is bad because it is noisy, then trapz results are about as good as you are going to get.

  On the other hand if your data is comparatively free of noise and is accurately obtained from a function which is smoothly varying, meaning that it's higher derivatives are not excessively large, then there is hope for better accuracy from higher order integration methods.

  There are a number of these in the file exchange, including one I wrote which does cubic type approximation, but they all require that the discrete data be derived from smooth functions. Mine approximates the integral over each interval using the two endpoints of the interval and two other points at the ends of the two adjacent intervals. It computes the integral a cubic polynomial would have over the central interval if it runs through all four points. However the size of the inevitable error it makes depends on how large the underlying function's fourth derivative is, based on the mean value theorem of calculus. For trapz the mean value theorem expresses the error in terms of its second derivative.

Roger Stafford

Subject: precise numerical integration

From: Marcio Barbalho

Date: 4 Jun, 2010 01:56:04

Message: 4 of 7

"us " <us@neurol.unizh.ch> wrote

> well...
> not even ML has the magic wand that turns your bad data into good data...
> unless, of course, you use one of its many powerful interpolators - which, however, will make things even worse...
>

No, that was not my point. I can't change the data, nor should I. What I am trying to find is an alternative integrator to 'trapz'.

Many thanks

Subject: precise numerical integration

From: us

Date: 4 Jun, 2010 02:15:07

Message: 5 of 7

"Marcio Barbalho" <marciobarbalho@live.com> wrote in message <hu9mfj$rhl$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote
>
> > well...
> > not even ML has the magic wand that turns your bad data into good data...
> > unless, of course, you use one of its many powerful interpolators - which, however, will make things even worse...
> >
>
> No, that was not my point. I can't change the data, nor should I. What I am trying to find is an alternative integrator to 'trapz'.
>
> Many thanks

i guess you missed my point a bit:
whichever integrator you're using, it will have to deal with your data, which, as you said yourself, is messy...
hence, as john d'errico usually says at this point: garbage in, garbage out... no matter what box is in between...

however, there are many other ML integrators available, see roger stafford's reply...

us

Subject: precise numerical integration

From: Roger Stafford

Date: 4 Jun, 2010 03:04:04

Message: 6 of 7

"Marcio Barbalho" <marciobarbalho@live.com> wrote in message <hu9mfj$rhl$1@fred.mathworks.com>...
> No, that was not my point. I can't change the data, nor should I. What I am trying to find is an alternative integrator to 'trapz'.

  To expound further upon the point Urs and I have been making about your data, Marcio, even though the data may have been determined very accurately from some hypothetical infinite continuum source of data, it can only be a discrete representation of that source. All the points between each of the discrete points are missing, and yet by definition what calculus defines as an integral depends, not just on those discrete points, but on all the points in between. For that reason, no integration routine that depends only on discrete data can ever give you a perfectly accurate answer. The error it is bound to make depends on the nature of that infinitude of points that were left out.

  The use of discrete quadrature routines is based purely on the ability of the known discrete points to predict something of the probable values of those that are missing. If your source has rather a smooth nature where its derivatives are reasonably well-behaved, there is something to be gained in using higher order routines. If the source is very unruly so that such prediction is inaccurate, then you are better off using the simpler routines such as trapz which does only first order approximation.

  You will notice that the above argument in no way casts aspersions on the data-gathering process itself, which may have been excellent. It states only that something is inherently being lost in the attempt to represent a continuum of data with a discrete representation.

Roger Stafford

Subject: precise numerical integration

From: John D'Errico

Date: 4 Jun, 2010 03:25:06

Message: 7 of 7

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hu9qf4$i9v$1@fred.mathworks.com>...
> "Marcio Barbalho" <marciobarbalho@live.com> wrote in message <hu9mfj$rhl$1@fred.mathworks.com>...
> > No, that was not my point. I can't change the data, nor should I. What I am trying to find is an alternative integrator to 'trapz'.
>
> To expound further upon the point Urs and I have been making about your data, Marcio, even though the data may have been determined very accurately from some hypothetical infinite continuum source of data, it can only be a discrete representation of that source. All the points between each of the discrete points are missing, and yet by definition what calculus defines as an integral depends, not just on those discrete points, but on all the points in between. For that reason, no integration routine that depends only on discrete data can ever give you a perfectly accurate answer. The error it is bound to make depends on the nature of that infinitude of points that were left out.
>
> The use of discrete quadrature routines is based purely on the ability of the known discrete points to predict something of the probable values of those that are missing. If your source has rather a smooth nature where its derivatives are reasonably well-behaved, there is something to be gained in using higher order routines. If the source is very unruly so that such prediction is inaccurate, then you are better off using the simpler routines such as trapz which does only first order approximation.
>
> You will notice that the above argument in no way casts aspersions on the data-gathering process itself, which may have been excellent. It states only that something is inherently being lost in the attempt to represent a continuum of data with a discrete representation.
>
> Roger Stafford

If your data is noisy, then it turns out that you don't
really want to use a high order interpolant to integrate.
Trapezoidal rule can actually be the best choice under
some circumstances.

John

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us