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.

[xx,solnum]=ibvp_ode_split(n,dom,kind)
function [xx,solnum]=ibvp_ode_split(n,dom,kind)
% solves the initial/boundary value problems for a general linear ode using
% the integration matrix and splitting dom
% dom=[d1,d2,...,dm];
% x: the Chebyshev grid, solnum: the numerical solution
%
tic;
m=length(dom);
A=spalloc(n*(m-1),n*(m-1),100*n*(m-1));b=zeros(n*(m-1),1);xx=[];
xs=pd(n,[-1 1],kind);Js=prim(n,[-1,1]);Xs=mult(n,[-1 1]);Ds=deriv(n,[-1,1]);
for k=1:m-1
pdom=[dom(k),dom(k+1)];l=(pdom(2)-pdom(1))/2;med=(pdom(2)+pdom(1))/2;
x=l*xs+med;J=l*Js;X=l*Xs+med*speye(n);xx=[xx,x];
myDE;
E=zeros(m-1);E(k,k)=1;AA(1:2,:)=0;A=A+kron(E,AA);
EE=zeros(m-1,1);EE(k)=1;bb(1:2)=0;b=b+kron(EE,bb);
end;
myBC; sol=A\b;% the solution in spectral form
toc;solnum=[];
for i=1:m-1
solnum = [solnum,t2x(sol((i-1)*n+1:i*n),kind)];
end
% the solution in physical form
x=reshape(xx,(m-1)*n,1);solnumv=reshape(solnum,(m-1)*n,1);
myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
% describes the differential equation
% must be written by the user
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
% describes the initial/boundary conditions
% must be written by the user
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
% describes the output of the code
% must be written by the user
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end