Graphics Programs Reference
In-Depth Information
k ( n )
(2 n )!
f (2 n ) ( c ),
E
=
0
<
c
<
1
(6.39)
where k (2)
=
0
.
00 285, k (3)
=
0
.
000 17, k (4)
=
0
.
000 01.
gaussNodes
The function gaussNodes computes the nodal abscissas x i and the corresponding
weights A i usedinGauss-Legendrequadrature. 14
It can be shown that the approxi-
mate values of the abscissas are
cos π
.
( i
0
25)
x i =
n
+
0
.
5
Using these approximations as the starting values, wecompute the nodal ab-
scissas by finding the nonnegativezeros of the Legendre polynomial p n ( x ) with
the Newton-Raphsonmethod (the negativezeros areobtained from symmetry).
Note that gaussNodes calls the subfunction legendre , which returns p n ( t ) and its
derivative.
function [x,A] = gaussNodes(n,tol)
% Computes nodal abscissas x and weights A of
% Gauss-Legendre n-point quadrature.
% USAGE: [x,A] = gaussNodes(n,epsilon,maxIter)
% tol = error tolerance (default is 1.0e4*eps).
if nargin < 2; tol = 1.0e4*eps; end
A=zeros(n,1);x=zeros(n,1);
nRoots = fix(n + 1)/2;
% Number of non-neg. roots
fori=1:nRoots
t = cos(pi*(i - 0.25)/(n + 0.5)); % Approx. roots
forj=i:30
[p,dp] = legendre(t,n);
% Newton's
dt=-p/dp;t=t+dt;
%rootfinding
if abs(dt) < tol
% method
x(i) = t; x(n-i+1) = -t;
A(i) = 2/(1-tˆ2)/dpˆ2;
% Eq. (6.25)
A(n-i+1) = A(i);
break
14
Thisfunctionis an adaptation of aroutine in Numerical Recipes in Fortran 90 , W. H. Press et al.,
CambridgeUniversity Press (1996).
Search WWH ::




Custom Search