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.

Ex5( n)
function [ x,sol ] = Ex5( n)
% Example 5
%
% u'=5./(1+exp(-8*(u-1)))-0.8u, u(0)=u(1)
%
% call: [ x,sol ] = Ex5( 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');axis([0 1 6 7]);
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');axis([0 1 0.5 1]);
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');axis([0 1 0.001 0.003]);
T(1,:)*U,T(2,:)*U

a=0.8;
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)))-0.8*u;
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+0.8*eye(n);A(n,:)=T(1,:)-T(2,:);f(n)=0;
F=A*U-f;
end
end