 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 of type realcons Y - one-dimensional rtable or list of dependent data values of type complexcons XY - two-dimensional rtable or list of independent and dependent data values, with each row representing a single point, the first column being of type realcons, and the second column being of type complexcons Options

 • compiled : Either true or false, specifies if auxiliary procedures are to be compiled if they are currently uncompiled. The default is false.
 • 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.
 • tolerance : Positive numeric value which specifies the tolerance for determining if the independent data in X is uniformly spaced. The default is HFloat(5,-15).
 • uniform : Either true or false, specifies if the independent data in X are to be assumed uniform. The default is false. Description

 • The IntegrateData command approximates the area beneath a 1-D data set using the specified method.
 • 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 calling sequence IntegrateData(X,Y), either when uniform=true or X is determined to be uniform, is reduced to IntegrateData(Y,step=X-X).
 • Internally, the complex case (where Y is complex) is reduced to the real case by applying IntegrateData separately to the real and imaginary parts of Y. That is:

$\mathrm{IntegrateData}\left(X,Y\right)=\mathrm{IntegrateData}\left(X,\mathrm{\Re }\left(Y\right)\right)+I\mathrm{IntegrateData}\left(X,\mathrm{\Im }\left(Y\right)\right)$

 For the discussion below, assume the values in Y are real-valued.
 • 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 the IntegrateData(X,Y) calling sequence, if sortdata=true then the values in X are sorted in increasing order, and the values in Y are sorted accordingly. If sortdata=false, on the other hand, the onus is on the user to ensure that the data is sorted. For the IntegrateData(Y) calling sequence, if sortdata=true and step<0, then abs(step) is used and Y is sorted in reverse order. 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 Float(undefined).
 • When method is leftendpoint, rightendpoint, or trapezoid and the number of data points is less than two, or when method is simpson and the number of data points is less than three, the result will be Float(undefined).
 • 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.
 • For the IntegrateData(X,Y) calling sequence, when uniform=true, it is assumed that X is uniformly spaced, with spacing ${X}_{2}-{X}_{1}$. When uniform=false, however, the procedure first checks if X is uniform before deciding which auxiliary procedure to use to compute the volume. For X to be considered uniformly spaced, it must satisfy $\left|{\mathrm{\Delta }}_{i}-{\mathrm{\Delta }}_{j}\right|\le \mathrm{\tau }$ for each $i$ and $j$, where ${\mathrm{\Delta }}_{i}={X}_{i+1}-{X}_{i}$ and $\mathrm{\tau }=\mathrm{tolerance}$.
 • Computations using regular/uniform data X, compared with irregular/non-uniform X of the same size, tend to be quicker (approximately 40%) and have smaller numerical error in the final result.
 • The main computations are handled internally by compilable auxiliary procedures. When IntegrateData is called for the first time with compiled=true, these procedures will be compiled before being used. Subsequent calls to IntegrateData will used these compiled versions, even if compiled=false, and execute much more quickly. If IntegrateData has yet to be called in the session with the compiled=true option, then the auxiliary procedures will be called in evalhf mode. Note: There will be a slight time delay when the procedures are first compiled.
 • Use of compiled=true is recommended when the number of data points in large, on the order of 10^5 or larger, or if IntegrateData is to be called many times in a Maple session.
 • Any input rtable/list is converted to an rtable of float or complex datatype having no infinite or undefined values, and an error is 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. 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{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(\right)..\left(\right),2},'\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 we can still obtain an area:
 > $\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\mathrm{sin}\left(3t\right)+0.01\mathrm{sin}\left(5t\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.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{yValues}≔\mathrm{GenerateSignal}\left(\mathrm{signal},\mathrm{t1}..\mathrm{t2},\mathrm{points},'\mathrm{output}'=\left['\mathrm{times}','\mathrm{signal}'\right]\right)$ • The approximation methods give the following answers:
 > $\mathit{area__leftendpoint}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{leftendpoint}'\right)$
 $\mathrm{area__leftendpoint}{≔}{51.8981501007384}$ (12)
 > $\mathit{area__rightendpoint}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{rightendpoint}'\right)$
 $\mathrm{area__rightendpoint}{≔}{51.8329533308560}$ (13)
 > $\mathit{area__simpson}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{simpson}'\right)$
 $\mathrm{area__simpson}{≔}{51.8673373379068394}$ (14)
 > $\mathit{area__trapezoid}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{trapezoid}'\right)$
 $\mathrm{area__trapezoid}{≔}{51.8655517157972}$ (15)
 • 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},'\mathrm{digits}'=15\right)$
 ${\mathrm{area}}{≔}{51.8673332153566}$ (16)
 • 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. Example 4

 • Here, we will use will approximate an area with a large number of sample points and use the compiled option. Consider the following function over the given range:
 > $f≔x→\frac{2}{1+{x}^{2}}$
 ${f}{≔}{x}{↦}\frac{{2}}{{1}{+}{{x}}^{{2}}}$ (17)
 > $a≔-1.0:$
 > $b≔1.0:$
 • First, we will compile the internal procedures separately using a token call of IntegrateData to measure the time it takes:
 > $\mathrm{CodeTools}:-\mathrm{Usage}\left(\mathrm{IntegrateData}\left(\left[1,2,3\right],\left[4,5,6\right],'\mathrm{method}'='\mathrm{simpson}','\mathrm{compiled}'\right)\right)$
 memory used=49.52KiB, alloc change=0 bytes, cpu time=1000.00us, real time=1000.00us, gc time=0ns
 ${10.}$ (18)
 • Now, approximate the area, which we expect to be close to $\mathrm{\pi }$:
 > $n≔{10}^{4}$
 ${n}{≔}{10000}$ (19)
 > $X,Y≔\mathrm{GenerateSignal}\left(f,a..b,n,'\mathrm{output}'=\left['\mathrm{times}','\mathrm{signal}'\right]\right)$ > $\mathrm{CodeTools}:-\mathrm{Usage}\left(\mathrm{IntegrateData}\left(X,Y,'\mathrm{method}'='\mathrm{simpson}','\mathrm{compiled}'\right)\right)$
 memory used=209.80KiB, alloc change=0 bytes, cpu time=1000.00us, real time=1000.00us, gc time=0ns
 ${3.14159265358978956}$ (20) Example 4

 • Complex data can also be handled:
 > $T,X≔\mathrm{GenerateSignal}\left({ⅇ}^{I{t}^{2}},t=0..2\mathrm{Pi},{10}^{4},'\mathrm{output}'=\left['\mathrm{times}','\mathrm{signal}'\right]\right)$ > $\mathrm{IntegrateData}\left(T,X,'\mathrm{method}'='\mathrm{simpson}'\right)$
 ${0.704681810428634203}{+}{0.642138187610691302}{}{I}$ (21) 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.