我想使用Gauss-Legendre积分来评估双积分。我想出了以下代码使用Gauss-Legendre正交的双重积分
m=5000;
%generate weights and abscissas
[wx,xx]=leg(-1,1,m);
[wy,xy]=leg(-1,1,m);
%define function
[email protected](x,y) hypergeom(-1./4,3./2,x.^2.*y.^6);
%integrate with respect to x
intx=zeros(1,m);
for num=1:m
intx(num)=sum(wx.*psi(xx,yx(num)));
end
sum(wy.*intx)
我使用符号腿(x1,x2,m)来生成权重和横坐标。
有没有其他方法可以让这段代码更快运行?
你为什么不定义为环外的磅?但是,这仍然不应该成为你的瓶颈。你有没有尝试分析你的代码?你可以通过按钮“运行和时间”来访问它 –
当我把psi放在lopp之外时发生错误。它说价值y是未定义的 – PhilCsar
尝试了你的建议,但代码仍然运行非常缓慢 – PhilCsar