|
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 and satisfy for each and .
|
•
|
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:
|
|
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 and , 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 for some , 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 and . 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 for each and , where and .
|
•
|
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:
|
|
where and . For method=bottomleftcorner:
|
|
For method=topleftcorner:
|
|
For method=toprightcorner:
|
|
For method=bottomrightcorner:
|
|
For method=averagecorner:
|
|
Note: method=averagecorner is the 2-D analogue of the Trapezoid Method in 1-D, and for a given sub-box consisting of , , , and , 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 and . Now, partition the grid into non-overlapping sub-boxes with nine points each, formed by points consisting of , , , , , and , where and . 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
|
|
|
Example 1
|
|
•
|
Consider this quadratic bivariate polynomial:
|
•
|
First, create sample points:
|
•
|
Now, compute the volume using Simpson's Method:
|
•
|
Since the independent data values are uniformly spaced, we can also use the other calling sequence:
|
•
|
Since Simpson's Method gives the exact answer for such cases, we can compare the result of IntegrateData2D with the expected answer:
|
|
|
Example 2
|
|
•
|
Consider the following function:
|
•
|
With a uniform spacing of 1.0, Simpson's Method gives the following:
|
•
|
This approximation for the volume is good, but it could be better, as we can see from integrating the original function:
|
•
|
From the plot of the dependent data, we can see that more samples for and between 0.0 and 3.0 will improve the approximate volume found:
|
•
|
Since we have the access to the original function, we have the luxury of being able to sample more densely for smaller and :
|
•
|
This approximation is much closer:
|
|
|
Example 3
|
|
|
|
Example 4
|
|
•
|
Consider the following function and box:
|
•
|
Now, create a Matrix of sample data points:
|
•
|
Finally, approximate the volume, using two different methods:
|
memory used=7.66MiB, alloc change=7.63MiB, cpu time=9.00ms, real time=9.00ms, gc time=0ns
| |
memory used=7.66MiB, alloc change=7.63MiB, cpu time=9.00ms, real time=8.00ms, gc time=0ns
| |
|
|
Example 5
|
|
•
|
Here, will use unsorted and irregular (not uniform) independent data:
|
•
|
The expected answer, for comparison, is the following:
|
•
|
To approximate the volume, we will use two approaches. For the first approach, just use the sortdata option:
|
•
|
For the second approach, we will manually sort the data:
|
|
|
Example 6
|
|
•
|
In this example, we show that IntegrateData2D gives the exact answer when the data is generated by a plane.
|
•
|
For comparison, the int command gives the following:
|
•
|
Using IntegrateData2D with sorted regular data:
|
•
|
Using IntegrateData2D with sorted irregular data:
|
|
|
Example 7
|
|
•
|
The IntegrateData2D command also works with complex data. Here, we find the volume under for and in the interval :
|
|
|
Example 8
|
|
|
|
|
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.
|
•
|
The SignalProcessing[IntegrateData2D] command was updated in Maple 2024.
|
|
|
|