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.
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.
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.
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:
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. 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.
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=true,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 that is allowed except when Simpson's Method is used:
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≔Vector⁡points,i↦evalhf⁡t1+i−1⋅t2points−1,datatype=float8
tValues≔0.0.1010101010101010.2020202020202020.3030303030303030.4040404040404040.5050505050505050.6060606060606060.7070707070707070.8080808080808080.909090909090909⋮100 element Vector[column]
yValues≔`~`signal⁡tValues
yValues≔5.5.135518317107255.266081122849615.387292873001075.495779939120795.589477388979045.667700302208445.731003583381615.780875711121205.81934122416630⋮100 element Vector[column]
The approximation methods give the following answers:
area__leftendpoint≔IntegrateData⁡tValues,yValues,method=leftendpoint
area__leftendpoint≔51.8981501007383912
area__rightendpoint≔IntegrateData⁡tValues,yValues,method=rightendpoint
area__rightendpoint≔51.8329533308560002
area__simpson≔IntegrateData⁡tValues,yValues,method=simpson
area__simpson≔51.8673373379068607
area__trapezoid≔IntegrateData⁡tValues,yValues,method=trapezoid
area__trapezoid≔51.8655517157971957
Since we have the original algebraic expression for the signal, we can compute the area exactly for comparison:
area≔int⁡signal,t1..t2
area≔51.86733322
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.
Shklov, N. "Simpson's Rule for Unequally Spaced Ordinates." The American Mathematical Monthly. Vol. 67, No. 10, 1960, pp. 1022-1023.
The SignalProcessing[IntegrateData] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
Student[Calculus1]
Download Help Document
What kind of issue would you like to report? (Optional)