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.

Ex4( n)
```function [ x,sol ] = Ex4( n)
% Example 4
%
% u'=5./(1+exp(-8*(u-1)))-exp(t/2)u/2, u(0)=u(1)
%
% call: [ x,sol ] = Ex4( 64);
%
dom = [0,1];kind = 2;
[x,w] = pd(n,dom,kind);X=mult(n,dom);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(1+x.*(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');
T(1,:)*U,T(2,:)*U

fact=1;
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');
T(1,:)*U,T(2,:)*U

fact=0.1;
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');
T(1,:)*U,T(2,:)*U

A=sqrt(exp(1))/2;
for kont=0:250
R=0.1*kont;%R=0:0.01:25
u=R*exp(-A*x);
f=5./(1+exp(-8*(u-1)))-exp(x/2).*u/2;
integrand=exp(A*x).*f;
F(kont+1)=w*integrand-(exp(A)-1-A)*R;
G(kont+1)=w*integrand-(1-exp(-A)-A)*R;
end
subplot(2,2,4);plot(0:0.1:25,F,'k-',0:0.1:25,G,'k--');
grid;title('d');xlabel('u');ylabel('F,G');legend('F','G');

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