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_ex1(n,dom,kind)
```function [x,solnum]=ibvp_ode_int_ex1(n,dom,kind)
% Example: sin(x)y'-cos(x)y=cos(2x), x in [0 2]
%          y(pi/2)=0;
% Exact solution: solex=pi*sin(x)-cos(x)-2*x.*sin(x)
% call: [x,solnum]=ibvp_ode_int_ex1(32,[0 2],2);
tic;
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
f=cos(2*x);P1=funm(full(X),@sin);P0=funm(full(X),@cos);
A=P1-2*J*P0;b=J*x2t(f,kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
T=cpv(n,pi/2,dom);
A(1,:)=T;b(1)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
solex=pi*sin(x)-cos(x)-2*x.*sin(x);
figure(1)
subplot(2,1,1);semilogy(abs(sol),'.');grid;
title('The absolute values 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(solex-solnum)),')']);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end```