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_test(n,dom,kind)
function [x,solnum]=ibvp_ode_int_test(n,dom,kind)
% Example: y''+ 5y'+10000y=-500cos(100x)exp(-5x), x in [0,1]
%          y(0)=0, y(1)=sin(100)exp(-5), 
% From L. Greengard, SIAM J. NUMER. ANAL. 28(4) 1991, pp. 1071-1080. 
% Exact solution: solex=sin(100x)exp(-5x)
% call: [x,solnum]=ibvp_ode_int_test(128,[0 1],2);
% 
tic;
A=zeros(n);b=zeros(n,1);
x=pd(n,dom,kind);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
    % describes the differential equation
    A=speye(n)+5*J+10000*J^2;
    f=-500*cos(100*x).*exp(-5*x);b=J^2*x2t(f,kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    % describes the initial/boundary conditions
    T=cpv(n,dom,dom);% T(1,:) for xc=0, T(2,:) for xc=1
    A(1,:)=T(1,:);b(1)=0;% y(0)=0
    A(2,:)=T(2,:);b(2)=sin(100)*exp(-5);% y(1)=sin(100)*exp(-5)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    % describes the output of the code
    solex=sin(100*x).*exp(-5*x);
    figure(1)
    subplot(2,1,1);semilogy(abs(sol),'.');grid;
    title('The absolute value of the coefficients of the solution');
    subplot(2,1,2);plot(x,solnum);grid;xlabel('x');ylabel('y(x)');
    title(['The solution (err = ',num2str(norm(solnum-solex)),')']);
    figure(2);semilogy(x,abs(solnum-solex));title('The errors');grid;
    xlabel('x');ylabel('err');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us