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_ode4_test(n,dom,kind,numeigval)
function [lam,phi,x]=eig_ode4_test(n,dom,kind,numeigval)
% Example: y^(4)=lambda y, x in [-1,1]
%          y(-1)=y'(-1)=y(1)=y'(1)=0
% From: B. Fornberg, SIAM J. Sci. Comp., 28(5), 2006, pp. 1716-1729
% Exact eigenvalues: rho=(16lambda)^(1/4), cos(rho)cosh(rho)-1=0
% call: [lam,phi,x]=eig_ode4_test(80,[-1 1],2,32);
%
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;
[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((eye(n)-X^2)^2*[VV(:,s);0;0;0;0],kind);
end
toc;myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    % describes the differential operator
    E=eye(n);
    A=D^4*(E-X^2)^2;B=(E-X^2)^2;
    A=A(1:n-4,1:n-4);B=B(1:n-4,1:n-4);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    rho=2*sqrt(sqrt(lam));%exact=cos(rho).*cosh(rho);
    exact=cos(rho).*(1+exp(-2*rho))/2-exp(-rho);
    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

Contact us