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]=deriv_frac_ex2_phys(n,dom,q)
function [x,solnum]=deriv_frac_ex2_phys(n,dom,q)
% Example: D^q y(x)+y(x)=1, x in [0,5]
%          y(0)=0, y'(0)=0, q=1.8
% From I. Podlubny, Fractional Calculus & Applied Analysis, 3(4), 2000, 359-386
% Exact solution: yex=x^q E_(q,q+1)(-x^q)
%                 E_(al,be) is the Mittag-Leffler function given by mlf.m
%                 (C) 2001-2009 Igor Podlubny, Martin Kacenak
% Remark: uses physical form
% call: [x,solnum]=deriv_frac_ex2_phys(256,[0,5],1.8);
tic;
[x,~,T,DFphys]=deriv_frac(n,dom,q);% the physical derivative matrix DFphys
myDE;myBC;
solnum=A\b;
toc
myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    % physical form
    A=DFphys+eye(n);b=ones(n,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    % implementing the initial conditions in physical form
    A(1:2,:)=0;
    A(1,1)=1;b(1)=0;
    A(2,:)=T(1,:)*deriv(n,dom)/T;b(2)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
xq=x.^q;solex=xq.*mlf(q,q+1,-xq);% the solution
subplot(2,1,1);plot(x(2:n),solnum(2:n),'r',x(2:n),solex(2:n),'b');
legend('y','yex');title('The solution');xlabel x;ylabel y(x);grid;
subplot(2,1,2);semilogy(x(2:n),abs(solnum(2:n)-solex(2:n)));
title('The error');xlabel x; ylabel err;grid
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us