From 88295a9295ee0470565ffdae4e451bcf02cbe047 Mon Sep 17 00:00:00 2001 From: pbrubeck Date: Tue, 6 Dec 2016 11:31:17 -0600 Subject: [PATCH] Rename Quadratures --- Analysis/LegendreSeries.m | 2 +- Analysis/hermSeries.m | 2 +- Integration/ClenshawCurtis.m | 10 +++++----- Integration/{GaussChebyshev.m => gaucheb.m} | 2 +- Integration/{GaussHermite.m => gauherm.m} | 2 +- Integration/{GaussJacobi.m => gaujac.m} | 4 ++-- Integration/{GaussLaguerre.m => gaulag.m} | 4 ++-- Integration/{GaussLegendre.m => gauleg.m} | 2 +- PDE/heatExp.m | 2 +- Physics/brachistochrone.m | 2 +- Physics/schrodCayley.m | 2 +- Physics/schrodExp.m | 2 +- Physics/schrodPolar.m | 2 +- Sandbox/besselPlot.m | 2 +- Sandbox/eigKernel.m | 2 +- Solitons/nlsecheb.m | 2 +- Spectral/hermD.m | 8 +++++--- Spectral/lagD.m | 2 +- 18 files changed, 28 insertions(+), 26 deletions(-) rename Integration/{GaussChebyshev.m => gaucheb.m} (81%) rename Integration/{GaussHermite.m => gauherm.m} (84%) rename Integration/{GaussJacobi.m => gaujac.m} (73%) rename Integration/{GaussLaguerre.m => gaulag.m} (63%) rename Integration/{GaussLegendre.m => gauleg.m} (85%) diff --git a/Analysis/LegendreSeries.m b/Analysis/LegendreSeries.m index 1b00128..666cf28 100755 --- a/Analysis/LegendreSeries.m +++ b/Analysis/LegendreSeries.m @@ -1,7 +1,7 @@ function [c, Q] = LegendreSeries(f, a, b, n) % Calculates the Legendre expansion of f over the interval [a,b]. % Additionally returns the equivalent polynomial. -[x, w]=GaussLegendre(-1, 1, n+1); +[x, w]=gauleg(-1, 1, n+1); P=Legendre(n); y1=Horner(P, x); y2=f(((b-a)*x+b+a)/2); diff --git a/Analysis/hermSeries.m b/Analysis/hermSeries.m index 208c4a5..2e53257 100644 --- a/Analysis/hermSeries.m +++ b/Analysis/hermSeries.m @@ -1,6 +1,6 @@ function [ c ] = hermSeries(f, n) sig=1/sqrt(2); -[x,w]=GaussHermite(n,0,sig); +[x,w]=gauherm(n,0,sig); Psi=zeros(n); a=zeros(n,1); a(end)=1; for i=1:n diff --git a/Integration/ClenshawCurtis.m b/Integration/ClenshawCurtis.m index f5dacd4..3ead5fb 100755 --- a/Integration/ClenshawCurtis.m +++ b/Integration/ClenshawCurtis.m @@ -1,9 +1,9 @@ function [x, w] = ClenshawCurtis(a, b, n) % Returns abscissas and weights for the corresponding Clenshaw-Curtis -% (n+1)-point quadrature over the interval [a, b]. -th=(0:n)*pi/n; +% n-point quadrature over the interval [a, b]. +th=(0:n-1)*pi/(n-1); x=(b-a)/2*cos(th)+(b+a)/2; -d=1./(1-(0:2:n).^2); -c=ifft([d, d(ceil(n/2):-1:2)], 'symmetric'); -w=(b-a)*[c(1)/2, c(2:n), c(1)/2]; +d=1./(1-(0:2:n-1).^2); +c=ifft([d, d(ceil((n-1)/2):-1:2)], 'symmetric'); +w=(b-a)*[c(1)/2, c(2:n-1), c(1)/2]; end \ No newline at end of file diff --git a/Integration/GaussChebyshev.m b/Integration/gaucheb.m similarity index 81% rename from Integration/GaussChebyshev.m rename to Integration/gaucheb.m index cb1eb10..3cf148d 100755 --- a/Integration/GaussChebyshev.m +++ b/Integration/gaucheb.m @@ -1,4 +1,4 @@ -function [x, w] = GaussChebyshev(a, b, n) +function [x, w] = gaucheb(a, b, n) % Returns abscissas and weights for the Gauss-Chebyshev n-point quadrature % over the interval [a, b]. th=pi*(1:2:2*n-1)/(2*n); diff --git a/Integration/GaussHermite.m b/Integration/gauherm.m similarity index 84% rename from Integration/GaussHermite.m rename to Integration/gauherm.m index bc33e58..4a62692 100755 --- a/Integration/GaussHermite.m +++ b/Integration/gauherm.m @@ -1,4 +1,4 @@ -function [x, w] = GaussHermite(n, mu, sigma) +function [x, w] = gauherm(n, mu, sigma) % Returns abscissas and weights for the Gauss-Hermite n-point quadrature % over the interval [-inf, inf] using the Golub-Welsch Algorithm. E=sqrt((1:n-1)/2); diff --git a/Integration/GaussJacobi.m b/Integration/gaujac.m similarity index 73% rename from Integration/GaussJacobi.m rename to Integration/gaujac.m index bb86fd3..093494d 100644 --- a/Integration/GaussJacobi.m +++ b/Integration/gaujac.m @@ -1,6 +1,6 @@ -function [x, w] = GaussJacobi(a,b,n) +function [x, w] = gaujac(a,b,n) % Returns abscissas and weights for the Gauss-Jacobi n-point quadrature -% over the interval [-1, 1] using the Golub-Welsch Algorithm. +% over the interval [a, b] using the Golub-Welsch Algorithm. k=1:n; c=2*k+a+b; D=(b^2-a^2)./(c.*(c-2)+(b^2==a^2)); diff --git a/Integration/GaussLaguerre.m b/Integration/gaulag.m similarity index 63% rename from Integration/GaussLaguerre.m rename to Integration/gaulag.m index 2adc6ea..c0452d6 100755 --- a/Integration/GaussLaguerre.m +++ b/Integration/gaulag.m @@ -1,6 +1,6 @@ -function [x, w] = GaussLaguerre(alpha, n) +function [x, w] = gaulag(alpha, n) % Returns abscissas and weights for the Gauss-Laguerre n-point quadrature -% over the interval [0, inf] using the Golub-Welsch Algorithm. +% over the interval [0, inf) using the Golub-Welsch Algorithm. k=(1:n); D=2*k-1+alpha; E=sqrt(k.*(k+alpha)); diff --git a/Integration/GaussLegendre.m b/Integration/gauleg.m similarity index 85% rename from Integration/GaussLegendre.m rename to Integration/gauleg.m index 3302e9f..99ed9d0 100755 --- a/Integration/GaussLegendre.m +++ b/Integration/gauleg.m @@ -1,4 +1,4 @@ -function [x, w] = GaussLegendre(a, b, n) +function [x, w] = gauleg(a, b, n) % Returns abscissas and weights for the Gauss-Legendre n-point quadrature % over the interval [a, b] using the Golub-Welsch Algorithm. k=1:n-1; diff --git a/PDE/heatExp.m b/PDE/heatExp.m index d4f4bb9..2de447b 100644 --- a/PDE/heatExp.m +++ b/PDE/heatExp.m @@ -1,7 +1,7 @@ function [] = heatExp( N ) dt=0.001; -[x,w]=GaussLegendre(-1,1,N); x=x(:); w=w(:); +[x,w]=gauleg(-1,1,N); x=x(:); w=w(:); V=exp(1i*pi/2*x*(-N/2:N/2-1))/sqrt(2); L=-pi^2/4*(-N/2:N/2-1)'.^2; diff --git a/Physics/brachistochrone.m b/Physics/brachistochrone.m index bf9fe4f..b60be2b 100644 --- a/Physics/brachistochrone.m +++ b/Physics/brachistochrone.m @@ -2,7 +2,7 @@ global D x w y1 y2 h; L=20; -[~,w]=ClenshawCurtis(-1,1,n-1); w=w(:); +[~,w]=ClenshawCurtis(-1,1,n); w=w(:); [D,x]=chebD(n); y1=0; diff --git a/Physics/schrodCayley.m b/Physics/schrodCayley.m index f02254e..7a30782 100644 --- a/Physics/schrodCayley.m +++ b/Physics/schrodCayley.m @@ -10,7 +10,7 @@ Psi=(-(r-R1).*(r-R2).*(r-(R1+R2)/2))*sin(3*th.^2/(2*pi)); -[x,w]=ClenshawCurtis(R1,R2,N-1); +[x,w]=ClenshawCurtis(R1,R2,N); W=diag(w); Psi=Psi/sqrt(sum(r'*W*abs(Psi).^2)*(2*pi/N)); diff --git a/Physics/schrodExp.m b/Physics/schrodExp.m index 0f5b322..d55b005 100644 --- a/Physics/schrodExp.m +++ b/Physics/schrodExp.m @@ -1,6 +1,6 @@ function [] = schrodExp( N ) [D,x]=chebD(N); -[~,w]=ClenshawCurtis(-1,1,N-1); +[~,w]=ClenshawCurtis(-1,1,N); dt=0.001; V0=1000; diff --git a/Physics/schrodPolar.m b/Physics/schrodPolar.m index 5b4c41d..9a76122 100644 --- a/Physics/schrodPolar.m +++ b/Physics/schrodPolar.m @@ -20,7 +20,7 @@ mu=diag(mu); Phi=Phi/sqrt(2*pi/N); -[x,w]=ClenshawCurtis(R1,R2,N-1); +[x,w]=ClenshawCurtis(R1,R2,N); W=diag(w(2:end-1)); E=zeros(k,k); diff --git a/Sandbox/besselPlot.m b/Sandbox/besselPlot.m index b79fd9e..09d96c4 100644 --- a/Sandbox/besselPlot.m +++ b/Sandbox/besselPlot.m @@ -1,7 +1,7 @@ m=0; rlim=100; r=linspace(-rlim,rlim,2048)'; -[tau,w]=GaussLegendre(-pi,pi,256); +[tau,w]=gauleg(-pi,pi,256); f=exp(1i*(m*ones(size(r))*tau-r*sin(tau))); J=1/(2*pi)*f*w'; diff --git a/Sandbox/eigKernel.m b/Sandbox/eigKernel.m index 2bb0b47..c9adc0e 100755 --- a/Sandbox/eigKernel.m +++ b/Sandbox/eigKernel.m @@ -1,5 +1,5 @@ n=512; p=0; a=-4; b=4; -[x,w]=GaussLegendre(a,b,n); +[x,w]=gauleg(a,b,n); x2 = x.^2; r=exp(0.5i*x2); diff --git a/Solitons/nlsecheb.m b/Solitons/nlsecheb.m index 49b14ec..6550e5c 100644 --- a/Solitons/nlsecheb.m +++ b/Solitons/nlsecheb.m @@ -5,7 +5,7 @@ % Domain substitution x=tan(th), u=sec(th).*w [Dt,th]=chebD(N); th=pi/2*th; Dt=2/pi*Dt; x=tan(th); -[~,w]=ClenshawCurtis(-pi/2,pi/2,N-1); +[~,w]=ClenshawCurtis(-pi/2,pi/2,N); w=(sec(th).^2).*w(:); T=-1/2*diag(cos(th).^4)*(eye(N)+Dt*Dt); diff --git a/Spectral/hermD.m b/Spectral/hermD.m index 9cbd7c5..e3ccee7 100644 --- a/Spectral/hermD.m +++ b/Spectral/hermD.m @@ -1,9 +1,11 @@ function [D, x, w] = hermD(N) % Hermite spectral differentiation matrix -[x,w]=GaussHermite(N,0,1/sqrt(2)); -x=x(:); w=w(:).*exp(x.^2); +[x,w]=gauherm(N,0,1/sqrt(2)); +x=x(:); a(N)=1; +h=HermitePsi(a,x); X=repmat(x,[1, N]); -H=repmat(HermitePsi(a,x),[1, N]); +H=repmat(h,[1, N]); D=(H./H'-eye(N))./(X-X'+eye(N)); +w=1./(N*h.^2); end \ No newline at end of file diff --git a/Spectral/lagD.m b/Spectral/lagD.m index 6d42899..70cd577 100644 --- a/Spectral/lagD.m +++ b/Spectral/lagD.m @@ -1,6 +1,6 @@ function [D,x,w] = lagD(N) % Laguerre spectral differentiation matrix -[x,w]=GaussLaguerre(1,N-1); x=x(:); w=w(:); +[x,w]=gaulag(1,N-1); x=x(:); w=w(:); X=repmat([0;x], [1, N]); c(N-1)=1; L=[N; -x.*LaguerreL(c,2,x).*exp(-x/2)];