You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
847 B
24 lines
847 B
% GAUSS Gauss quadrature rule.
|
|
%
|
|
% Given a weight function w encoded by the nx2 array ab of the
|
|
% first n recurrence coefficients for the associated orthogonal
|
|
% polynomials, the first column of ab containing the n alpha-
|
|
% coefficients and the second column the n beta-coefficients,
|
|
% the call xw=GAUSS(n,ab) generates the nodes and weights xw of
|
|
% the n-point Gauss quadrature rule for the weight function w.
|
|
% The nodes, in increasing order, are stored in the first
|
|
% column, the n corresponding weights in the second column, of
|
|
% the nx2 array xw.
|
|
%
|
|
function xw=gauss(N,ab)
|
|
N0=size(ab,1); if N0<N, error('input array ab too short'), end
|
|
J=zeros(N);
|
|
for n=1:N, J(n,n)=ab(n,1); end
|
|
for n=2:N
|
|
J(n,n-1)=sqrt(ab(n,2));
|
|
J(n-1,n)=J(n,n-1);
|
|
end
|
|
[V,D]=eig(J);
|
|
[D,I]=sort(diag(D));
|
|
V=V(:,I);
|
|
xw=[D ab(1,2)*V(1,:)'.^2];
|
|
|