I need to write a MEX file to evaluate the double integral of an arbitrary function, since in Matlab the numerical integration is too slow. So far I was only able defining by hand all the possible functions that I use and parse a string in the MEX file to choose which one to integrate. This is very ugly. I would like to send to the MEX file directly the function, something like
myIntMex(@(x,y)f,0,1,0,1)
to integrate function f
in the interval [0,1]x[0,1]
.
So far the only option I have found is mexCallMATLAB
but I have also read that it is even slower than pure Matlab.
I have also found a free code here but it only works for single integrals.
So my question is: how do I do it? How do I give to the MEX file the function handle? Does a code for that already exists?