I have such a integral at hand, I need to integrate it numerically in matlab. or if somebody can give a simple answer implemented in any language, it's also appreciated.
$$\int_0^a \int_0^a \phi(x_1) e^{-q|x_1-x_2|}\phi(x_2) dx_1dx_2$$
mesh.nn = 101; % number of nodes
mesh.x = linspace(0,a,mesh.nn); % node coordinates, m
[xx,yy] = meshgrid(mesh.x,mesh.x);
MM= exp(-qnorm*abs(yy-xx));
mat= (phi_1.' * phi_2).* MM;
V = trapz(mesh.x,trapz(mesh.x,mat,1),2);
Is there a reason you're not using
integral2in Matlab to perform quadrature integration? If you're using an older version of Matlab, tryquad2dordblquad. If the problem is that your function $\phi$ is numerical data rather than an analytical function, then you can still use interpolation. For example, if $\phi($PHI_XCOORDS$) = $PHI_DATAthen, usinginterp1:Since your code/equations are incomplete I can't really check if this will work or help you further though.