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.

ibvp_ode_succapprox_ex1.m
function [x,solnum]=ibvp_ode_succapprox_ex1(n,dom,kind)
% Example: y''' = - (y+y^2)^(1/3), x in [0,1]
%          y(0)-y'(0)=0,y'(3/10)=0, y(1)=0
% From A. P. PALAMIDES, N. M. STAVRAKAKIS, EJDE, 2010(155),2010, pp. 112.
% call: [x,solnum]=ibvp_ode_succapprox_ex1(32,[0 1],2);
%
tic;
A=zeros(n);b=zeros(n,1);y=zeros(n,1);
x=pd(n,dom,kind);X=mult(n,dom);D=deriv(n,dom);
myDElin;myINIT;cont=1;dy(cont)=1;
while dy(cont) > 1.e-12
    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^3;T=cpv(n,[0,3/10,1],dom);
    A(n-2,:)=T(1,:)-T(1,:)*D;A(n-1,:)=T(2,:)*D;A(n,:)=T(3,:);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDEnonlin
    % describes the nonlinear part of the differential equation
    % describes the boundary conditions
    yv=t2x(y,kind);work=-nthroot((yv+yv.^2),3);
    b=x2t(work,kind);b(n-2)=0;b(n-1)=0;b(n)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myINIT
    % describes the initial approximation in spectral form
    y(1)=0.4;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    % describes the output of the code
    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);
    semilogy(1:cont,dy,'.');grid;title('History of iterations - corrections');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us