IntegrateData - Maple Help

SignalProcessing

 IntegrateData
 calculate the area under a 1-D data set

 Calling Sequence IntegrateData( X, Y, options ) IntegrateData( Y, options ) IntegrateData( XY, options )

Parameters

 X - One-dimensional rtable or list of independent data values. Y - One-dimensional rtable or list of dependent data values. XY - Two-dimensional rtable or list of independent and dependent data values, with each row representing a single point.

Options

 • method : One of leftendpoint, rightendpoint, simpson, and trapezoid. The default is trapezoid.
 • sortdata : Either true or false, this specifies whether to sort the data when both independent and dependent values are provided. The default is true.
 • step : Positive numeric value, this specifies the uniform step size when only dependent data values are provided. The default is 1.0.

Description

 • The IntegrateData command approximates the area beneath a 1-D data set using the specified method.
 • For the IntegrateData(X,Y) calling sequence, X and Y must be of the same size. Note that the independent data values do not need to be uniformly-spaced. For method=simpson, the independent data values are required to be unique, but the other methods have no such restriction.
 • For the IntegrateData(X,Y) calling sequence, if sortdata=true then the values in X will be sorted in increasing order, and the values in Y will be sorted accordingly. If sortdata=false, on the other hand, the onus is on the user to ensure that the data is sorted. Caution: If sortdata=false and the data is in fact not sorted or unique, then the result may be unreliable, and when method=simpson, the result may be HFloat(undefined).
 • The IntegrateData(XY) calling sequence is reduced to the IntegrateData(X,Y) calling sequence by taking X and Y to be, respectively, the first and second columns of XY. Similarly, the IntegrateData(Y) calling sequence is reduced to the IntegrateData(X,Y) calling sequence by taking X to be the Vector of size numelems(Y) with elements X[i]=i*step. Note that the sortdata option has no effect in this case.
 • If the number of data points is 1, then the result will be HFloat(0.0). Passing an empty rtable/list will result in an error.
 • When method is not simpson, IntegrateData can integrate data representing piecewise-continuous expressions. To this end, the x-value for a jump discontinuity can be listed twice in X, with the dependent values on the left and right included, in order, in Y. See below for an example.
 • When method=leftendpoint, the following formula is used:

$\mathrm{IntegrateData}\left(X,Y\right)={\sum }_{i=2}^{n}\left({X}_{i}-{X}_{i-1}\right){Y}_{i-1}$

 where $n=\mathrm{numelems}\left(X\right)$. That is, the area is approximated by using rectangles of height determined by the left-endpoint of each sub-interval. The above assumes that the values in X have already been sorted.
 • When method=rightendpoint, the following formula is used:

$\mathrm{IntegrateData}\left(X,Y\right)={\sum }_{i=2}^{n}\left({X}_{i}-{X}_{i-1}\right){Y}_{i}$

 where $n=\mathrm{numelems}\left(X\right)$. That is, the area is approximated by using rectangles of height determined by the right-endpoint of each sub-interval. The above assumes that the values in X have already been sorted.
 • When method=trapezoid, the following formula is used:

$\mathrm{IntegrateData}\left(X,Y\right)={\sum }_{i=2}^{n}\frac{\left({X}_{i}-{X}_{i-1}\right)\left({Y}_{i-1}+{Y}_{i}\right)}{2}$

 where $n=\mathrm{numelems}\left(X\right)$. That is, the area is approximated by using trapezoids over each sub-interval, which is equivalent to finding the area beneath a piecewise-linear interpolation. The above assumes that the values in X have already been sorted.
 • When method=simpson, the formula for Simpson's Composite Method for irregularly-spaced data is used. See references below. The full formula is omitted here for brevity, but it is derived using quadratic interpolants for data points in adjacent sub-intervals. The method requires three or more data points.
 • There are a few internal procedures which are first compiled in a session under certain circumstances when the number of data points is larger than 10^5. When this happens, there may be a slight delay in returning the result. Subsequent executions will use the compiled versions of these internal procedures, and not have this delay, even when the number of data points is not larger than 10^5.
 • Any input rtable/list is converted to an rtable of float[8] datatype, and an error will be thrown if this is not possible. For this reason, it is most efficient for any input to already be an rtable having the appropriate datatype. Note: The rtables cannot have an indexing function, and they need to have rectangular storage.
 • The IntegrateData command is not thread safe.
 • As the underlying implementation of the SignalProcessing package is a module, it is also possible to use the form SignalProcessing:-IntegrateData to access the command from the package. For more information, see Module Members.

Examples

 > $\mathrm{with}\left(\mathrm{SignalProcessing}\right):$

Example 1

 • Consider the following (unsorted) independent and dependent data:
 > $\mathrm{XY}≔\mathrm{Matrix}\left(\left[\left[3,9\right],\left[2.5,4\right],\left[1,1\right]\right]\right)$
 ${\mathrm{XY}}{≔}\left[\begin{array}{cc}{3}& {9}\\ {2.5}& {4}\\ {1}& {1}\end{array}\right]$ (1)
 • The (default) Trapezoid Method gives the following for the appropriate integral:
 > $\mathrm{z1}≔\mathrm{IntegrateData}\left(\mathrm{XY},\mathrm{sortdata}=\mathrm{true},\mathrm{method}=\mathrm{trapezoid}\right)$
 ${\mathrm{z1}}{≔}{7.}$ (2)
 • The independent data is in reverse order, so if we choose to not sort, we get the negative of the previous answer:
 > $\mathrm{z2}≔\mathrm{IntegrateData}\left(\mathrm{XY},\mathrm{sortdata}=\mathrm{false},\mathrm{method}=\mathrm{trapezoid}\right)$
 ${\mathrm{z2}}{≔}{-7.}$ (3)
 • If we omit the independent data and instead use a uniform spacing of 2.0, we get the following:
 > $\mathrm{z3}≔\mathrm{IntegrateData}\left(\mathrm{XY}\left[..,2\right],\mathrm{method}=\mathrm{trapezoid},\mathrm{step}=2.0\right)$
 ${\mathrm{z3}}{≔}{18.}$ (4)

