Graphics Programs Reference
In-Depth Information
end
end
end
function [p,dp] = legendre(t,n)
% Evaluates Legendre polynomial p of degree n
%anditsderivativedpatx=t.
p0=1.0;p1=t;
fork=1:n-1
p = ((2*k + 1)*t*p1 - k*p0)/(k + 1); % Eq. (6.19)
p0=p1;p1=p;
end
dp=n*(p0-t*p1)/(1-tĖ†2);
%Eq.(6.21)
gaussQuad
The function gaussQuad evaluates b
a f ( x ) dx with Gauss-Legendrequadrature us-
ing n nodes. The functiondefining f ( x ) must besuppliedbythe user. The nodal
abscissas and the weights areobtainedbycalling gaussNodes .
functionI=gaussQuad(func,a,b,n)
% Gauss-Legendre quadrature.
%USAGE:I=gaussQuad(func,a,b,n)
% INPUT:
%func=handleoffunctiontobeintegrated.
% a,b = integration limits.
% n = order of integration.
% OUTPUT:
%I=integral
c1=(b+a)/2;c2=(b-a)/2; %Mappingconstants
[x,A] = gaussNodes(n);
% Nodal abscissas & weights
sum=0;
fori=1:length(x)
y = feval(func,c1 + c2*x(i)); % Function at node i
sum = sum + A(i)*y;
end
I = c2*sum;
EXAMPLE 6.8
Evaluate 1
āˆ’
x 2 ) 3 / 2 dx as accuratelyas possible with Gaussian integration.
1 (1
āˆ’
Search WWH ::




Custom Search