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

• 

compiled: Either true or false, specifies if auxiliary procedures are to be compiled if they are currently uncompiled. The default is false.

• 

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.

• 

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 internally by compilable auxiliary procedures. When IntegrateData2D is called for the first time with compiled=true, these procedures will be compiled before being used. Subsequent calls to IntegrateData2D will used these compiled versions, even if compiled=false, and execute much more quickly. If IntegrateData2D has yet to be called in the session with the compiled=true option, then the auxiliary procedures will be called in evalhf mode. Note: There will be a slight time delay when the procedures are first compiled.

• 

Use of compiled=true is recommended when the number of data points in large, on the order of 10^5 or larger, or if IntegrateData2D is to be called many times in a Maple session. Typically, when the number of data points is large, the compiled version will run approximately ten times faster than the uncompiled version.

• 

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=Typesetting:-_Hold%/Zi&comma;j&plus;Zi&comma;j&plus;1&plus;Zi&plus;1&comma;j&plus;Zi&plus;1&comma;j&plus;1&comma;4

  

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..Typesetting:-_Hold%/m1&comma;2 and q=1..Typesetting:-_Hold%/n1&comma;2. 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 an 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;y&rarr;32x&plus;5y&plus;4x210xy&plus;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;i&rarr;evalhfa&plus;i1dx&comma;&apos;datatype&apos;&equals;&apos;float8&apos;

X0.1.666666666666673.333333333333335.6.666666666666678.3333333333333310.

(2)

YVectorn&comma;j&rarr;evalhfc&plus;j1dy&comma;&apos;datatype&apos;&equals;&apos;float8&apos;

ZMatrixm&comma;n&comma;i&comma;j&rarr;evalhfpXi&comma;Yj&comma;&apos;datatype&apos;&equals;&apos;float8&apos;

• 

Now, compute the volume using Simpson's Method:

&alpha;IntegrateData2DX&comma;Y&comma;Z&comma;&apos;uniform&apos;&comma;&apos;method&apos;&equals;&apos;simpson&apos;

α121933.333333333358

(3)
• 

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

IntegrateData2DZ&comma;&apos;steps&apos;&equals;dx&comma;dy&comma;&apos;method&apos;&equals;&apos;simpson&apos;

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:

&beta;evalf15intpx&comma;y&comma;x&equals;a..b&comma;y&equals;c..d

β121933.333333333

(5)

Example 2

• 

Consider the following function:

fx&comma;y&rarr;&ExponentialE;11&plus;x2&plus;y2

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

(6)

plot3df&comma;0.0..10&comma;0.0..10.0

• 

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

XVectorseq0.0..10.0&comma;1.0&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

YX&colon;

ZMatrixnumelemsX&comma;numelemsY&comma;i&comma;j&rarr;evalhffXi&comma;Yj&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

&alpha;IntegrateData2DX&comma;Y&comma;Z&comma;&apos;method&apos;&equals;&apos;simpson&apos;

α104.150606423932388

(7)
• 

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

&xi;intfx&comma;y&comma;x&equals;0.0..10.0&comma;y&equals;0.0..10.0&comma;&apos;numeric&apos;&comma;&apos;digits&apos;&equals;15

ξ104.263869308879

(8)

evalhf&alpha;&xi;

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.0..3.0&comma;0.01&comma;seq4.0..10.0&comma;1.0&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

VU&colon;

WMatrixnumelemsU&comma;numelemsV&comma;i&comma;j&rarr;evalhffUi&comma;Vj&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

&beta;IntegrateData2DU&comma;V&comma;W&comma;&apos;method&apos;&equals;&apos;simpson&apos;

β104.264569012844262

(10)
• 

This approximation is much closer:

evalhf&beta;&xi;

0.000699703965267417516

(11)

Example 3

• 

Here, we use the compile option on a simple example to see how long the (one-time only) compilation takes:

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)

CodeTools:-UsageIntegrateData2DX&comma;Y&comma;Z&comma;&apos;compiled&apos;&comma;&apos;method&apos;&equals;&apos;bottomleftcorner&apos;

memory used=27.26MiB, alloc change=0 bytes, cpu time=756.00ms, real time=756.00ms, gc time=0ns

12.

(15)

Example 4

• 

Consider the following function and box:

fx&comma;y&rarr;1&plus;sinPix2&plus;3y2

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

(16)

a0.0&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;j&rarr;evalhffa&plus;i1dx&comma;c&plus;j1dy&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

• 

Finally, approximate the volume, using two different methods:

uCodeTools:-UsageIntegrateData2DZ&comma;&apos;steps&apos;&equals;dx&comma;dy&comma;&apos;compiled&apos;&comma;&apos;method&apos;&equals;&apos;averagecorner&apos;

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

