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

Online Help

All Products    Maple    MapleSim


SignalProcessing

  

IntegrateData2D

  

calculate the volume under a 2-D data set

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

IntegrateData2D( X, Y, Z, options )

IntegrateData2D( Z, options )

Parameters

X, Y

-

one-dimensional rtables or lists of independent data values of type realcons

Z

-

two-dimensional rtable or list of dependent data values of type complexcons

Options

• 

method: One of bottomleftcorner, topleftcorner, toprightcorner, bottomrightcorner, averagecorner, and simpson. The default is averagecorner.

• 

sortdata: Either true or false, specifies if the data is to be sorted. The default is true.

• 

steps: List of two numeric values, specifies the constant spacing of the independent data for the IntegrateData2D(Z) calling sequence. The default is [1,1].

• 

tolerance: Positive numeric value which specifies the tolerance for determining if the independent data in X and Y are uniformly spaced. The default is HFloat(5,-15).

• 

uniform: Either true or false, specifies if the independent data in X and Y are to be assumed uniform. The default is false.

Description

• 

The IntegrateData2D command approximates the volume beneath a 2-D data set using the specified method.

• 

For the IntegrateData2D(X,Y,Z) calling sequence, Z must have numelems(X) rows and numelems(Y) columns. The values of Z are assumed to have been generated by some hypothetical function fx,y and satisfy Zi,j=fXi,Yj for each i and j.

• 

Units are supported in the values of steps and the containers X, Y, and Z (when the rtable shape is a unit).

• 

Internally, the complex case (where Z is complex) is reduced to the real case by applying IntegrateData2D separately to the real and imaginary parts of Z. That is:

IntegrateData2DX,Y,Z=IntegrateData2DX,Y,Z+IIntegrateData2DX,Y,Z

  

For the discussion below, assume the values in Z are real-valued.

• 

When method is any of the "corner methods" and Z has less than two rows or columns, or when method is simpson and Z has less than three rows or columns, the result will be Float(undefined).

• 

Suppose sortdata=true. For the IntegrateData2D(X,Y,Z) calling sequence, X and Y are sorted to be in non-decreasing order and Z is sorted in tandem. For the IntegrateData2D(Z) calling sequence, if one or both values in steps is negative, then the absolute values of these widths is used, and the elements of Z are sorted accordingly. For example, if steps1<0 and 0<steps2, then the rows of Z are sorted in reverse order.

• 

When sortdata=false, the onus is on the user to ensure that the data passed is sorted. For the IntegrateData2D(X,Y,Z) calling sequence, if the data is in fact not sorted, then the result may be useless. For example, if method=simpson and Xi+1=Xi for some i, then a division by zero occurs and the computed volume will be Float(undefined).

• 

For the IntegrateData2D(X,Y,Z) calling sequence, when uniform=true, it is assumed that X and Y are uniformly spaced, with respective spacings X2X1 and Y2Y1. When uniform=false, however, the procedure first checks if X and Y are uniform before deciding which auxiliary procedure to use to compute the volume. For X to be considered uniformly spaced, for example, it must satisfy ΔiΔjτ for each i and j, where Δi=Xi+1Xi and τ=tolerance.

• 

Computations using regular/uniform data, compared with irregular/non-uniform data, tend to be quicker and have smaller numerical error in the final result. Regarding speed, for one of the "corner methods" with a fixed number of values in X and Y, the computation typically takes twice as long if X and Y are irregular than if they are regular. For Simpson's Method, the time taken for irregular data is approximately quadruple the time taken for regular data.

• 

The main computations are handled by external C code.

• 

For any of the "corner methods", the following formula is used:

IntegrateData2DX&comma;Y&comma;Z=i=1m1j=1n1zi,jXi+1XiYi+1Yi

  

where m=numelemsX and n=numelemsY. For method=bottomleftcorner:

zi,j=Zi,j

  

For method=topleftcorner:

zi,j=Zi,j+1

  

For method=toprightcorner:

zi,j=Zi+1,j+1

  

For method=bottomrightcorner:

zi,j=Zi+1,j

  

For method=averagecorner:

zi,j=Zi,j+Zi,j+1+Zi+1,j+Zi+1,j+14

  

Note: method=averagecorner is the 2-D analogue of the Trapezoid Method in 1-D, and for a given sub-box consisting of Xi, Xi+1, Yj, and Yj+1, the volume is that of the best-fit plane through the four points.

