Code covered by the BSD License

# Chebpack

### Damian Trif (view profile)

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

[x,solnum]=deriv_frac_ex2(n,dom,q)
```function [x,solnum]=deriv_frac_ex2(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 spectral form
% call: [x,solnum]=deriv_frac_ex2(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;
toc
myOUT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
% spectral form
A=DF+eye(n);b=T\ones(n,1);
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);% 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```