/ concept-collection / windowedFourierProjection
Sign in
concept-collection / windowedFourierProjection
windowedFourierProjection / wfp_1Dspringscattering / utils / glwt_prep.m
64 lines · 1.4 KBBlameHistoryRaw
1function gl = glwt_prep(N)
2% GLWT_PREP to get GL nodes and weights on [-1,1]
3%
4% [y,w]=glwt_prep(N)
5% returns GL nodes 'y' and GL weights 'w' given a number of GL nodes 'N'
6%
7% Notes:
8% This script is for computing definite integrals using Legendre-Gauss
9% Quadrature. Computes the Legendre-Gauss nodes and weights on an interval
10% [a,b] with truncation order N
12% Suppose you have a continuous function f(x) which is defined on [a,b]
13% which you can evaluate at any x in [a,b]. Simply evaluate it at all of
14% the values contained in the x vector to obtain a vector f. Then compute
15% the definite integral using sum(f.*w);
17% Written by Greg von Winckel - 02/25/2004
19N=N-1;
20N1=N+1; N2=N+2;
22xu=linspace(-1,1,N1)';
24% Initial guess
25y=cos((2*(0:N)'+1)*pi/(2*N+2))+(0.27/N1)*sin(pi*xu*N/N2);
27% Legendre-Gauss Vandermonde Matrix
28L=zeros(N1,N2);
30% Derivative of LGVM
31Lp=zeros(N1,N2);
33% Compute the zeros of the N+1 Legendre Polynomial
34% using the recursion relation and the Newton-Raphson method
36y0=2;
38% Iterate until new points are uniformly within epsilon of old points
39while max(abs(y-y0))>eps
41 L(:,1)=1;
42 Lp(:,1)=0;
44 L(:,2)=y;
45 Lp(:,2)=1;
47 for k=2:N1
48 L(:,k+1)=( (2*k-1)*y.*L(:,k)-(k-1)*L(:,k-1) )/k;
49 end
51 Lp=(N2)*( L(:,N1)-y.*L(:,N2) )./(1-y.^2);
53 y0=y;
54 y=y0-L(:,N2)./Lp; % Newton's iteration
56end
58w= 1./((1-y.^2).*Lp.^2)*(N2/N1)^2;
61gl.x0 = y;
62gl.w0 = w;
64end
moveopenescclose