2
$\begingroup$

I am trying to calculate the integral of the data. Following this post, I know what to do with a one-dimensional list. But, let's consider a simple function, just to show you, what I want to do.

f[x_, y_]:= x y;

Now, I create a two-dimensional table

L = Table[f[x,y], {x, 0, 5}, {y,0, 5}];

Now on this data, I would like to do the following operation

Integrate[f[x,y,], {x, 0, 5}, {y, 0, 5}]

For one dimension, I would use the Simpson rule from the mentioned post, but is it possible to extend it to calculate the following integral?

$\endgroup$

1 Answer 1

1
$\begingroup$
Integrate[f[x, y], {x, 0, 5}, {y, 0, 5}](*625/4*)

integration weights

g = Table[1, {x, 0, 5}, {y, 0, 5}];
g[[All, 1]] = g[[1, All ]] = g[[All, 6]] = g[[6, All ]] = 1/2;
g[[1, 1]] = g[[1, 6]] = g[[6, 1]] = g[[6, 6]] = 1/4;

enter image description here

numerical integration

Flatten[g L] // Total (* 625/4 *)
$\endgroup$
9
  • $\begingroup$ Thank you very much, can you explain, why you take such weights? $\endgroup$
    – blahblah
    Commented Apr 26 at 8:23
  • $\begingroup$ @blahblah Have a look at the grid: Neighborhood of inner points is one, boundary points (except corners) is 1/2 and corners is 1/4. Sum of all weights should be 25 $\endgroup$ Commented Apr 26 at 9:07
  • $\begingroup$ Ok, I understand, but why the sum should be 25 if the array is 6x6? $\endgroup$
    – blahblah
    Commented Apr 26 at 10:57
  • 1
    $\begingroup$ Check the neighbourhood of your new gridpoints: innerpoints .1^2,boundary points .1^2/2, corner points .1^2/4 $\endgroup$ Commented May 28 at 11:19
  • 1
    $\begingroup$ Yes , seems to be correct! $\endgroup$ Commented May 28 at 11:56

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.