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.

ex1.m
```% Example 1
% x'=1.2 x, t<>k
% x(k+)-x(k-)=-0.9 x(k-), k=1,2,...,K
% x(0+)=1
% From: X.J. Ran, M.Z. Liu, Q.Y. Zhu,
%       Numerical methods for impulsive differential equation,
%       Mathematical and Computer Modelling 48(2008), 4655
%
n=16;K=3;k=0;
dom=[0 1];kind=2;D=deriv(n,dom);T=cpv(n,dom(1),dom);x=pd(n,dom,kind);
A=D-1.2*eye(n);b=zeros(n,1);
A(n,:)=T;b(n)=1;solex=exp(1.2*x);solcoef=A\b;solnum=t2x(solcoef,kind);
plot(x,solex,'-b',x,solnum,'or');grid;hold on;
display(['[',num2str(k),' ',num2str(k+1),']  ',...
'error= ',num2str(norm(solnum-solex))]);
for k=1:K
dom=[k k+1];D=deriv(n,dom);T=cpv(n,dom(1),dom);x=pd(n,dom,kind);
A=D-1.2*eye(n);A(n,:)=T;b(n)=solnum(end)-0.9*solnum(end);
solex=10^(-k)*exp(1.2*x);solcoef=A\b;solnum=t2x(solcoef,kind);
plot(x,solex,'-b',x,solnum,'or');grid;pause(0.1);
grid;xlabel('t');ylabel('x(t)');
display(['[',num2str(k),' ',num2str(k+1),']  ',...
'error= ',num2str(norm(solnum-solex))]);
end
legend('exact','numeric');```

Contact us