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.

Ex5_delay.m
% use: Ex5_delay;
n=14;dom=[0 1];kind=2;
t=pd(n,dom,kind);tt=[t;t+1;t+2];
D=deriv(n,dom);I=eye(n);Z=zeros(n);T=cpv(n,dom,dom);
m=3;
a=m-0.5*exp(-m)-0.5*exp(m);b=0.5;c=0.5;
psi1=x2t(exp(m*(t-1)),kind);psi2=x2t(exp(m*(t+3)),kind);
A=[D-a*I -c*I Z; -b*I D-a*I -c*I;Z -b*I D-a*I];
B=zeros(3*n,1);B(1:n)=b*psi1;B(2*n+1:3*n)=c*psi2;
%
A(n,:)=0;A(n,1:n)=T(2,:);A(n,n+1:2*n)=-T(1,:);B(n)=0;
A(2*n,:)=0;A(2*n,n+1:2*n)=T(2,:);A(2*n,2*n+1:3*n)=-T(1,:);B(2*n)=0;
A(3*n,:)=0;A(3*n,1:n)=T(1,:);B(3*n)=T(2,:)*psi1;
%
Y=A\B;Ym=reshape(Y,n,3);
solnum=t2x(Ym,kind);solnum=reshape(solnum,3*n,1);
%
figure(1);plot(tt,solnum,'r.',tt,exp(m*tt),'b');grid;
xlabel('t');ylabel('y(t)');legend('numeric','analytic');
figure(2);semilogy(tt,abs(solnum-exp(m*tt))./solnum);grid;
xlabel('t');ylabel('abserr');
relerr=norm((solnum-exp(m*tt))./solnum)
abserr=norm((solnum-exp(m*tt)))

Contact us