2
$\begingroup$

I have a set of xyz data points. X and Y are coordinates of a regular grid of 10x10 units, Z is the independent variable.

I am trying to calculate the volume under the set of points, using Riemann sum. I have used two approaches that I expected to produce the same result, and on the contrary, produce very different results.

In the first approach I make a sum of the volumes of the prism formed by every point. In the second approach I make an interpolation function with an interpolation order of 0, and then integrate it. Here is a MWE of the code I'm using:

Data = {{{230, 310}, 0.4434}, {{230, 320}, 0.5078}, {{230, 330}, 
0.6000}, {{230, 340}, 0.6430}, {{230, 350}, 0.6724}, {{230, 360}, 
0.7204}, {{230, 370}, 0.7593}, {{230, 380}, 0.7987}, {{230, 390}, 
0.8908}, {{230, 400}, 1.0175}, {{230, 410}, 1.1136}, {{230, 420}, 
1.2342}, {{230, 430}, 1.3375}, {{230, 440}, 1.4055}, {{230, 450}, 
1.3979}, {{240, 310}, 0.4593}, {{240, 320}, 0.3963}, {{240, 330}, 
0.3985}, {{240, 340}, 0.3877}, {{240, 350}, 0.4262}, {{240, 360}, 
0.4763}, {{240, 370}, 0.5465}, {{240, 380}, 0.6163}, {{240, 390}, 
0.7376}, {{240, 400}, 0.8567}, {{240, 410}, 0.9769}, {{240, 420}, 
1.1350}, {{240, 430}, 1.2960}, {{240, 440}, 1.4032}, {{240, 450}, 
1.4310}, {{250, 310}, 0.5866}, {{250, 320}, 0.4513}, {{250, 330}, 
0.3789}, {{250, 340}, 0.3360}, {{250, 350}, 0.3273}, {{250, 360}, 
0.3526}, {{250, 370}, 0.4068}, {{250, 380}, 0.4520}, {{250, 390}, 
0.5269}, {{250, 400}, 0.6071}, {{250, 410}, 0.6807}, {{250, 420}, 
0.7808}, {{250, 430}, 0.8794}, {{250, 440}, 0.9572}, {{250, 450}, 
0.9682}};

Total[Data[[All, 2]]*100]

Integrate[Interpolation[Data, InterpolationOrder -> 0][x, y], {x, 230, 250}, {y, 310, 450}]

The first approach yields a volume of 3377.73, and the second one of 1918.94. Can someone explain the reason for this difference? Or which one is more appropriate for the purpose of estimating a volume?

Any help will be very much appreciated.

$\endgroup$

1 Answer 1

2
$\begingroup$

First method includes all the boundaries. In effect it is an estimate of the integral over $225<x<255, 305<y<455$. Omit the lower edges and the two calculations agree.

Total[Select[Data, 
    230 < #[[1, 1]] <= 250 && 310 < #[[1, 2]] <= 450 &][[All, 2]]*100]

Integrate[
 Interpolation[Data, InterpolationOrder -> 0][x, y],
 {x, 230, 250}, {y, 310, 450}]

(*
1918.94
1918.94
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.