SignalProcessing
IntegrateData
calculate the area under a 1-D data set
Calling Sequence
Parameters
Options
Description
Examples
References
Compatibility
IntegrateData( X, Y, options )
IntegrateData( Y, options )
IntegrateData( XY, options )
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
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.
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:
IntegrateData⁡X,Y,output=total≈c+∫abf⁡xⅆx
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:
IntegrateData⁡X,Y,output=runningi≈c+∫aXif⁡xⅆx
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:
IntegrateData⁡X,Y=IntegrateData⁡X,ℜ⁡Y+I⁢IntegrateData⁡X,ℑ⁡Y
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:
IntegrateData⁡X,Y=∑i=2n⁡Xi−Xi−1⁢Yi−1
where n=numelems⁡X. 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:
IntegrateData⁡X,Y=∑i=2n⁡Xi−Xi−1⁢Yi
where n=numelems⁡X. 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:
IntegrateData⁡X,Y=∑i=2n⁡Xi−Xi−1⁢Yi−1+Yi2
where n=numelems⁡X. 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 X2−X1. 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 Δi−Δj≤τ for each i and j, where Δi=Xi+1−Xi and τ=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.
with⁡SignalProcessing:
Example 1
Consider the following (unsorted) independent and dependent data:
XY≔Matrix⁡3,9,2.5,4,1,1
XY≔392.5411
The (default) Trapezoid Method gives the following for the appropriate integral:
z1≔IntegrateData⁡XY,sortdata,method=trapezoid
z1≔7.
The independent data is in reverse order, so if we choose to not sort, we get the negative of the previous answer:
z2≔IntegrateData⁡XY,sortdata=false,method=trapezoid
z2≔−7.
If we omit the independent data and instead use a uniform spacing of 2.0, we get the following:
z3≔IntegrateData⁡XY..,2,method=trapezoid,step=2.0
z3≔18.
Example 2
The following data could result from a step function:
X≔−10,0,0,10
X≔−100010
Y≔2,2,4,4
Y≔2244
dataplot⁡X,Y,view=−10..10,0..5,thickness=3
The independent data values are not unique, but we can still obtain an area:
IntegrateData⁡X,Y,method=trapezoid,sortdata=false
60.
Example 3
Consider the following signal over the given time interval:
signal≔t↦5+sin⁡t+0.1⋅sin⁡3⋅t+0.01⋅sin⁡5⋅t:
t1≔0.:
t2≔10.0:
Now take samples:
points≔100:
tValues,yValues≔GenerateSignal⁡signal,t1..t2,points,output=times,signal
The approximation methods give the following answers:
area__leftendpoint≔IntegrateData⁡tValues,yValues,method=leftendpoint
area__leftendpoint≔51.8981501007384196
area__rightendpoint≔IntegrateData⁡tValues,yValues,method=rightendpoint
area__rightendpoint≔51.8329533308559931
area__simpson≔IntegrateData⁡tValues,yValues,method=simpson
area__simpson≔51.8673373379068536
area__trapezoid≔IntegrateData⁡tValues,yValues,method=trapezoid
area__trapezoid≔51.8655517157972312
Since we have the original algebraic expression for the signal, we can compute the area exactly for comparison:
area≔int⁡signal,t1..t2,digits=15
area≔51.8673332153566
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↦21+x2:
a≔−1.0:
b≔1.0:
Now, approximate the area, which we expect to be close to π:
n≔104:
X,Y≔GenerateSignal⁡f,a..b,n,output=times,signal
CodeTools:-Usage⁡IntegrateData⁡X,Y,method=simpson
memory used=211.12KiB, alloc change=0 bytes, cpu time=1000.00us, real time=0ns, gc time=0ns
3.14159265358978956
Example 5
Complex data can also be handled:
T,X≔GenerateSignal⁡exp⁡I⁢t2,t=0..2⁢π,104,output=times,signal
IntegrateData⁡T,X,method=simpson
0.704681810428586908+0.642138187610876709⁢I
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:
t2≔2.0:
n≔100:
dt,T,V≔GenerateSignal⁡t⁢exp⁡−t2⁢sin⁡2⁢t⁢π,t=t1..t2,n,output=timestep,times,signal:
x0≔1.0:
X≔IntegrateData⁡V,step=dt,initial=x0,method=trapezoid,output=running:
dataplot⁡T,V,X,color=darkgreen,blue,labels=time,,legend=velocity,position,style=line
Example 7
Units are supported:
T≔Vector⁡1,2,3,datatype=float8⁢Unit⁡s
T≔1.⁢s2.⁢s3.⁢s
V≔Vector⁡1,4,9,datatype=float8⁢Unit⁡ms
V≔1.⁢ms4.⁢ms9.⁢ms
IntegrateData⁡V,step=1.0⁢Unit⁡s
9.⁢m
IntegrateData⁡T,V
X≔IntegrateData⁡T,V,output=running
X≔0.2.50000000000000⁢m9.⁢m
Shklov, N. "Simpson's Rule for Unequally Spaced Ordinates." The American Mathematical Monthly. Vol. 67, No. 10, 1960, pp. 1022-1023.
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.
For more information on Maple 2021 changes, see Updates in Maple 2021.
The tolerance and uniform options were introduced in Maple 2022.
For more information on Maple 2022 changes, see Updates in Maple 2022.
The SignalProcessing[IntegrateData] command was updated in Maple 2024.
The initial and output options were introduced in Maple 2024.
For more information on Maple 2024 changes, see Updates in Maple 2024.
See Also
CodeTools[Usage]
int
SignalProcessing[DifferentiateData]
SignalProcessing[GenerateSignal]
SignalProcessing[IntegrateData2D]
Student[Calculus1]
Download Help Document