glnodewt.m
来自「这是《Numerical Methods with MATLAB: Imple」· M 代码 · 共 23 行
M
23 行
function [x,w] = GLNodeWt(n)
% GLNodeWt Nodes and weights for Gauss-Legendre quadrature of arbitrary order
% obtained by solving an eigenvalue problem
%
% Synopsis: [x,w] = GLNodeWt(n)
%
% Input: n = order of quadrature rule
%
% Output: x = vector of nodes
% w = vector of weights
% Algorithm based on ideas from Golub and Welsch, and Gautschi. For a
% condensed presentation see H.R. Schwarz, "Numerical Analysis: A
% Comprehensive Introduction," 1989, Wiley. Original MATLAB
% implementation by H.W. Wilson and L.H. Turcotte, "Advanced Mathematics
% and Mechanics Applications Using MATLAB," 2nd ed., 1998, CRC Press
beta = (1:n-1)./sqrt(4*(1:n-1).^2 - 1);
J = diag(beta,-1) + diag(beta,1); % eig(J) needs J in full storage
[V,D] = eig(J);
[x,ix] = sort(diag(D)); % nodes are eigenvalues, which are on diagonal of D
w = 2*V(1,ix)'.^2; % V(1,ix)' is column vector of first row of sorted V
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?