Code covered by the BSD License  

Highlights from
LaguerreEig

image thumbnail
from LaguerreEig by Damian Trif
Calculates numerical eigenvalues and eigenfunctions of Schroedinger problems on (0,infinity).

[x,w,T,iT,X,D]=lagtool(n,b)
function [x,w,T,iT,X,D]=lagtool(n,b)
% Tools for Laguerre spectral method 
%
% input:   n - number of gridpoints
%          b - scaling factor
%    
% output:  x - the (Laguerre) grid (n x 1)
%          w - the corresponding weights (1 x n)
%   		Warning! int(f(x),x=0:inf)=w*f(x)
%
%          X - the multiplication by x matrix
%          D - the spectral differentiation matrix
%          T - the transpose of the conversion matrix
%         iT - the inverse of T
%  
% From: Gerald Moore
% Math. Comp. 73(245) 2004, pp. 211-242
%
if nargin < 2, b=1;end
d=-(1:n-1);f=1:2:2*n-1;
X=(diag(d,-1)+diag(f)+diag(d,1))/b;
[S,D]=eig(X);x=diag(D);
%test=norm(X*S-S*D)
S=S*diag(sign(S(1,:)))/sqrt(b);
D=-triu(ones(n))+eye(n)/2;D=b*D;
p=exp(b*x/2+log(S(1,:)'));w=p'.^2;
T=diag(1./p)*S';
iT=S*diag(p)*b;

Contact us at files@mathworks.com