Example 2

 • The following data could result from a step function:
 > $X≔⟨-10,0,0,10⟩$
 ${X}{≔}\left[\begin{array}{c}{-10}\\ {0}\\ {0}\\ {10}\end{array}\right]$ (5)
 > $Y≔⟨2,2,4,4⟩$
 ${Y}{≔}\left[\begin{array}{c}{2}\\ {2}\\ {4}\\ {4}\end{array}\right]$ (6)
 > $\mathrm{dataplot}\left(X,Y,\mathrm{view}=\left[-10..10,0..5\right],\mathrm{thickness}=3\right)$
 • The independent data values are not unique, but that is allowed except when Simpson's Method is used:
 > $\mathrm{IntegrateData}\left(X,Y,\mathrm{method}=\mathrm{trapezoid},\mathrm{sortdata}=\mathrm{false}\right)$
 ${60.}$ (7)

Example 3

 • Consider the following signal over the given time interval:
 > $\mathrm{signal}≔t↦5+\mathrm{sin}\left(t\right)+0.1\cdot \mathrm{sin}\left(3\cdot t\right)+0.01\cdot \mathrm{sin}\left(5\cdot t\right)$
 ${\mathrm{signal}}{≔}{t}{↦}{5}{+}{\mathrm{sin}}{}\left({t}\right){+}{0.1}{\cdot }{\mathrm{sin}}{}\left({3}{\cdot }{t}\right){+}{0.01}{\cdot }{\mathrm{sin}}{}\left({5}{\cdot }{t}\right)$ (8)
 > $\mathrm{t1}≔0.$
 ${\mathrm{t1}}{≔}{0.}$ (9)
 > $\mathrm{t2}≔10.0$
 ${\mathrm{t2}}{≔}{10.0}$ (10)
 • Now take samples:
 > $\mathrm{points}≔100$
 ${\mathrm{points}}{≔}{100}$ (11)
 > $\mathrm{tValues}≔\mathrm{Vector}\left(\mathrm{points},i↦\mathrm{evalhf}\left(\mathrm{t1}+\frac{\left(i-1\right)\cdot \mathrm{t2}}{\mathrm{points}-1}\right),\mathrm{datatype}=\mathrm{float}\left[8\right]\right)$
 ${\mathrm{tValues}}{≔}\begin{array}{c}\left[\begin{array}{c}{0.}\\ {0.101010101010101}\\ {0.202020202020202}\\ {0.303030303030303}\\ {0.404040404040404}\\ {0.505050505050505}\\ {0.606060606060606}\\ {0.707070707070707}\\ {0.808080808080808}\\ {0.909090909090909}\\ {⋮}\end{array}\right]\\ \hfill {\text{100 element Vector[column]}}\end{array}$ (12)
 > $\mathrm{yValues}≔\mathrm{~}\left[\mathrm{signal}\right]\left(\mathrm{tValues}\right)$
 ${\mathrm{yValues}}{≔}\begin{array}{c}\left[\begin{array}{c}{5.}\\ {5.13551831710725}\\ {5.26608112284961}\\ {5.38729287300107}\\ {5.49577993912079}\\ {5.58947738897904}\\ {5.66770030220844}\\ {5.73100358338161}\\ {5.78087571112120}\\ {5.81934122416630}\\ {⋮}\end{array}\right]\\ \hfill {\text{100 element Vector[column]}}\end{array}$ (13)
 • The approximation methods give the following answers:
 > $\mathrm{area__leftendpoint}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},\mathrm{method}=\mathrm{leftendpoint}\right)$
 $\mathrm{area__leftendpoint}{≔}{51.8981501007383912}$ (14)
 > $\mathrm{area__rightendpoint}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},\mathrm{method}=\mathrm{rightendpoint}\right)$
 $\mathrm{area__rightendpoint}{≔}{51.8329533308560002}$ (15)
 > $\mathrm{area__simpson}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},\mathrm{method}=\mathrm{simpson}\right)$
 $\mathrm{area__simpson}{≔}{51.8673373379068607}$ (16)
 > $\mathrm{area__trapezoid}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},\mathrm{method}=\mathrm{trapezoid}\right)$
 $\mathrm{area__trapezoid}{≔}{51.8655517157971957}$ (17)
 • Since we have the original algebraic expression for the signal, we can compute the area exactly for comparison:
 > $\mathrm{area}≔\mathrm{int}\left(\mathrm{signal},\mathrm{t1}..\mathrm{t2}\right)$
 ${\mathrm{area}}{≔}{51.86733322}$ (18)
 • Simpson's Method is usually (but not always) the most accurate, so it is not surprising that it gives the closest approximation here, but it tends to be the slowest.

References

 Shklov, N. "Simpson's Rule for Unequally Spaced Ordinates." The American Mathematical Monthly. Vol. 67, No. 10, 1960, pp. 1022-1023.

Compatibility

 • The SignalProcessing[IntegrateData] command was introduced in Maple 2021.