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]=eig_ode2_ex3(n,dom,kind,numeigval)
function [lam,phi,x]=eig_ode2_ex3(n,dom,kind,numeigval)
% Example: - y'' + x y = lam y, y(0)=0, y(50)=0 (Airy)
% call: [lam,phi,x]=eig_ode2_ex3(128,[0 50],2,5);
%
tic;A=zeros(n);B=zeros(n);phi=zeros(n,numeigval);
[x,w]=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=-D^2+X;B=speye(n);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    T=cpv(n,dom,dom);
    A(n-1,:)=T(1,:);B(n-1,:)=A(n-1,:)/1.e8;
    A(n,:)=T(2,:);B(n,:)=A(n,:)/1.e8;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    for i=1:numeigval
        I=w*(phi(:,i).^2);
        phi(:,i)=phi(:,i)/sqrt(I);
    end
    display('test1: orthogonality of the eigenfunctions');
    for i=1:numeigval
        for j=1:numeigval
            I(i,j)=w*(phi(:,i).*phi(:,j));
        end
    end
    display(I);
    display('test2: calculate eigenvalues, plot eigenfunctions');
    display('the eigenvalues are the roots of airy(-lam)');
    airy(-lam)
    for k=1:numeigval
        figure(k);plot(x,phi(:,k));grid;
        xlabel('x');ylabel(['\phi_',num2str(k)]);
        title(['\lambda_{',num2str(k),'}= ',num2str(lam(k))]);
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end


Contact us