我提供了以下代码来评估在 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)
我在不同的脚本中定义了函数 leg(x1,x2,m) 来生成权重和横坐标,我只是在我的代码中调用它。与 Mathematica 的 NIntegrate 相比,我的 MatLab 代码运行缓慢。
我想让我的代码更快,因为我使用 MatLab 的想法是它比 Mathematica 更快。有什么办法可以让我的代码运行得更快?
附件是我运行代码时的个人资料摘要