I have an array of values $f[x,y]$ which was calculated numerically for "grid" ${x,y}$ and I have steps ${dx,dy}$.

I would like to know how can I perform numerical integration, $$\sum_{i,j}dx_idx_jf(x_i,y_j)$$ with high precision. I use simply


I assume that there is a function in Mathematica which does it with higher precision. Or, can anyone suggest where can I found Mathematica realizations of methods of numerical integration (like Simpson's rule, etc.)

  • 2
    $\begingroup$ I recently did such an operation with an array {x,y,z}, where x and y represented points on an irregular mesh, and z - the values in these points. I did it as follows. First, used the 1st order interpolation to get an interpolation function. Second, I integrated it using NIntegrate routine, and, by trial and error, selected a suitable numeric strategy. Hope this helps. $\endgroup$ Jun 28, 2020 at 12:21
  • 1
    $\begingroup$ array.dy.dx is a speedier equivalent to your Sum, assuming array is the array of values $f[x_i,y_j]$. Your Sum code suggests you have access to f, so you could use NIntegrate on it. With NIntegrate, you would probably get a more satisfactory result. If you have access only to the data, then interpolating as @Alexei suggests is a good idea. Most likely one could avoid NIntegrate and directly apply the rule associated with interpolation, or use FEM to do it. $\endgroup$
    – Michael E2
    Jun 28, 2020 at 15:09
  • $\begingroup$ @MichaelE2 unfortunately I have extremely small values of f[x,y]. Thank you for advice with array.dy.dx. Can I simply use my array as the argument of NIntegrate? $\endgroup$ Jun 28, 2020 at 15:15
  • $\begingroup$ No, the argument to NIntegrate has to be a function. $\endgroup$
    – Michael E2
    Jun 28, 2020 at 15:19
  • $\begingroup$ @MichaelE2 firstly I misunderstand your point about f. I have not f explicitly. $\endgroup$ Jun 28, 2020 at 15:19


Your Answer

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

Browse other questions tagged or ask your own question.