我正在使用MATLAB和这个函数。
function [x,w,P]=lglnodes(N)
% Truncation + 1
N1=N+1;
x=cos(pi*(0:N)/N)';
% Legendre Vandermonde Matrix
P=zeros(N1,N1);
xold=2;
while max(abs(x-xold))>eps
xold=x;
P(:,1)=1; P(:,2)=x;
for k=2:N
P(:,k+1)=( (2*k-1)*x.*P(:,k)-(k-1)*P(:,k-1) )/k;
end
x=xold-( x.*P(:,N1)-P(:,N) )./( N1*P(:,N1) );
end
w=2./(N*N1*P(:,N1).^2);
有了这个函数,我得到了权重和节点,我可以在上面整合我喜欢的函数。例如,我可以调用 lglnodes(400 - 1)
并获得节点和权重的 N = 400
. 然后我有这个代码。
我想对Gauss-Laguerre(GaussLaguerre(n, alpha)
函数),但我不明白如何使用这些输入来获得和上面差不多的权重。你能给我解释一下如何调整输入吗?如何设置 n
和 alpha
?
Gauss-Lobatto和Gauss-Laguerre是两种不同积分的积分权重。
x^alpha exp(-x)
.你不能指望永远得到相同的重量。