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.

Ex2( n)
function [ x,sol ] = Ex2( n)
% Example 2
%
% u'=5./(1+exp(-8*(u-1))), u(0)=int(u(s)ds,s=0..1)/2
%
% call: [ x,sol ] = Ex2( 64);
%

dom = [0,1];kind = 2;
[x,w] = pd(n,dom,kind);T = cpv(n,dom,dom);
D = deriv(n,dom);J=prim(n,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,w*sol/2

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,w*sol/2

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,w*sol/2

x=0:0.1:12;F=5./(1+exp(-8*(x-1)))/2-x;G=5./(1+exp(-8*(x-1)))*3/2-x;
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,:)-T(1,:))*J/2;f(n)=0;
        F=A*U-f;
    end
end

Contact us