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_ex2(n,dom,kind,numeigval)
function [lam,phi,x]=eig_ode2_ex2(n,dom,kind,numeigval)
% Example: y''-V(x)y=-lambda y, x in [-pi/2,pi/2], 
%          y(-pi/2)=y(pi/2)=0, 
%          V(x)=-2 beta cos(2x)+beta^2 sin^2(2x) (Coffey-Evans potential)
% From: M. K. El Daou, International Journal of Computational and 
%       Mathematical Sciences, 3:4 2009, pp. 153-159
% call: [lam,phi,x]=eig_ode2_ex2(128,[-pi/2 pi/2],2,10);
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
    beta=20;S=funm(2*full(X),@sin);C=funm(2*full(X),@cos);
    V=-2*beta*C+beta^2*S^2;
    A=D^2-V;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
    display(lam);I=zeros(3);
    for k=1:3
        figure(k);plot(x,phi(:,k+6));grid;
        title(['lam(',num2str(k+6),')= ',num2str(lam(k+6))]);
        xlabel('x');ylabel(['\phi',num2str(k+6)]);
        for j=1:3
            I(k,j)=w*(phi(:,k+6).*phi(:,j+6));
        end
    end 
         display('Orthogonality test for phi_7, phi_8, phi_9')
         display(I);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us