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,t,solnum]=pde_lin_test(n,dom, kind,dt,K)
```function [x,t,solnum]=pde_lin_test(n,dom, kind,dt,K)
% Example: u_t=u_xx + 20 u_x, x in [-4,2],t>0
%          u(x,0)=max(0,1-abs(x)), u(-4,t)=u(2,t)=0
% From: Chebfun, pde examples
% Remark: uses backward Euler method for time step
% call: [x,t,solnum]=pde_lin_test(128,[-4,2],2,0.01,40);
%
x=pd(n,dom,kind);D=deriv(n,dom);T=cpv(n,dom,dom);
myDE;A=speye(n)-dt*A;myINIT;uo=x2t(f,kind);solnum(:,1)=f;t(1)=0;
for k=1:K
myBC;un=A\uo;t(k+1)=k*dt;
uo=un;solnum(:,k+1)=t2x(uo,kind);
end
myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
% describes the linear spatial part of the pde
A=D^2+20*D;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
% describes the boundary conditions
A(end-1,:)=T(1,:);uo(end-1)=0;
A(end,:)=T(2,:);uo(end)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myINIT
% describes the initial condition in physical form
f=max(0,1-abs(x));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
% describes the output of the program
plot(x,f);axis([-4 2 0 1]);title('t= 0');grid;
xlabel('x');ylabel('u(x,t)');hold on;pause(0.5);
for j=2:K+1
if rem(j-1,5)==0,plot(x,solnum(:,j));
title(['t= ',num2str(t(j))]);pause(0.5);
end
end;hold off
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end```