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.

[x,solnum]=ibvp_ode_int_ex2(n,dom,kind)
function [x,solnum]=ibvp_ode_int_ex2(n,dom,kind)
% Example: epy''+ (x^2-w^2)y=0, x in [-1,1]
%          y(-1)=1, y(1)=2, w=0.5, ep=1.e-6
% From: J.-Y. Lee, L. Greengard, 
%       SIAM J. SCI. COMPUT., 18, 2, pp.403-429, 1997
% call: [x,solnum]=ibvp_ode_int_ex2(1024,[-1 1],2);
%
tic;ep=1.e-6;w=0.5;
A=zeros(n);b=zeros(n,1);
x=pd(n,dom,kind);X=mult(n,dom);J=prim(n,dom);
myDE;myBC;sol=A\b;% the solution in spectral form
toc;
solnum = t2x(sol,kind);% the solution in physical form
myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    A=ep*speye(n)+J^2*(X^2-w^2*speye(n));
    f=zeros(n,1);b=J^2*x2t(f,kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    T=cpv(n,dom,dom);% T(1,:) for xc=-1, T(2,:) for xc=1
    A(1,:)=T(1,:);b(1)=1;
    A(2,:)=T(2,:);b(2)=2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    xx=linspace(-1,1,10000);fx = barycheb(xx,solnum,x,kind);
    figure(1)
    subplot(2,1,1);semilogy(abs(sol),'.');grid;
    title('Absolute value of the Chebyshev coefficients of the solution');
    subplot(2,1,2);plot(xx,fx);grid;xlabel('x');ylabel('y(x)');
    title('The solution');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us