使用 Gauss-Legendre 积分的双重积分
Double integration using Gauss-Legendre quadrature
我想用 Gauss-Legendre 求积求二重积分。我想出了以下代码
m=5000;
%generate weights and abscissas
[wx,xx]=leg(-1,1,m);
[wy,xy]=leg(-1,1,m);
%define function
psi=@(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)
我使用符号 leg(x1, x2, m) 生成权重和横坐标。
有没有其他方法可以使这段代码 运行 更快?
假设 w 是一个行向量,您可以使用 meshgrid 复制 y 、 x 然后进行矩阵乘法:
m = 5000;
[w,x]=leg(-1,1,m);
[X, Y] = meshgrid(x);
psi=@(x,y) hypergeom(-1./4,3./2,x.^2.*y.^6);
result = w * psi(X,Y) * w';
我想用 Gauss-Legendre 求积求二重积分。我想出了以下代码
m=5000;
%generate weights and abscissas
[wx,xx]=leg(-1,1,m);
[wy,xy]=leg(-1,1,m);
%define function
psi=@(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)
我使用符号 leg(x1, x2, m) 生成权重和横坐标。
有没有其他方法可以使这段代码 运行 更快?
假设 w 是一个行向量,您可以使用 meshgrid 复制 y 、 x 然后进行矩阵乘法:
m = 5000;
[w,x]=leg(-1,1,m);
[X, Y] = meshgrid(x);
psi=@(x,y) hypergeom(-1./4,3./2,x.^2.*y.^6);
result = w * psi(X,Y) * w';