This is a very simple program that makes use of Matlab's trapz (single integral). It has the benefit that it can be used to integrate over vectors x, y, and the function f(x,y), rather than on lower and upper limits. It can also be used with nonuniform spacing at the input vectors.
Example of nonuniform spacing:
Yes, that's a nice statement. But, I think it should be (according to the latest change)
result = trapz(y,trapz(x,mat,1),2);
Although I think keeping it as is is more illustrative. I will add it as a comment.
Thanks for the comment.
N.B. I am still not sure if it would perform faster/better than quad2d if one use it with empirical data.
Could be replaced with a single line:
result = trapz(x,trapz(y,mat,1),2);
Considering the suggestion
Thanks Richard :)
A simple correction to the example.
Modification so that the input matrix is MxN rather than NxN.
Adding one extra tag, keyword.
Adding one line to the code.
Doing corrections to the comments.
Correcting the description.