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_ex3(n,dom,q)
function [x,solnum]=deriv_frac_ex3(n,dom,q)
% Example:  D^q y(x)+y(x)=1, x in [0,5], 
%           y(0)=c0=1, y'(0)=c1=-1, 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)+c0 E_(q,1)(-x^q)+c1 x E_(q,2)(-x^q)
%                 E_(al,be) is the Mittag-Leffler function given by mlf.m
%                 (C) 2001-2009 Igor Podlubny, Martin Kacenak
% Remark: uses spectral form
% call: [x,solnum]=deriv_frac_ex3(256,[0,5],1.8);
tic;
[x,DF,T]=deriv_frac(n,dom,q);% the spectral derivative matrix DF
myDE;myBC;
sol=A\b;solnum=T*sol+c0+c1*x;
toc
myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    % spectral form
    c0=1;c1=-1;
    A=DF+eye(n);b=T\(ones(n,1)-c0-c1*x);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    % implementing the initial conditions in spectral form
    A(n-1,:)=T(1,:);b(n-1)=0;
    A(n,:)=T(1,:)*deriv(n,dom);b(n)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
xq=x.^q;solex=xq.*mlf(q,q+1,-xq)+c0*mlf(q,1,-xq)+c1*x.*mlf(q,2,-xq);
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