Code covered by the BSD License  

Highlights from
Chebpack

image thumbnail

Chebpack

by

 

15 Jul 2011 (Updated )

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

[x,solnum]=pde_lin_matr_test(n,dom,kind,dt,K)
function [x,solnum]=pde_lin_matr_test(n,dom,kind,dt,K)
% Example: u_t=u_xx, x in [a,b],t>0
%          u(a,t)=alpha, u(b,t)=beta ,u(x,0)=uo, 
% Remark: uses matricial exponential method in physical form
% call: [x,solnum]=pde_lin_matr_test(64,[-4,2],2,0.1,100);
%
x=pd(n,dom,kind);D=deriv(n,dom);T=cpv(n,x,dom);alpha=[];beta=[];
myINIT;myDE;myBC;t(1)=0;solnum(:,1)=uo;
for k=1:K
    t(k+1)=k*dt;A=expm(t(k)*D2b);
    B=D2b\(A-eye(n-2));b=Dt(2:n-1,[1,n])*[alpha;beta];
    solnum(:,k+1)=[alpha;A*uo(2:n-1)+B*b;beta];
end
myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myINIT
    % describes the initial condition in physical form
    uo=max(0,1-abs(x));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    % describes the linear spatial part of the pde
    Dt=T*D^2/T;D2b=Dt(2:n-1,2:n-1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    % describes the boundary conditions
    alpha=1;beta=2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    % describes the output of the program
    p=plot(x,uo,'EraseMode','none');axis([-4.1 2.1 -0.1 2.1]);grid;
    title(['t= ',num2str(0)]);xlabel('x');ylabel('u(x,t)');hold on;pause(1)
    for j=2:K+1
        t(j)=(j-1)*dt;A=expm(t(j)*D2b);B=D2b\(A-eye(n-2));
        solnum(:,j)=[alpha;A*uo(2:n-1)+B*b;beta];
        set(p,'color','w');set(p,'Ydata',solnum(:,j),'color','b');
        title(['t= ',num2str(t(j))]);hold on;pause(0.1)
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us