• 

We will omit the long and complicated formulas for method=simpson, and include only a description of the derivation. Suppose first that m and n are odd, where m=numelemsX and n=numelemsY. Now, partition the grid into non-overlapping sub-boxes with nine points each, formed by points consisting of Xp, Xp+1, Xp+2, Yq, Yq+1, and Yq+2, where p=1..m12 and q=1..n12. The formula for the approximate volume over one of these sub-boxes is found by integrating over the sub-box the unique quadratic bivariate polynomial which interpolates these nine points. When one or more of m and n is even, however, sub-boxes of nine points are again considered, but the integration is performed only over the parts that have not yet been counted using the above method.

• 

Any input rtable/list of independent data is converted to an rtable of float[8] datatype having no infinite or undefined values, and an error is thrown if this is not possible. Similarly, the input rtable/list of dependent data is converted to an rtable of either 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 IntegrateData2D command is not thread safe.

Examples

withSignalProcessing&colon;

Example 1

• 

Consider this quadratic bivariate polynomial:

px&comma;y32x+5y+4x210yx+7y2

px&comma;y32x+5y+4x210yx+7y2

(1)

a0&colon;

b10&colon;

c0&colon;

d20&colon;

plot3dp&comma;a..b&comma;c..d

• 

First, create sample points:

m7&colon;

n13&colon;

dxevalhfbam1&colon;

dyevalhfdcn1&colon;

XVectorm&comma;ievalhfa+i1dx&comma;datatype=float8

X0.1.666666666666673.333333333333335.6.666666666666678.3333333333333310.

(2)

YVectorn&comma;jevalhfc+j1dy&comma;datatype=float8

ZMatrixm&comma;n&comma;i&comma;jevalhfpXi&comma;Yj&comma;datatype=float8

• 

Now, compute the volume using Simpson's Method:

αIntegrateData2DX&comma;Y&comma;Z&comma;uniform&comma;method=simpson

α121933.333333333358

(3)
• 

Since the independent data values are uniformly spaced, we can also use the other calling sequence:

IntegrateData2DZ&comma;steps=dx&comma;dy&comma;method=simpson

121933.333333333358

(4)
• 

Since Simpson's Method gives the exact answer for such cases, we can compare the result of IntegrateData2D with the expected answer:

βevalf15intpx&comma;y&comma;x=a..b&comma;y=c..d

β121933.333333333

(5)

Example 2

• 

Consider the following function:

fx&comma;yexp11+x2+y2

fx&comma;y&ExponentialE;11+x2+y2

(6)

plot3df&comma;0...10&comma;0...10.0

• 

With a uniform spacing of 1.0, Simpson's Method gives the following:

XVectorseq0...10.0&comma;1.0&comma;datatype=float8&colon;

YX&colon;

ZMatrixnumelemsX&comma;numelemsY&comma;i&comma;jevalhffXi&comma;Yj&comma;datatype=float8&colon;

αIntegrateData2DX&comma;Y&comma;Z&comma;method=simpson

α104.150606423932388

(7)
• 

This approximation for the volume is good, but it could be better, as we can see from integrating the original function:

ξintfx&comma;y&comma;x=0...10.0&comma;y=0...10.0&comma;numeric&comma;digits=15

ξ104.263869308879

(8)

evalhfabsαξ

0.113262884946607301

(9)
• 

From the plot of the dependent data, we can see that more samples for x and y between 0.0 and 3.0 will improve the approximate volume found:

plots:-matrixplotZ

• 

Since we have the access to the original function, we have the luxury of being able to sample more densely for smaller x and y:

UVectorseq0...3.0&comma;0.01&comma;seq4.0..10.0&comma;1.0&comma;datatype=float8&colon;

VU&colon;

WMatrixnumelemsU&comma;numelemsV&comma;i&comma;jevalhffUi&comma;Vj&comma;datatype=float8&colon;

βIntegrateData2DU&comma;V&comma;W&comma;method=simpson

β104.264569012844262

(10)
• 

This approximation is much closer:

evalhfabsβξ

0.000699703965267417516

(11)

Example 3

m3&colon;

n3&colon;

Xseq1..m

X1&comma;2&comma;3

(12)

Yseq1..n

Y1&comma;2&comma;3

(13)

ZMatrixm&comma;n&comma;seq1..mn

