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_ex1(n,dom,q)
```function [x,solnum]=deriv_frac_ex1(n,dom,q)
% Example:  D^q_*y(x)=x^2+2/GAMMA(3-q)x^(2-q)-y(x),y(0)=0, x in [0,1], q=0.5
% From M. Weilbeer, Dissertation, Technischen Universitat Braunschweig
% Exact solution: yex=x^2
% Remark: uses the physical form
% call: [x,solnum]=deriv_frac_ex1(32,[0,1],0.5);
%
tic;
[x,~,~,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=x.^2+2/gamma(3-q)*x.^(2-q);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
% the initial condition in physical form
A(1,:)=0;A(1,1)=1;b(1)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
solex=x.^2;
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);
subplot(2,1,2);semilogy(x(2:n),abs(solnum(2:n)-solex(2:n)));
title('The error');xlabel x; ylabel err
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end```