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,tau]=eig42E(n,dom,kind,numeigval)
function [lam,phi,x,tau]=eig42E(n,dom,kind,numeigval)
%
% From: DAVID R. GARDNER, STEVEN A. TROGDON, ROD W. DOUGLASS,  
% A Modified Tau Spectral Method That Eliminates Spurious Eigenvalues, 
% JOURNAL OF COMPUTATIONAL PHYSICS 80, 137-167 (1989) Example 1, R=0

% y^(4)=lambda y'', x in [-1 1]
% y(-1)=y'(-1)=y(1)=y'(1)=0
% 
% Call: [lam,phi,x,tau]=eig42E(64,[-1 1],2,60);
% Calculates the eigenvalues, the eigenfunctions and the tau coefficients
%
tic;tau=zeros(4,numeigval);
T=cpv(n,dom,dom);x=pd(n,dom,kind);D=deriv(n,dom);
ntau=zeros(numeigval,1);
A=D^4;B=D^2;AA=A;BB=B;BB(n-3:n,:)=zeros(4,n);
AA(n-3:n,:)=[T(1,:);T(2,:);T(1,:)*D;T(2,:)*D];
A11=AA(1:n-4,1:n-4);A12=AA(1:n-4,n-3:n);
A21=AA(n-3:n,1:n-4);A22=AA(n-3:n,n-3:n);
B11=BB(1:n-4,1:n-4);B12=BB(1:n-4,n-3:n);
AAA=A11-A12*(A22\A21);BBB=B11-B12*(A22\A21);
%
[VV,L]=eig(full(AAA),full(BBB));lam=diag(L);
V=[VV;A22\A21*VV];phi=t2x(V,kind);
for s=1:numeigval
    tau(:,s)=(A(n-3:n,:)-lam(s)*B(n-3:n,:))*V(:,s);ntau(s)=norm(tau(:,s));
end
toc;
[lam,ind]=sort(lam,'descend');tau=tau(:,ind);ntau=ntau(ind);
disp([lam(3:7),ntau(3:7)]);
end

Contact us