# Numerical integration: efficiency and precision

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

Sum[dx[[i]]*dy[[j]]*f[x[[i]],y[[j]]],{i,Lenth[x]},{j,Length[y]}


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.)

• 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. Commented Jun 28, 2020 at 12:21
• 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. Commented Jun 28, 2020 at 15:09
• @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? Commented Jun 28, 2020 at 15:15
• No, the argument to NIntegrate has to be a function. Commented Jun 28, 2020 at 15:19
• @MichaelE2 firstly I misunderstand your point about f. I have not f explicitly. Commented Jun 28, 2020 at 15:19