Code covered by the BSD License  

Highlights from
Chebpack

image thumbnail

Chebpack

by

 

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

[lam,phi,x]=KdV_eig(n,dom,kind,numeigval)
function [lam,phi,x]=KdV_eig(n,dom,kind,numeigval)
% From: W. Heinrichs, Spectral Approximation of third order problems,
% Journal of Scientific Computing, Volume 14, Issue 3, pp 275-289 (1999)
%
% y'''=\lambda y, x in [-1,1]
% y(-1)=y(1)=0=y'(-1), 
%
% Call: [lam,phi,x]=KdV_eig(64,[-1 1],2,15);
% Calculates the eigenvalues and the eigenfunctions
%
tic;A=zeros(n);B=zeros(n);phi=zeros(n,numeigval);
x=pd(n,dom,kind);X=mult(n,dom);D=deriv(n,dom);T=cpv(n,dom,dom);E=speye(n);
F=(E-X)*(E+X)^2;A=F*D^3*F;B=F*F;A=A(1:n-3,1:n-3);B=B(1:n-3,1:n-3);
%
[V,L]=eig(full(A),full(B));
[LL,ind]=sort(diag(L),'ascend');VV=V(:,ind);
lam=LL(1:numeigval);
for s=1:numeigval
    phi(:,s)=t2x(F*[VV(:,s);0;0;0],kind);
end
toc;
for k=1:numeigval
if isreal(lam(k)),s3=nthroot(lam(k),3);
    err(k)=exp(3*s3)-2*sin(sqrt(3)*s3+pi/6);
else err(k)=0;
end
end
[xx,ww]=pd(n,dom,3);
for k=1:5
    figure(k);
    fx(:,k) = barycheb(xx,phi(:,k),x,kind);
    plot(xx,fx(:,k));grid;
    title(['\lambda_{',num2str(k),'} = ',num2str(lam(k))]);
    xlabel('x');ylabel(['\phi_{',num2str(k),'}(x)']);
end
disp([lam,err']);I=wip(fx,fx,ones(n,1),ww);disp(I);
figure(6);semilogx(real(lam),imag(lam),'*k');
grid;xlabel('real(\lambda)');ylabel('imag(\lambda)');
end

Contact us