我想使用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