gquad2.m

来自「小的源码Matlab编程」· M 代码 · 共 29 行

M
29
字号

function [s, w, x] = Gquad2(fun, n, type, varargin)

% Numerical integration using either the Gauss-Laguerre
% (type = 'L') or the Gauss-Hermite (type = 'H') with n (n > 0) nodes. 
% fun is a string containing the name of the function that is 
% integrated.
% The output parameters s, w, and x hold the computed approximation
% of the integral, list of weights, and the list of nodes, 
% respectively. 

if type == 'L'
   d = -(1:n-1);
   f = 1:2:2*n-1;
   fc = 1;
else
   d = sqrt(.5*(1:n-1));
   f = zeros(1,n);
   fc = sqrt(pi);
end
J = diag(d,-1) + diag (f) + diag(d,1);
[u,v] = eig(J);
[x,j] = sort(diag(v));
w = (fc*u(1,:).^2)';
w = w(j);
f = feval(fun,x,varargin{:});
s = w'*f(:);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?