Re: Compute area between curves [message #62876 is a reply to message #62821] |
Tue, 14 October 2008 04:26   |
jameskuyper
Messages: 79 Registered: October 2007
|
Member |
|
|
mystea wrote:
> Hi everyone,
>
> I am also working on a topic where I need to numerically calculate an
> integral
> of a tabulated function. However, what I need is an indefinite
> integral, namely,
> the area under a curve as a function of x-coordinate.
You can't calculate the true indefinite integral using numerical
methods; that's something that can only be done by using a symbolic math
program like Mathematica.
> The procedure int_tabulated only calculates the definite integral,
> given tabulated
> f and its x-coordinates x. Let's say both f and x are double array of
> length nl.
>
> I tried the following fix:
>
> integral=dblarr(nl)
> for i=1, nl-1 do integral[i]=int_tabulated(x[0:i],f[0:i])
What you're getting by this method is not the indefinite integral, but a
tabulation of definite integrals. This can represent the indefinite
integral, in much the same sense that your x and f arrays represent the
function you want to integrate, but it is not the indefinite integral
itself.
> I thought it will work but not quite! Turns out that in general, the
> result
> integral will not be monotone even if f are always positive.
That should not be the case for the true integral of a function that is
always positive, assuming that the x values are sorted.
However, numerical integration always produces no better than an
approximation. INT_TABULATED uses a " a five-point Newton-Cotes
integration formula", which is basically derived from fitting those five
points to a polynomial. The best-fit polynomial could go to negative
values within the range of integration, even if all of the data it is
being fitted to is positive; in that case, the integral could decrease
with increasing x, for some values of x. That seems unlikely, however,
if your function is tabulated with sufficient detail.
Could you give a simple example that demonstrates the problem you've seen?
|
|
|