Z123456789

(14)

IntegrateData2DX&comma;Y&comma;Z&comma;method=bottomleftcorner

12.

(15)

Example 4

• 

Consider the following function and box:

fx&comma;ysqrt1+sinπx2+3y2

fx&comma;y1+sinπx2+3y2

(16)

a0.&colon;

b1.0&colon;

c0.5&colon;

d1.5&colon;

plot3df&comma;a..b&comma;c..d

• 

Now, create a Matrix of sample data points:

m1000&colon;

n1000&colon;

dxevalhfbam1&colon;

dyevalhfdcn1&colon;

ZMatrixm&comma;n&comma;i&comma;jevalhffa+i1dx&comma;c+j1dy&comma;datatype=float8&colon;

• 

Finally, approximate the volume, using two different methods:

uCodeTools:-UsageIntegrateData2DZ&comma;steps=dx&comma;dy&comma;method=averagecorner

memory used=7.66MiB, alloc change=7.63MiB, cpu time=9.00ms, real time=9.00ms, gc time=0ns

u2.06220791967658945

(17)

vCodeTools:-UsageIntegrateData2DZ&comma;steps=dx&comma;dy&comma;method=simpson

memory used=7.66MiB, alloc change=7.63MiB, cpu time=9.00ms, real time=8.00ms, gc time=0ns

v2.06221208164538305

(18)

Example 5

• 

Here, will use unsorted and irregular (not uniform) independent data:

fx&comma;y1.76965408823860471+0.0769328086078387985x2.65475838418437826y4.27801178528191528x26.15468302818204016yx+7.04479517210091011y2

fx&comma;y1.76965408823860471+0.0769328086078387985x2.65475838418437826y4.27801178528191528x26.15468302818204016yx+7.04479517210091011y2

(19)

XArray2.44882197894116&comma;0.934363022771893&comma;3.97599950568532&comma;3.82758394074501&comma;1.90779228546504&comma;0.&comma;2.19372179828199&comma;0.172230402514544&comma;4.75111024419177&comma;5.0&comma;1.58549740030430&comma;3.47414311487909&comma;4.11728914163646&comma;0.485658906179238&comma;0.230856953155770&comma;1.38461492480445&comma;0.159164231887103&comma;3.53023044009804&comma;0.855933439057809&comma;3.27738945088778&comma;datatype=float8

X2.448821978941160.9343630227718933.975999505685323.827583940745011.907792285465040.2.193721798281990.1722304025145444.751110244191775.1.585497400304303.474143114879094.117289141636460.4856589061792380.2308569531557701.384614924804450.1591642318871033.530230440098040.8559334390578093.27738945088778

(20)

YArray6.99076722656686&comma;10.0&comma;5.05957051665142&comma;2.55095115459269&comma;7.51267059305653&comma;2.23811939491137&comma;5.85267750979777&comma;3.40385726666133&comma;9.59743958516081&comma;4.98364051982143&comma;1.18997681558377&comma;1.62611735194631&comma;6.55098003973841&comma;6.79702676853675&comma;0.&comma;2.76025076998578&comma;7.54686681982361&comma;7.09364830858073&comma;6.46313010111265&comma;4.45586200710899&comma;datatype=float8

Y6.9907672265668610.5.059570516651422.550951154592697.512670593056532.238119394911375.852677509797773.403857266661339.597439585160814.983640519821431.189976815583771.626117351946316.550980039738416.797026768536750.2.760250769985787.546866819823617.093648308580736.463130101112654.45586200710899

(21)

ZArray1..numelemsX&comma;1..numelemsY&comma;i&comma;jevalhffXi&comma;Yj&comma;datatype=float8

plot3df&comma;minX..maxX&comma;minY..maxY

• 

The expected answer, for comparison, is the following:

αevalf15intfx&comma;y&comma;x=minX..maxX&comma;y=minY..maxY

α5546.55319312876

(22)
• 

To approximate the volume, we will use two approaches. For the first approach, just use the sortdata option:

ξIntegrateData2DX&comma;Y&comma;Z&comma;sortdata=true&comma;method=simpson

ξ5546.55319312876418

(23)
• 

For the second approach, we will manually sort the data:

PsortinplaceX&comma;output=permutation&colon;

QsortinplaceY&comma;output=permutation&colon;

ZZP,Q&colon;