u2.06220791967658945

(17)

vCodeTools:-UsageIntegrateData2DZ&comma;&apos;steps&apos;&equals;dx&comma;dy&comma;&apos;compiled&apos;&comma;&apos;method&apos;&equals;&apos;simpson&apos;

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

v2.06221208164538305

(18)
• 

Observe that, even though the rtables are fairly large, the time taken to approximate the volume was fairly small, due to the compilation of the internal procedures (which was performed in an earlier example).

Example 5

• 

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

fx&comma;y&rarr;1.76965408823860471&plus;0.0769328086078387985x2.65475838418437826y4.27801178528191528x26.15468302818204016xy&plus;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.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;&apos;datatype&apos;&equals;&apos;float8&apos;

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.0&comma;2.76025076998578&comma;7.54686681982361&comma;7.09364830858073&comma;6.46313010111265&comma;4.45586200710899&comma;&apos;datatype&apos;&equals;&apos;float8&apos;

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;j&rarr;evalhffXi&comma;Yj&comma;&apos;datatype&apos;&equals;&apos;float8&apos;

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

• 

The expected answer, for comparison, is the following:

&alpha;evalf15intfx&comma;y&comma;x&equals;minX..maxX&comma;y&equals;minY..maxY

α5546.55319312876

(22)
• 

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

&xi;IntegrateData2DX&comma;Y&comma;Z&comma;&apos;sortdata&apos;&equals;&apos;true&apos;&comma;&apos;method&apos;&equals;&apos;simpson&apos;

ξ5546.55319312876418

(23)
• 

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

Psort&apos;inplace&apos;X&comma;&apos;output&apos;&equals;&apos;permutation&apos;&colon;

Qsort&apos;inplace&apos;Y&comma;&apos;output&apos;&equals;&apos;permutation&apos;&colon;

ZZP&comma;Q&colon;

zetaIntegrateData2DX&comma;Y&comma;Z&comma;&apos;sortdata&apos;&equals;&apos;false&apos;&comma;&apos;method&apos;&equals;&apos;simpson&apos;

&zeta;5546.55319312876418

(24)

Example 6

• 

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

&phi;x&comma;y&rarr;5.89801239837002367x&plus;6.33497857715261770y3.14488365480468168

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

(25)

a0.0&colon;

b10.0&colon;

c0.0&colon;

d5.0&colon;

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

• 

For comparison, the int command gives the following:

&nu;evalf15int&phi;x&comma;y&comma;x&equals;a..b&comma;y&equals;c..d

ν2109.13123899635

(26)
• 

Using IntegrateData2D with sorted regular data:

m15&colon;

n20&colon;

XVectorm&comma;i&rarr;evalhfa&plus;i1bam1&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

YVectorn&comma;j&rarr;evalhfc&plus;j1dcn1&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

ZMatrixm&comma;n&comma;i&comma;j&rarr;evalhf&phi;Xi&comma;Yj&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

&alpha;IntegrateData2DX&comma;Y&comma;Z&comma;&apos;uniform&apos;&equals;&apos;true&apos;&comma;&apos;sortdata&apos;&equals;&apos;false&apos;&comma;&apos;method&apos;&equals;&apos;averagecorner&apos;

α2109.13123899635002

(27)
• 

Using IntegrateData2D with sorted irregular data:

UVector0.0&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;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

VVector0.0&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;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

WMatrixnumelemsU&comma;numelemsV&comma;i&comma;j&rarr;evalhf&phi;Ui&comma;Vj&comma;&apos;datatype&apos;&equals;&apos;float8&apos;&colon;

&beta;IntegrateData2DU&comma;V&comma;W&comma;&apos;uniform&apos;&equals;&apos;false&apos;&comma;&apos;sortdata&apos;&equals;&apos;false&apos;&comma;&apos;method&apos;&equals;&apos;averagecorner&apos;

β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;y&rarr;&ExponentialE;x21

fx&comma;y&ExponentialE;x21

(29)

a0&colon;

b2&colon;

n250&colon;

hevalhfban1&colon;

ZMatrixn&comma;n&comma;i&comma;j&rarr;evalhffa&plus;i1h&comma;a&plus;j1h&comma;&apos;datatype&apos;&equals;&apos;complex8&apos;&colon;

vIntegrateData2DZ&comma;&apos;steps&apos;&equals;h&comma;h&comma;&apos;method&apos;&equals;&apos;simpson&apos;

v7.74723830751058973+1.38245111945337396I

(30)

Compatibility

• 

The SignalProcessing[IntegrateData2D] command was introduced in Maple 2022.

• 

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

See Also

CodeTools[Usage]

int

plots[matrixplot]

SignalProcessing

SignalProcessing[IntegrateData]