Code covered by the BSD License

Chebpack

Damian Trif (view profile)

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

[x,solnum]=ibvp_ode_int_ex3(n,dom,kind)
```function [x,solnum]=ibvp_ode_int_ex3(n,dom,kind)
% Example: y'''-4y' = 3, y'(0)=0, y'(1)=0, y(1/2)=0
% From: G. B. Loghmani, M. Ahmadinia, Iranian Journal of Science & Technology,
%       Transaction A, 30, A3, 2006, pp. 291-295
% Exact solution: solex=-3/8*(2*x-1+(exp(2-2*x)-exp(2*x))/(exp(2)+1));
% call: [x,solnum]=ibvp_ode_int_ex3(32,[0 1],2);
%
tic;
A=zeros(n);b=zeros(n,1);
x=pd(n,dom,kind);J=prim(n,dom);D=deriv(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=speye(n)-4*J^2;
f=3*ones(n,1);b=J^3*x2t(f,kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
T=cpv(n,[0,0.5,1],dom);% T(1,:) for xc=0, T(2,:) for xc=1/2 and T(3,:) for xc=1
A(1,:)=T(1,:)*D;b(1)=0;
A(2,:)=T(2,:);b(2)=0;
A(3,:)=T(3,:)*D;b(3)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
solex=-3/8*(2*x-1+(exp(2-2*x)-exp(2*x))/(exp(2)+1));
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 (error = ',num2str(norm(solnum-solex)),')']);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end```