Skip to content

Commit

Permalink
Rename Quadratures
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Dec 6, 2016
1 parent 314d995 commit 88295a9
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Analysis/LegendreSeries.m
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Analysis/hermSeries.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions Integration/ClenshawCurtis.m
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Integration/GaussChebyshev.m → Integration/gaucheb.m
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Integration/GaussHermite.m → Integration/gauherm.m
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Integration/GaussJacobi.m → Integration/gaujac.m
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
4 changes: 2 additions & 2 deletions Integration/GaussLaguerre.m → Integration/gaulag.m
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Integration/GaussLegendre.m → Integration/gauleg.m
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PDE/heatExp.m
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Physics/brachistochrone.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Physics/schrodCayley.m
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion Physics/schrodExp.m
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Physics/schrodPolar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Sandbox/besselPlot.m
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion Sandbox/eigKernel.m
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Solitons/nlsecheb.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions Spectral/hermD.m
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Spectral/lagD.m
Original file line number Diff line number Diff line change
@@ -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)];
Expand Down

0 comments on commit 88295a9

Please sign in to comment.