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_ex3(n,dom,kind)
function [x,solnum]=ibvp_ode_ex3(n,dom,kind)
% Example: -ep y'''+4 y'- y = 0.7-(x>0.5)*1.3, x in [0,1]
%          y(0)=1, y'(0)=0, y'(1)=0, ep=1/2^8
% From: T. Valanarasu, N. Ramanujam, Novi Sad J. Math., 37(2), 2007, 41-57.
% call: [x,solnum]=ibvp_ode_ex3(1024,[0 1],2);
% 
tic;ep=1/2^8;
A=zeros(n);b=zeros(n,1);
x=pd(n,dom,kind);X=mult(n,dom);D=deriv(n,dom);
myDE;bb=b;myBC;sol=A\b;% the solution in spectral form
toc;
solnum = t2x(sol,kind);% the solution in physical form
myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    f=0.7-(x>0.5)*1.3;% f=0.7 for x in [0,0.5], f=-0.6 for x in [0.5,1]
    A=-ep*D^3+4*D-speye(n);b=x2t(f,kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    T=cpv(n,dom,dom);% T(1,:) for xc=0, T(2,:) for xc=1
    A(n-2,:)=T(1,:);b(n-2)=1;
    A(n-1,:)=T(1,:)*D;b(n-1)=0;
    A(n,:)=T(2,:)*D;b(n)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    dsolnum=t2x(D*sol,kind);% the derivative of the solution
    figure(1);
    subplot(2,1,1);semilogy(abs(sol),'.');grid;
    title('The absolute value of the coefficients of the solution');
    subplot(2,1,2);semilogy(abs(bb),'.');grid;
    title('The absolute value of the coefficients of the rhs');
    figure(2);
    subplot(2,1,1);plot(x,solnum,'b');grid;
    title('The numerical solution');xlabel('x');ylabel('y(x)');
    subplot(2,1,2);plot(x,dsolnum,'b');grid;xlabel('x');ylabel('y''(x)');
    title('The derivative of the numerical solution');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us