Search code examples
algorithmmathnonlinear-functions

How to divide area under a curve into equal segments


I am trying to divide the area under a curve given in tabulated form into equal area segments. I have to solve the following integral and find a set of points x_0,x_1,...,x_k,x_N for which the following holds

Unfortunately, I don't really see how to do that for a tabulated function. For an analytic linear or quadratic function the above results in solving a quadratic or cubic equation for x_k. I tried to iterate the value of x_k until the integral is less than k/N. I start with the first fixed value x_0 and try to find x_1 for which the integral is k/N, then use x_1 as the new lower limit and look for x_2 with the same property.
I assume that a much more efficient way to do this exists, this is why I decided to ask the experts here. I would appreciate your ideas.


Solution

  • There is no hope of getting exact correct answers without knowing a great deal more about function f(x). However, we could use a reasonable approximation to f(x) and use that, so our answers would also be reasonable approximations.

    One common approximation used in integration is the trapezoid rule, where we assume that the function is linear between consecutive values of x_i, so the area between those values is a trapezoid and easily calculated. So let's make the same approximation for f(x). Let's say the given points are (x[i], f(x[i])) and we are looking for x-coordinates z[i].

    An algorithm would then be (in pseudocode):

    Sort the values (x[i], f(x[i])) by the first coordinate
    if any of the neighboring x[i] are equal but the corresponding f(x[i]) are not:
        raise an error
    Sum the trapezoidal areas to get the total area
    Find the desired area between x-coordinates
    Run through the x[i] and sum individual trapezoid areas
        When the summed area are greater than the desired area,
            Use interpolation to find z[i] between the x[i] that give the desired area
    

    That should be clear enough. The interpolation will be a quadratic interpolation, which should be straightforward enough.