ζIntegrateData2DX&comma;Y&comma;Z&comma;sortdata=false&comma;method=simpson

ζ5546.55319312876418

(24)

Example 6

• 

In this example, we show that IntegrateData2D gives the exact answer when the data is generated by a plane.

φx&comma;y5.89801239837002367x+6.33497857715261770y3.14488365480468168

φx&comma;y5.89801239837002367x+6.33497857715261770y3.14488365480468168

(25)

a0.&colon;

b10.0&colon;

c0.&colon;

d5.0&colon;

plot3dφ&comma;a..b&comma;c..d

• 

For comparison, the int command gives the following:

νevalf15intφx&comma;y&comma;x=a..b&comma;y=c..d

ν2109.13123899635

(26)
• 

Using IntegrateData2D with sorted regular data:

m15&colon;

n20&colon;

XVectorm&comma;ievalhfa+i1bam1&comma;datatype=float8&colon;

YVectorn&comma;jevalhfc+j1dcn1&comma;datatype=float8&colon;

ZMatrixm&comma;n&comma;i&comma;jevalhfφXi&comma;Yj&comma;datatype=float8&colon;

αIntegrateData2DX&comma;Y&comma;Z&comma;uniform=true&comma;sortdata=false&comma;method=averagecorner

α2109.13123899635002

(27)
• 

Using IntegrateData2D with sorted irregular data:

UVector0.&comma;0.344460805029088&comma;1.86872604554379&comma;3.17099480060861&comma;3.81558457093008&comma;4.38744359656398&comma;4.45586200710899&comma;4.89764395788231&comma;6.46313010111265&comma;6.94828622975817&comma;7.65516788149002&comma;7.95199901137063&comma;8.23457828327293&comma;9.50222048838355&comma;10.0&comma;datatype=float8&colon;

VVector0.&comma;0.594988407791883&comma;0.813058675973153&comma;1.11905969745568&comma;1.27547557729635&comma;1.38012538499289&comma;1.70192863333067&comma;2.49182025991071&comma;2.52978525832571&comma;2.92633875489889&comma;3.27549001986920&comma;3.39851338426837&comma;3.49538361328343&comma;3.54682415429036&comma;3.75633529652826&comma;3.77343340991180&comma;4.45451626267899&comma;4.79645712602722&comma;4.79871979258041&comma;5.0&comma;datatype=float8&colon;

WMatrixnumelemsU&comma;numelemsV&comma;i&comma;jevalhfφUi&comma;Vj&comma;datatype=float8&colon;

βIntegrateData2DU&comma;V&comma;W&comma;uniform=false&comma;sortdata=false&comma;method=averagecorner

β2109.13123899634866

(28)

Example 7

• 

The IntegrateData2D command also works with complex data. Here, we find the volume under &ExponentialE;x21 for x and y in the interval 0&comma;2:

fx&comma;yexpsqrtx21

fx&comma;y&ExponentialE;x21

(29)

a0&colon;

b2&colon;

n250&colon;

hevalhfban1&colon;

ZMatrixn&comma;n&comma;i&comma;jevalhffa+i1h&comma;a+j1h&comma;datatype=complex8&colon;

vIntegrateData2DZ&comma;steps=h&comma;h&comma;method=simpson

v7.74723830751058973+1.38245111945337396I

(30)

Example 8

• 

Units are supported:

XVector1&comma;2&comma;3&comma;datatype=float8Unitm

X1.m2.m3.m

(31)

YVector1&comma;3&comma;5&comma;datatype=float8Units

Y1.s3.s5.s

(32)

ZMatrix10&comma;2&comma;5&comma;7&comma;0&comma;3&comma;1&comma;6&comma;4&comma;datatype=float8Unitkg

Z10.kg2.kg5.kg7.kg0.3.kg1.kg6.kg4.kg

(33)

h1Unitm&comma;2Units

hm&comma;2s

(34)

IntegrateData2DX&comma;Y&comma;Z

23.kgms

(35)

IntegrateData2DZ&comma;steps=h

23.kgms

(36)

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[IntegrateData2D] command was introduced in Maple 2022.

• 

For more information on Maple 2022 changes, see Updates in Maple 2022.

• 

The SignalProcessing[IntegrateData2D] command was updated in Maple 2024.

See Also

CodeTools[Usage]

int

plots[matrixplot]

SignalProcessing

SignalProcessing[IntegrateData]