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

 • initial : Numeric value, this specifies the initial area. The default is 0.0.
 • 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.
 • output : Either running, total, or a list of these names. This specifies the output. When a list is provided, an expression sequence with the corresponding outputs, in the same order, is returned. The default is total.

Description

 • The IntegrateData command approximates the area beneath a 1-D data set using the specified method. More precisely, if c=initial and the containers X and Y consist of data sampled from the curve y=f(x) over the interval [a,b], then:

$\mathrm{IntegrateData}\left(X,Y,'\mathrm{output}'='\mathrm{total}'\right)\approx \left(c+{{\int }}_{a}^{b}f\left(x\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}x\right)$

 • For output=running, the cumulative areas are returned. That is, the output is a Vector of the same size as X and Y with elements given by the following:

${\mathrm{IntegrateData}\left(X,Y,'\mathrm{output}'='\mathrm{running}'\right)}_{i}\approx \left(c+{{\int }}_{a}^{{X}_{i}}f\left(x\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}x\right)$

 • 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[2]-X[1]).
 • Units are supported in the value of step and the containers X, Y, and XY (when the rtable shape is a unit).
 • 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.
 • Any input rtable/list is converted to an rtable of float[8] or complex[8] 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 a non-unit 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[..,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 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\cdot \mathrm{sin}\left(3\cdot t\right)+0.01\cdot \mathrm{sin}\left(5\cdot t\right):$
 > $\mathrm{t1}≔0.:$
 > $\mathrm{t2}≔10.0:$
 • Now take samples:
 > $\mathrm{points}≔100:$
 > $\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:
 > $\mathrm{area__leftendpoint}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{leftendpoint}'\right)$
 $\mathrm{area__leftendpoint}{≔}{51.8981501007384196}$ (8)
 > $\mathrm{area__rightendpoint}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{rightendpoint}'\right)$
 $\mathrm{area__rightendpoint}{≔}{51.8329533308559931}$ (9)
 > $\mathrm{area__simpson}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{simpson}'\right)$
 $\mathrm{area__simpson}{≔}{51.8673373379068536}$ (10)
 > $\mathrm{area__trapezoid}≔\mathrm{IntegrateData}\left(\mathrm{tValues},\mathrm{yValues},'\mathrm{method}'='\mathrm{trapezoid}'\right)$
 $\mathrm{area__trapezoid}{≔}{51.8655517157972312}$ (11)
 • 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}$ (12)
 • 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. Consider the following function over the given range:
 > $f≔x↦\frac{2}{1+{x}^{2}}:$
 > $a≔-1.0:$
 > $b≔1.0:$
 • Now, approximate the area, which we expect to be close to $\mathrm{\pi }$:
 > $n≔{10}^{4}:$
 > $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}'\right)\right)$
 memory used=211.12KiB, alloc change=0 bytes, cpu time=1000.00us, real time=0ns, gc time=0ns
 ${3.14159265358978956}$ (13)

Example 5

 • Complex data can also be handled:
 > $T,X≔\mathrm{GenerateSignal}\left(\mathrm{exp}\left(I{t}^{2}\right),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.704681810428586908}{+}{0.642138187610876709}{}{I}$ (14)

Example 6

 • An initial value can be specified and the container of cumulative areas can be returned. Suppose we have a velocity Vector along with starting position and need to find the position Vector:
 > $\mathrm{t1}≔0.:$
 > $\mathrm{t2}≔2.0:$
 > $n≔100:$
 > $\mathrm{dt},T,V≔\mathrm{GenerateSignal}\left(t\mathrm{exp}\left(-\frac{t}{2}\right)\mathrm{sin}\left(2t\mathrm{\pi }\right),t=\mathrm{t1}..\mathrm{t2},n,'\mathrm{output}'=\left['\mathrm{timestep}','\mathrm{times}','\mathrm{signal}'\right]\right):$
 > $\mathrm{x0}≔1.0:$
 > $X≔\mathrm{IntegrateData}\left(V,'\mathrm{step}'=\mathrm{dt},'\mathrm{initial}'=\mathrm{x0},'\mathrm{method}'='\mathrm{trapezoid}','\mathrm{output}'='\mathrm{running}'\right):$
 > $\mathrm{dataplot}\left(T,\left[V,X\right],'\mathrm{color}'=\left['\mathrm{darkgreen}','\mathrm{blue}'\right],'\mathrm{labels}'=\left["time",""\right],'\mathrm{legend}'=\left['\mathrm{velocity}','\mathrm{position}'\right],'\mathrm{style}'='\mathrm{line}'\right)$

Example 7

 • Units are supported:
 > $T≔\mathrm{Vector}\left(\left[1,2,3\right],'\mathrm{datatype}'='\mathrm{float}\left[8\right]'\right)\mathrm{Unit}\left('s'\right)$
 ${T}{≔}\left[\begin{array}{c}{1.}{}⟦{s}⟧\\ {2.}{}⟦{s}⟧\\ {3.}{}⟦{s}⟧\end{array}\right]$ (15)
 > $V≔\mathrm{Vector}\left(\left[1,4,9\right],'\mathrm{datatype}'='\mathrm{float}\left[8\right]'\right)\mathrm{Unit}\left('\frac{m}{s}'\right)$
 ${V}{≔}\left[\begin{array}{c}{1.}{}⟦\frac{{m}}{{s}}⟧\\ {4.}{}⟦\frac{{m}}{{s}}⟧\\ {9.}{}⟦\frac{{m}}{{s}}⟧\end{array}\right]$ (16)
 > $\mathrm{IntegrateData}\left(V,'\mathrm{step}'=1.0\mathrm{Unit}\left('s'\right)\right)$
 ${9.}{}⟦{m}⟧$ (17)
 > $\mathrm{IntegrateData}\left(T,V\right)$
 ${9.}{}⟦{m}⟧$ (18)
 > $X≔\mathrm{IntegrateData}\left(T,V,'\mathrm{output}'='\mathrm{running}'\right)$
 ${X}{≔}\left[\begin{array}{c}{0.}\\ {2.50000000000000}{}⟦{m}⟧\\ {9.}{}⟦{m}⟧\end{array}\right]$ (19)

References

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

Compatibility

 • Starting with Maple 2023, external C code is used for the auxiliary procedures that were formerly implemented in Maple and could be compiled by passing the compiled option. The compiled option is now deprecated, but it is still accepted for backwards compatibility.
 • The SignalProcessing[IntegrateData] command was introduced in Maple 2021.