I came with a the following code to evaluate a double integral using Gauss Legendre quadrature in MatLab
m=100; %generate weights and abscissas [wx,xx]=leg(-1,1,m); [wtheta,xtheta]=leg(0,2.*pi,m); %define function psi=@(x,theta) hypergeom(-3./4,1./2,x.^2.*exp(1i.*theta)); %integrate with respect to x intx=zeros(1,m); for num=1:m intx(num)=sum(wx.*psi(xx,xtheta(num))); end sum(wtheta.*intx)
I defined the function leg(x1,x2,m) in a different script to generate the weights and abscissas and I just call it in my code. My MatLab code runs significanlty slowly compared to NIntegrate of Mathematica.
I'd like to make my code faster because my idea of using MatLab is that it is faster than Mathematica. Is there any way I can make my code run faster?
Attached is a profile summary when i ran the code