Short Tutorial - Solving Fractional Differential Equations by Matlab Codes
Short Tutorial - Solving Fractional Differential Equations by Matlab Codes
1 Introduction
The Matlab code fde12.m and flmm.m are devised to numerically solve FDEs
and they are freely available on the file exchange service of Matlab central.
The code fde12.m implements the PredictorCorrector method proposed by
Diethelm and Freed in [1]. This methods is a combination of some product
integration rules, usually known as fractional AdamsBashforthmMoulton
methods and its stability properties were studied in [3]. The code is available
in the file exchange service of Matlab central at
1
http://www.mathworks.com/matlabcentral/fileexchange/32918
The code flmm.m implements some fractional linear multistep methods (FLMMs)
introduced by Lubich in [5] of the second order. In particular the code im-
plements three different implicit methods: a generalization of the classical
Trapezoidal rule (sometimes referenced as the Tustin method), a generaliza-
tion of the Newton-Gregory formula and the generalization of a Backward
Differentiation Formula (BDF). We refer to [2] for a description of the way in
which the methods are implemented and for a discussion of the various cases
in which one method is preferable to the other. Also this code is available
in the file exchange service of Matlab central at
http://www.mathworks.com/matlabcentral/fileexchange/47081
2
2.2 Use of the code flmm.m
The code flmm.m is used in a very similar way to fde12.m but there are two
main differences:
since flmm.m implements three different methods, the parameter METHOD
is used to specify the selected method;
The basic syntax for solving and FDE by the code flmm.m is therefore
> [T,Y] = FLMM2(ALPHA,FDEFUN,JFDEFUN,T0,TFINAL,Y0,h,PARAM,METHOD)
where JFDEFUN defines the Jacobian of the vector field FDEFUN and METHOD
the method selected for solving the FDE. The options for METHOD are: 1 for
the Trapezoidal method, 2 for the Newton-Gregory formula and 3 for the
BDF-2 (see [5, 2]). The parameter METHOD and is optional; when not defined
by default it is assumed METHOD=3.
We refer to help flmm2 for the meaning and the use of the other parameters.
3 Examples
We provide here an example of application of the codes presented in this
tutorial. In particular we consider, as test problem, the fractional version of
the Brusselator model problem
2
t0 Dt y1 (t) = a ( + 1)y1 (t) + (y1 (t)) y2 (t)
2
t0 Dt y2 (t) = y1 (t) (y1 (t)) y1 (t)
, 0<<1 (1)
y1 (t0 ) = y1,0
y2 (t0 ) = y2,0
We assume that we need to integrate this FDE for the order = 0.8 in the
interval [0, 100] with a stepsize h = 26 . Moreover, we assume that the
main parameters has the values a = 1 and = 4.
The vector field of the test problem is
! !
f1 (y(t)) a ( + 1)y1 (t) + (y1 (t))2 y2 (t)
f (t, y(t)) f (y(t)) = =
f2 (y(t)) y1 (t) (y1 (t))2 y1 (t)
3
and it is easy to evaluate that the Jacobian
y f1 (y(t)) y2
f1 (y(t))
Jf (t, y(t)) = 1
f2 (y(t)) f2 (y(t))
y1 y2
of this function is given by
!
( + 1) + 2y1 (t)y2 (t) (y1 (t))2
Jf (t, y(t)) Jf (y(t)) =
2y1 (t) (y1 (t))2
There are two main ways to describe the above vector field and the corre-
sponding Jacobian. With recent versions of Matlab it is possible to define
a = 1 ; mu = 4 ;
fdefun = @(t,y) [ a-(mu+1)*y(1)+y(1)^2*y(2) ; mu*y(1)-y(1)^2*y(2) ] ;
Jfdefun = @(t,y) [ -(mu+1)+2*y(1)*y(2) , y(1)^2 ; mu-2*y(1)*y(2) , -y(1)^2 ] ;
Note that the Jacobian Jfdefun is used only by the flmm2.m code; in the
case of fde12.m it is sufficient to define only fdefun.
For the other parameters (order, interval of integration, initial value and
stepsize) we use the assignments
alpha = 0.8 ;
t0 = 0 ; tfinal = 100 ; y0 = [ 0.2 ; 0.03] ;
h = 2^(-6) ;
It is hence possible to solve the test problem by means of the following calls
To plot the solution the following few Matlab commands can be used
figure(1)
plot(t,y_flmm2(1,:),t,y_flmm2(2,:)) ;
xlabel(t) ; ylabel(y(t)) ;
legend(y_1(t),y_2(t)) ;
title(FDE solved by the FLMM2.m code) ;
4
FDE solved by the FLMM2.m code FDE solved by the FLMM2.m code
7 7
y1(t)
y2(t) 6
6
5 5
4 4
y(t)
y2
3 3
2 2
1 1
0 0
0 20 40 60 80 100 0 1 2 3 4 5 6
t y1
Figure 1: Solution of the Brusselator test problem in the plane (t, y) and in
the phase plane.
and similarly for plotting the results from the fde12.m code. The results
are shown in Figure 1.
An alternative approach (usually necessary in old versions of Matlab) to
define the vector field is by means of external functions of this kind
function y = f_Bruss(t,x,param)
a = param(1) ; mu = param(2) ;
y(1,1) = a -(mu+1)*x(1)+x(1)^2*x(2) ;
y(2,1) = mu*x(1)-x(1)^2*x(2) ;
which must be saved in a file named as f Bruss.m. similarly, for the corre-
sponding Jacobian matrix we define the external function
function J = Jf_Bruss(t,x,param)
a = param(1) ; mu = param(2) ;
J(1,1) = -(mu+1)+2*x(1)*x(2) ;
J(1,2) = x(1)^2 ;
J(2,1) = mu-2*x(1)*x(2) ;
J(2,2) = -x(1)^2 ;
5
a = 1 ; mu = 4 ;
param = [a , mu] ;
[t, y_flmm2] = flmm2(alpha,f_Bruss,Jf_Bruss,t0,tfinal,y0,h,param) ;
[t, y_fde12] = fde12(alpha,f_Bruss,t0,tfinal,y0,h,param) ;
References
[1] Kai Diethelm and Alan D. Freed. The FracPECE subroutine for the nu-
merical solution of differential equations of fractional order. In S.Heinzel
and T.Plesser, editors, Forschung und wissenschaftliches Rechnen 1998,
pages 5771. 1999.