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.

[x,solnum]=ibvp_ode_newton_ex1(n,dom,kind,M)
function [x,solnum]=ibvp_ode_newton_ex1(n,dom,kind,M)
% Example: y'-exp(-2.75*x*y)=0,y(-1)=0;
% Test: y(1)=5.078183023880...
% call: [x,solnum]=ibvp_ode_newton_ex1(196,[-1 1],2,4);
%
tic;solnum=zeros(n,1);x=pd(n,dom,kind);X=mult(n,dom);D=deriv(n,dom);
yv=zeros(n,1);myINIT;y=x2t(yv,kind);% starting approximation in spectral space
dy=1;cont=1;
while dy(cont) > 1.e-13
    if cont>100, break, end; 
    cont=cont+1;myDElin;myDEnonlin;cor=A\b;% this is the correction
    dy(cont)=norm(cor);y=cor+y;yv=t2x(y,kind);
end;toc;solnum = yv;myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myINIT
    yv=zeros(n,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDElin
    dr=df(x,yv);DF=fact(x2t(dr,kind),M);A=D-DF;T=cpv(n,-1,dom);A(n,:)=T;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDEnonlin
    r=f(x,yv);b=-D*y+x2t(r,kind);b(n)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function rez=f(x,yv)
    rez=exp(-2.75*x.*yv); 
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function drez=df(x,yv)
    drez=-2.75*x.*exp(-2.75*x.*yv);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    figure(1);yex=5.078183023880;
    subplot(2,1,1);semilogy(abs(y),'.');grid;
    title('Absolute value of the coefficients of the solution');
    subplot(2,1,2);plot(x,solnum);grid;xlabel('x');ylabel('y(x)');
    title('The solution');
    figure(2);
    semilogy(1:cont,dy,'.');grid;
    title('History of iterations - corrections');
    solnum(end),yex,
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us