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_sys_ex3_int(n,dom,kind,y0)
```function [x,solnum]=ibvp_sys_ex3_int(n,dom,kind,y0)
% Example: y1'-y2=0;y2'-y3=0;x^2 y3'-2x y1+(x^2-3)y2-xy3=0, x in [0,2]
%          y1(2)=0, y2(2)=4, y3(2)=2
% Exact solution: y1ex=x^2-4,
% call: [x,solnum]=ibvp_sys_ex3_int(128,[0,2],2,[0,4,2]);
%
tic;m=length(y0);A=spalloc(m*n,m*n,5*m*n);b=zeros(m*n,1);
x=pd(n,dom,kind);X=mult(n,dom);J=prim(n,dom);
myDE;myBC;sol=reshape(A\b,n,m);% the solution in spectral space
solnum = t2x(sol,kind);% the solution in physical space
toc;myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
b=zeros(m*n,1);
A=[speye(n),-J,zeros(n);zeros(n),speye(n),-J;...
-2*J*X,J*(X^2-3*speye(n)),X^2-3*J*X];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
T=cpv(n,dom(2),dom);
for k=1:m
A((k-1)*n+1,:)=0;A((k-1)*n+1,(k-1)*n+1:k*n)=T;
b((k-1)*n+1)=y0(k);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
y1ex=x.^2-4;err=norm(solnum(:,1)-y1ex);
subplot(2,1,1);semilogy(abs(sol),'.');
title('Absolute value of the coefficients of y_1, y_2, y_3');grid;
subplot(2,1,2);plot(x,solnum(:,1));xlabel('x');ylabel('y_1(x)');grid;
title(['Numerical solution (error =',num2str(err),')']);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end```