Code covered by the BSD License

# Chebpack

### Damian Trif (view profile)

15 Jul 2011 (Updated )

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

[lam,phi,x]=eig_ode3_test(n,dom,kind,numeigval)
function [lam,phi,x]=eig_ode3_test(n,dom,kind,numeigval)
% Example: y'''=lambda y, x in [-1,1]
%          y(-1)=y(1)=y'(-1)=0
% From: B. Fornberg, SIAM J. Sci. Comp., 28(5), 2006, pp. 1716-1729
% Exact eigenvalues: exp(3lam^(1/3))-2sin(sqrt(3)lam^(1/3)+pi/6)=0
% call: [lam,phi,x]=eig_ode3_test(32,[-1 1],2,10);
%
tic;A=zeros(n);B=zeros(n);phi=zeros(n,numeigval);
x=pd(n,dom,kind);D=deriv(n,dom);
myDE;myBC;
[V,L]=eig(full(A),full(B));
[LL,ind]=sort(diag(L));VV=V(:,ind);
lam=LL(1:numeigval);
for s=1:numeigval
phi(:,s)=t2x(VV(:,s),kind);
end
toc;myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
% describes the differential operator
A=D^3;B=eye(n);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
% implements the homogeneous boundary conditions
T=cpv(n,dom,dom);
A(n-2,:)=T(1,:);B(n-2,:)=A(n-2,:)/1.e8;% y(-1)=0
A(n-1,:)=T(1,:)*D;B(n-1,:)=A(n-1,:)/1.e8;% y'(-1)=0
A(n,:)=T(2,:);B(n,:)=A(n,:)/1.e8;% y(1)=0
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
exact=exp(3*nthroot(lam,3))-2*sin(sqrt(3)*nthroot(lam,3)+pi/6);
display(['        lambda  ','           test (=0)']);display([lam,exact]);
xx=linspace(dom(1),dom(2),1000);
for k=1:5
figure(k);
fx = barycheb(xx,phi(:,k),x,kind);
plot(xx,fx);grid;
title(['\lambda_{',num2str(k),'} = ',num2str(lam(k))]);
xlabel('x');ylabel(['\phi_{',num2str(k),'}(x)']);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end