IntegrateData - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


SignalProcessing

  

IntegrateData

  

calculate the area under a 1-D data set

 

Calling Sequence

Parameters

Options

Description

Examples

References

Compatibility

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:

IntegrateDataX,Y,output=totalc+abfxⅆ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:

IntegrateDataX,Y,output=runningic+aXifxⅆ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:

IntegrateDataX,Y=IntegrateDataX,Y+IIntegrateDataX,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:

IntegrateDataX&comma;Y=i=2nXiXi1Yi1

  

where n=numelemsX. 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:

IntegrateDataX&comma;Y=i=2nXiXi1Yi

  

where n=numelemsX. 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:

IntegrateDataX&comma;Y=i=2nXiXi1Yi1+Yi2

  

where n=numelemsX. 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 X2X1. 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+1Xi 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.

Examples

withSignalProcessing&colon;

Example 1

• 

Consider the following (unsorted) independent and dependent data:

XYMatrix3&comma;9&comma;2.5&comma;4&comma;1&comma;1

XY392.5411

(1)
• 

The (default) Trapezoid Method gives the following for the appropriate integral:

z1IntegrateDataXY&comma;sortdata&comma;method=trapezoid

z17.

(2)
• 

The independent data is in reverse order, so if we choose to not sort, we get the negative of the previous answer:

z2IntegrateDataXY&comma;sortdata=false&comma;method=trapezoid

z2−7.

(3)
• 

If we omit the independent data and instead use a uniform spacing of 2.0, we get the following:

z3IntegrateDataXY..,2&comma;method=trapezoid&comma;step=2.0

z318.

(4)

Example 2

• 

The following data could result from a step function:

X10&comma;0&comma;0&comma;10

X−100010

(5)

Y2&comma;2&comma;4&comma;4

Y2244

(6)

dataplotX&comma;Y&comma;view=10..10&comma;0..5&comma;thickness=3

• 

The independent data values are not unique, but we can still obtain an area:

IntegrateDataX&comma;Y&comma;method=trapezoid&comma;sortdata=false

60.

(7)

Example 3

• 

Consider the following signal over the given time interval:

signalt5+sint+0.1sin3t+0.01sin5t&colon;

t10.&colon;

t210.0&colon;

• 

Now take samples:

points100&colon;

tValues,yValuesGenerateSignalsignal&comma;t1..t2&comma;points&comma;output=times&comma;signal

• 

The approximation methods give the following answers:

area__leftendpointIntegrateDatatValues&comma;yValues&comma;method=leftendpoint

area__leftendpoint51.8981501007384196

(8)

area__rightendpointIntegrateDatatValues&comma;yValues&comma;method=rightendpoint

area__rightendpoint51.8329533308559931

(9)

area__simpsonIntegrateDatatValues&comma;yValues&comma;method=simpson

area__simpson51.8673373379068536

(10)

area__trapezoidIntegrateDatatValues&comma;yValues&comma;method=trapezoid

area__trapezoid51.8655517157972312

(11)
• 

Since we have the original algebraic expression for the signal, we can compute the area exactly for comparison:

areaintsignal&comma;t1..t2&comma;digits=15

area51.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:

fx21+x2&colon;

a1.0&colon;

b1.0&colon;

• 

Now, approximate the area, which we expect to be close to π:

n104&colon;

X,YGenerateSignalf&comma;a..b&comma;n&comma;output=times&comma;signal

CodeTools:-UsageIntegrateDataX&comma;Y&comma;method=simpson

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,XGenerateSignalexpIt2&comma;t=0..2π&comma;104&comma;output=times&comma;signal

IntegrateDataT&comma;X&comma;method=simpson

0.704681810428586908+0.642138187610876709I

(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:

t10.&colon;

t22.0&colon;

n100&colon;

dt,T,VGenerateSignaltexpt2sin2tπ&comma;t=t1..t2&comma;n&comma;output=timestep&comma;times&comma;signal&colon;

x01.0&colon;

XIntegrateDataV&comma;step=dt&comma;initial=x0&comma;method=trapezoid&comma;output=running&colon;

dataplotT&comma;V&comma;X&comma;color=darkgreen&comma;blue&comma;labels=time&comma;&comma;legend=velocity&comma;position&comma;style=line

Example 7

• 

Units are supported:

TVector1&comma;2&comma;3&comma;datatype=float8Units

T1.s2.s3.s

(15)

VVector1&comma;4&comma;9&comma;datatype=float8Unitms

V1.ms4.ms9.ms

(16)

IntegrateDataV&comma;step=1.0Units

9.m

(17)

IntegrateDataT&comma;V

9.m

(18)

XIntegrateDataT&comma;V&comma;output=running

X0.2.50000000000000m9.m

(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.

• 

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

SignalProcessing[DifferentiateData]

SignalProcessing[GenerateSignal]

SignalProcessing[IntegrateData2D]

Student[Calculus1]