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_ode2_ex1(n,dom,kind,numeigval)
function [lam,phi,x]=eig_ode2_ex1(n,dom,kind,numeigval)
% Example: x^2y''+2xy'=-lambda^2 x^2 y, x in [0,1]
%          y'(0)=y(1)=0, (sinc problem)
% Exact eigenvalues: lambda_n=n*pi
% call: [lam,phi,x]=eig_ode2_ex1(128,[0 1],2,5);
%
tic;A=zeros(n);B=zeros(n);phi=zeros(n,numeigval);
x=pd(n,dom,kind);X=mult(n,dom);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
A=X^2*D^2+2*X*D;B=-X^2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
T=cpv(n,dom,dom);
A(n-1,:)=T(1,:)*D;B(n-1,:)=A(n-1,:)/1.e8;
A(n,:)=T(2,:);B(n,:)=A(n,:)/1.e8;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
display(sqrt(lam)/pi);
xx=linspace(dom(1),dom(2),1000);
fx = barycheb(xx,phi(:,5),x,kind);
plot(xx,fx);grid;title(['\lambda_5 = ',num2str(sqrt(lam(5))/pi)]);
xlabel('x');ylabel('\phi_5');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end