area problem (9.11.98)

Powerhouse Museum

How do I calculate the area under a curve in Maple when I haven’t got a formula but experimental data?

Please send response to newsgroup or directly to myself: (omit the nospam for the true address).

John Little (11.11.98)

There are any number of standard techniques from numerical analysis for this kind of calculation – they are called numerical quadrature rules. A simple, commonly used example of these methods is Simpson’s Rule. If you have an odd number n = 2k+1 of data points

          (x_1,f(x_1)), (x_2,f(x_2)), ... , (x_n, f(x_n)) 
with x_0 < x_1 < ... < x_n and with x_i - x_{i-1} = h for all i,

(i.e. the independent variable values are *equally spaced*) then the Simpson’s Rule approximation to the integral of f over the interval \([x_1,x_n]\) (the ”area under the curve” that you want) is

  (f(x_1) + 4f(x_2) + 2f(x_3) + 4f(x_4) + ... + 4f(x_{n-1}) + f(x_n))*h/3

(the 4’s and 2’s alternate in the summation). If you have the dependent variable values stored in a 1-dimensional array (or list) you can compute this in Maple by the following procedure (assuming \(n = 2k + 1\) is odd):

Here are two examples:

Another example showing close agreement with the actual value of an integral – data points sampled from the sin function at \(x = .1\) to \(.9\) at intervals of \(.1\):

For information on other similar methods, you can consult almost any textbook on numerical analysis. Hope this information is useful.

Michael Brennan (12.11.98)

All you need do is define a function, say \(f(x)\) using the experimental data. Then you can apply either the command simpson or trapezoid from the student package to find approximates to the area. Of course I am assuming the data you have is in the form of a table where the readings are taken repeatedly over a period of time.##e.g.

Suppose you are trying to find the area of a swimming pool where you are given the following measurements for the width of the pool, where the readings are taken every two metres.

Area of a Swimming Pool. First enter the data as a list.

We would require about 85 m^2 of material to cover pool.

Helmut Kahovec (13.11.98)

If you have a mathematical model then fit it to the data. If the regression is linear then see the online help page for stats[fit,leastsquare]. If the regression is nonlinear then see the article

     Fit for Anything? 
     The Maple Reporter, Summer 1998 Edition 
     pp. 6-7

You may download The Maple Reporter from Afterwards transform the fit into a procedure using unapply() and (numerically) integrate this procedure using evalf/Int.

If you don’t have a mathematical model then I would suggest using splines to convert the data points into a (piecewise defined) procedure. See the online help page for spline(). If you have many points then let the degree of the segment polynomials be 1 (i.e., use lines), otherwise use cubic splines. However, if there are 30+ data points, the calculation of the splines may take some time, anyway. Afterwards (numerically) integrate the piecewise defined procedure within each interval separately using evalf/Int and add these areas using add(). Below I give you two examples of this.

Second example:

If you don’t need the splines explicitly you may define a procedure that calculates the area from this list of data points at once:

Willard, Daniel (16.11.98)

Elementary calculus texts define integrals as the limit of a process of summing adjacent rectangles whose heights are the location of the left-hand ordinate (a data point), or the right-hand ordinate, or some average of the two. Simpson’s Rule. Trapezoidal interpolation.

Splines (cubic fits to successive sets of data points). See the math section of the CRC Handbook of Physics and Chemistry, or Abramowitz and Stegun Handbook of Mathematical Functions.