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_succapprox_bica_bvp(n,dom,kind)
function [x,solnum]=ibvp_ode_succapprox_bica_bvp(n,dom,kind)
% Example: y'' = (y^2+abs(y)^3)y(x/2), x in [0,1] 
%          y(0)=1, y(1)=1/2,  
% From: A.M. Bica, M. Curila, S. Curila, Applied Mathematics and Computation 2011, in press
% Exact solution: solex = 1/(x+1);
% call: [x,solnum]=ibvp_ode_succapprox_bica_bvp(32,[0 1],2);
% 
tic;
A=zeros(n);b=zeros(n,1);y=zeros(n,1);
x=pd(n,dom,kind);D=deriv(n,dom);
myDElin;myINIT;cont=1;dy(cont)=1;
while dy(cont) > 1.e-14
    if cont>100, break, end; 
    cont=cont+1;myDEnonlin;
    sol=A\b;dy(cont)=norm(sol-y);y=sol;% the solution in spectral form
end
toc;
solnum = t2x(sol,kind);% the solution in physical form
myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDElin
    % describes the linear part of the differential equation
    % describes the type of the initial/boundary conditions
    A=D^2;
    T=cpv(n,dom,dom);A(n-1,:)=T(1,:);A(n,:)=T(2,:);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myINIT
    % describes the initial approximation in spectral form
    y=x2t(1-x/2,kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDEnonlin
    % describes the nonlinear part of the differential equation
    % describes the boundary conditions
    yvm=cpv(n,x/2,dom)*y;yv=t2x(y,kind);
    work=(yv.^2+abs(yv).^3).*yvm;b=x2t(work,kind);
    %yv=t2x(y,kind);work=-x.*yv.^5;b=x2t(work,kind);
    b(n-1)=1;b(n)=1/2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    % describes the output of the code
    solex=1./(x+1);
    figure(1);
    subplot(2,1,1);semilogy(abs(sol),'.');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 numerical solution');
    figure(2);
    subplot(2,1,1);semilogy(1:cont,dy,'.');grid;
    title('History of iterations - corrections');
    subplot(2,1,2);semilogy(x,abs(solnum-solex));grid;
    xlabel('x');ylabel('err');title('The error');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end


Contact us