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( n)
```function [ x,sol ] = Ex1( n)
% Example 1
%
% u'=5./(1+exp(-8*(u-1))), u(0)=u(1)/2,
%
% call: [ x,sol ] = Ex1( 64);
%

dom = [0,1];kind = 2;
x = pd(n,dom,kind);
D = deriv(n,dom);
T = cpv(n,dom,dom);

options=optimset('Display','iter','TolFun',1.e-6,'MaxFunEvals',20000,...
'MaxIter',1000,'Algorithm','Levenberg-Marquardt');
Uinit=x2t(0.5*(1+x),kind);

fact=5;
U=fsolve(@sant,fact*Uinit,options);
sol(:,1)=t2x(U,kind);
subplot(2,2,1);plot(x,real(sol(:,1)),'k');grid;title('a');xlabel('t');ylabel('u');
sol(1,1),sol(end,1)/2

fact=2.4;
U=fsolve(@sant,fact*Uinit,options);
sol(:,1)=t2x(U,kind);
subplot(2,2,2);plot(x,real(sol(:,1)),'k');grid;title('b');xlabel('t');ylabel('v');
sol(1,1),sol(end,1)/2

fact=2;
U=fsolve(@sant,fact*Uinit,options);
sol(:,1)=t2x(U,kind);
subplot(2,2,3);plot(x,real(sol(:,1)),'k');grid;title('c');xlabel('t');ylabel('w');
sol(1,1),sol(end,1)/2

x=0:0.1:12;F=5./(1+exp(-8*(x-1)))-x;G=5./(1+exp(-8*(x-1)))-x/2;
subplot(2,2,4);plot(x,F,'k-',x,G,'k--');legend('F','G');grid;
title('d');xlabel('u');ylabel('F(u),G(u)');

function F=sant(U)
% U coefficients
u=t2x(U,kind);
f=x2t(5./(1+exp(-8*(u-1))),kind);
A=D;A(n,:)=T(1,:)-T(2,:)/2;f(n)=0;
F=A*U-f;
end
end```