Page 1

0

Fractional Derivatives, Fractional

Integrals, and Fractional Differential

Equations in Matlab

Ivo Petráš

Technical University of Košice

Slovak Republic

1. Introduction

The term fractional calculus is more than 300 years old. It is a generalization of the ordinary

differentiation and integration to non-integer (arbitrary) order. The subject is as old as the

calculus of differentiation and goes back to times when Leibniz, Gauss, and Newton invented

this kind of calculation. In a letter to L’Hospital in 1695 Leibniz raised the following question

(Miller and Ross, 1993): “Can the meaning of derivatives with integer order be generalized to

derivatives with non-integer orders?" The story goes that L’Hospital was somewhat curious

about that question and replied by another question to Leibniz. “What if the order will

be 1/2?" Leibniz in a letter dated September 30, 1695 replied: “It will lead to a paradox,

from which one day useful consequences will be drawn." The question raised by Leibniz for

a fractional derivative was an ongoing topic in the last 300 years. Several mathematicians

contributed to this subject over the years. People like Liouville, Riemann, and Weyl made

major contributions to the theory of fractional calculus. The story of the fractional calculus

continued with contributions from Fourier, Abel, Leibniz, Grünwald, and Letnikov.

Nowadays, the fractional calculus attracts many scientists and engineers. There are several

applications of this mathematical phenomenon in mechanics, physics, chemistry, control

theory and so on (Caponetto et al., 2010; Magin, 2006; Monje et al., 2010; Oldham and Spanier,

1974; Oustaloup, 1995; Podlubny, 1999). It is natural that many authors tried to solve the

fractional derivatives, fractional integrals and fractional differential equations in Matlab.

A few very good and interesting Matlab functions were already submitted to the MathWorks,

Inc. Matlab Central File Exchange, where they are freely downloadable for sharing among

the users. In this chapter we will use some of them. It is worth mentioning some addition to

Matlab toolboxes, which are appropriate for the solution of fractional calculus problems. One

of them is a toolbox created by CRONE team (CRONE, 2010) and another one is the Fractional

State–Space Toolkit developed by Dominik Sierociuk (Sierociuk, 2005). Last but not least we

should also mention a Matlab toolbox created by Dingyü Xue (Xue, 2010), which is based on

Matlab object for fractional-order transfer function and some manipulation with this class of

the transfer function. Despite that the mentioned toolboxes are mainly for control systems,

they can be “abused" for solutions of general problems related to fractional calculus as well.

10

Page 2

2Will-be-set-by-IN-TECH

2. Fractional calculus fundamentals

2.1 Special functions

Here we should mention the most important function used in fractional calculus - Euler’s

gamma function, which is defined as

?∞

This function is a generalization of the factorial in the following form:

Γ(n) =

0

tn−1e−tdt.(1)

Γ(n) = (n − 1)! (2)

This gamma function is directly implemented in the Matlab with syntax []=gamma().

Another function, which plays a very important role in the fractional calculus, was in fact

introduced in 1953. It is a two-parameter function of the Mittag-Leffler type defined as

(Podlubny, 1999):

∞

∑

k=0

The Mittag-Leffler function (3) can be expressed in the integral representation as

Eα,β(z) =

zk

Γ(αk + β),

(α > 0,

β > 0). (3)

Eα,β(z) =

1

2πi

?

C

tα−βet

tα− zdt,(4)

the contour C starts and ends at −∞ and circles around the singularities and branch points of

the integrand.

There are some relationships (given e.g. in (Djrbashian, 1993; Podlubny, 1999)):

E1,1(z) = ez,

E1/2,1(√z) =

2

√πe−zerfc(−√z),

E2,1(z) = cosh(√z),

E2,1(−z2) = cos(z),

E1,2(z) =ez− 1

z

.

For β = 1 we obtain the Mittag-Leffler function in one parameter (Podlubny, 1999):

Eα,1(z) =

∞

∑

k=0

zk

Γ(αk + 1)≡ Eα(z). (5)

For the numerical evaluation of the Mittag-Leffler function (3) with the default accuracy set

to 10−6the Matlab routine [e]=mlf(alf,bet,c,fi), written by Podlubny and Kacenak

(2005) can be used. Another Matlab function f=gml_fun(a,b,c,x,eps0)for a generalized

Mittag-Leffler function was created by YangQuan Chen (Chen, 2008).

In Fig. 1(a) and Fig. 1(b) are plotted the well-known functions (ezand cos(z)) computed via

the Matlab routine []=mlf() created for the evaluation of the Mittag-Leffler function.

Another important function Ek(t,λ;μ,ν) of the Mittag-Leffler type was introduced by

(Podlubny, 1999). The function is defined by

Ek(t,λ;μ,ν) = tμk+ν−1E(k)

μ,ν(λtμ),

(k = 0,1,2,...), (6)

240

Engineering Education and Research Using MATLAB

Page 3

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab3

−2−10

z

12

0

2

4

6

8

E1,1(z)

(a) E1,1(z),where −2 < z < 2

0246

−1

−0.5

0

0.5

1

z

E2,1(−z2)

(b) E2,1(−z2), where 0 < z < 2π

Fig. 1. Mittag-Leffler function (3) for various parameters

where E(k)

μ,ν(z) is k-th derivative of the Mittag-Leffler function of two parameters given by

E(k)

μ,ν(z) =

∞

∑

i=0

(i + k)! zi

i! Γ(μi + μk + ν),

(k = 0,1,2,...). (7)

2.2 Fractional derivatives and integrals

Fractional calculus is a generalization of integration and differentiation to non-integer-order

fundamental operatoraDα

continuous integrodifferential operator is defined as

⎧

⎪

The three most frequently used definitions for the general fractional differintegral are: the

Grünwald-Letnikov (GL) definition, the Riemann-Liouville (RL) and the Caputo definition

(Miller and Ross, 1993; Oldham and Spanier, 1974; Podlubny, 1999). Other definitions are

connected with well-known names as for instance Weyl, Fourier, Cauchy, Abel, etc.

t, where a and t are the bounds of the operation and α ∈ R. The

aDα

t=

⎪

⎩

⎨

dα

dtα

1

?t

: α > 0,

: α = 0,

a(dτ)α: α < 0.

The GL definition is given as

aDα

tf(t) = lim

h→0h−α

[t−a

∑

j=0

h]

(−1)j

?α

j

?

f(t− jh), (8)

where [.] means the integer part. The RL definition is given as

aDα

tf(t) =

1

Γ(n − α)

dn

dtn

?t

a

f(τ)

(t − τ)α−n+1dτ, for

(n − 1 < α < n), (9)

241

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 4

4Will-be-set-by-IN-TECH

where Γ(.) is the gamma function. The Caputo definition of fractional derivatives can be

written as

aDα

tf(t) =

1

Γ(n − α)

?t

a

f(n)(τ)

(t − τ)α−n+1dτ,for

(n − 1 < α < n).(10)

In this chapter we will consider mainly the GL, the RL, and the Caputo definitions. This

consideration is based on the fact that, for a wide class of functions, the three best known

definitions - GL, RL, and Caputo - are equivalent under some conditions (Podlubny, 1999).

Asit wasalreadymentioned,under

Riemann-Liouville and the Caputo derivative are equivalent.

Riemann-Liouville fractional derivative asRL

then the relationship between them is:

the homogeneousinitialconditions

Let us denote the

the

aDα

tt(t) and the Caputo definition asC

aDα

tf(t),

RL

aDα

tt(t) =C

aDα

tf(t)+

n−1

∑

k=0

(t − a)k−α

Γ(k − α + 1)f(k)(a),

for f(k)(a) = 0 (k = 0,1,...,n − 1).

The initial conditions for the fractional-order differential equations with the Caputo

derivatives are in the same form as for the integer-order differential equations.

advantage because applied problems require definitions of fractional derivatives, where there

are clear interpretations of initial conditions, which contain f(a), f

In addition, for approximation purpose we consider the Laplace transform method of the

fractional differintegralaDα

RL and Caputo definitions, under the zero initial conditions is:

It is an

?(a), f

??(a), etc.

t. The Laplace transform of the join operator of order α for the GL,

L{0Dα

tf(t); s} = sαF(s). (11)

Laplace transform technique is considered as an efficient way in solving differential equations

with integer order and fractional order as well. For differential equations with fractional

order, the Laplace transform technique works effectively only for relatively simple equations,

because of the difficulties of calculating inversion of Laplace transforms. This problem was

solved by applying a numerical inverse Laplace transform algorithms in fractional calculus

(Sheng et al., 2011). Three numerical inverse Laplace transform algorithms in Matlab, named

invlap(), gavsteh(), and nilt(), were described there and tested.

The Laplace transforms for several known Mittag-Leffler type functions are summarized as

follows (Magin, 2006; Podlubny, 1999):

L{Eα(−λtα)} =

sα−1

sα+ λ,

sα−β

sα+ λ,

L{tα−1Eα,α(−λtα)} =

1

sα+ λ,

k!sα−β

(sα∓ λ)k+1.

(12)

L{tβ−1Eα,β(−λtα)} =

L{Ek(t,±λ;α, β)} =

2.3 Numerical methods for fractional calculus

There are many numerical methods appropriate for the fractional calculus computation. They

were describedinseveral worksand a goodsurveycan be found in (Vinagre et al., 2000; 2003).

In the above-mentioned papers are described the time domain and frequency methods in

242

Engineering Education and Research Using MATLAB

Page 5

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab5

the form of IIR and FIR approximations together with illustrative examples. Some of the

mentioned frequency methods in both forms of approximation have been realized as the

Matlab routinesinDuarteValerio’stoolboxcalledninteger(seedetail reviewin(Valério,2005)).

Also created in this toolbox was a Simulink block nid for fractional derivative and integral,

where the order of derivative/integral and method of its approximation can be selected.

2.3.1 Grünwald-Letnikov method

For numerical calculation of fractional-order derivatives we can use the relation (13) derived

from the GL definition (8). This approach is based on the fact that for a wide class of functions

the threedefinitions -GL (8), RL(9), and Caputo’s(10) -areequivalentif f(a) = 0. The relation

for the explicit numerical approximation of q-th derivative at the points kh, (k = 1,2,...) has

the following form (Dorˇ cák, 1994; Podlubny, 1999):

(k−Lm/h)Dq

tkf(t) ≈ h−q

k

∑

j=0

(−1)j

?q

j

?

f(tk−j) = h−q

k

∑

j=0

c(q)

j

f(tk−j), (13)

where Lmis the “memory length", tk= kh, h is the time step of calculation and c(q)

0,1,...,k) are binomial coefficients. For their calculation we can use for instance the following

expression (Dorˇ cák, 1994):

j

(j =

c(q)

0

= 1,

c(q)

j

=

?

1 −1 + q

j

?

c(q)

j−1. (14)

The binomial coefficients c(q)

Writing the factorial as a gamma function (2), it allows the binomial coefficient to be

generalized to non-integer arguments. We can write the relations:

?q

Obviously, for this simplification we pay a penalty in the form of some inaccuracy. If f(t) ≤

M, we can easily establish the following estimate for determining the memory length Lm,

providing the required accuracy ?:

j

(j = 0,1,...,k) can be also expressed by using a factorial.

(−1)j

j

?

= (−1)j

Γ(q+ 1)

Γ(j+ 1)Γ(q − j +1)=

Γ(j − q)

Γ(−q)Γ(j+ 1). (15)

Lm≥

?

M

?|Γ(1− q)|

?1/q

.(16)

The above-describednumericalmethodiscalledPowerSeriesExpansion(PSE)ofagenerating

function. It is important to note that PSE leads to approximation in the form of polynomials,

that is, the discretized fractional operator is in the form of FIR filter, which has only zeros

(Chen and Moore, 2002; Vinagre et al., 2003).

The resulting discrete transfer function, approximating fractional-order operators, can be

expressed in z-domain as follows:

0D±r

kTG(z) =Y(z)

F(z)=

?1

T

?±r

PSE

??

1 − z−1?±r?

n

≈ T∓rRn(z−1), (17)

243

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 6

6Will-be-set-by-IN-TECH

where T is the sample period, PSE{u} denotes the function resulting fromapplying the power

series expansion to the function u, Y(z) is the Z transform of the output sequence y(kT), F(z)

is the Z transform of the input sequence f(kT), n is the order of the approximation, and R is

polynomial of degree n, respectively, in the variable z−1, and k = 1,2,.... A Matlab routine

dfod2() of this method (17) can be downloaded (see (Petráš, 2003b)).

EXAMPLE 2.1. Letusconsiderthe fractional-orderderivative α ∈ [0,1] ofthe function y=sin(t)

for t ∈ [0,2π]. The following Matlab code using a function fderiv(), which was created by

Bayat (2007) and is based on relation (13), can be used:

clear all; close all;

h=0.01; t=0:h:2*pi;

y=sin(t);

order=0:0.1:1;

for i=1:length(order)

yd(i,:)=fderiv(order(i),y,h);

end

[X, Y]=meshgrid(t,order);

mesh(X,Y,yd)

xlabel(’t’); ylabel(’\alpha’); zlabel(’y’)

Fig. 2. Fractional derivatives of function y=sin(t)

In Fig. 2 is depicted the fractional derivative of the sine function for fractional order of

derivative 0 < α < 1 and 0 < t < 2π.

2.3.2 Continuous and discrete-time approximation techniques

Other approach can be realized by Continued Fraction Expansion (CFE) of the generating

function and then the approximated fractional operator is in the form of IIR filter, which has

poles and zeros.

Taking into account that our aim is to obtain equivalents to the fractional integrodifferential

operators in the Laplace domain, s±r, the result of such approximation for an irrational

244

Engineering Education and Research Using MATLAB

Page 7

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab7

function, G(s), can be expressed in the form (Vinagre et al., 2003):

G(s) ? a0(s) +

b1(s)

a1(s) +

b2(s)

a2(s)+

b3(s)

a3(s)+...

= a0(s) +

b1(s)

a1(s)+

b2(s)

a2(s)+

b3(s)

a3(s)+

...(18)

where ais and bis are rational functions of the variable s, or are constants. The application

of the method yields a rational function, which is an approximation of the irrational function

G(s).

In other words, for evaluation purposes, the rational approximations obtained by CFE

frequently converge much more rapidly than the PSE and have a wider domain of

convergence in the complex plane. On the other hand, the approximation by PSE and the

short memory principle is convenient for the dynamical properties consideration.

For interpolation purposes, rational functions are sometimes superior to polynomials. This

is, roughly speaking, due to their ability to model functions with poles. These techniques are

based on the approximations of an irrational function, G(s), by a rational function defined by

the quotient of two polynomials in the variable s in frequency s-domain:

G(s) ? Ri(i+1)...(i+m)=

Pμ(s)

Qν(s)=p0+ p1s + ... + pμsμ

q0+ q1s + ... + qνsν,

(m + 1 = μ + ν + 1)

(19)

passing through the points (si,G(si)), ..., (si+m, G(si+m)).

The resulting discrete transfer function, approximating fractional-order operators, can be

expressed as (Vinagre et al., 2003):

⎧

⎩

where T is the sample period, CFE{u} denotes the function resulting from applying the

continued fraction expansion to the function u, Y(z) is the Z transform of the output sequence

y(kT), F(z) is the Z transform of the input sequence f(kT), p and n are the orders of the

approximation, and P and Q are polynomials of degrees p and n, respectively, in the variable

z−1, and k = 1,2,....

In general, the discretization of fractional-order differentiator/integrator s±r(r ∈ R) can be

expressed by the generating function s ≈ ω(z−1). This generating function and its expansion

determine both the form of the approximation and the coefficients (Lubich, 1986).

In this section, for direct discretizing sr, (0 < r < 1), we will concentrate on the IIR form

of discretization where as a generating function we will adopt an Al-Alaoui idea on mixed

scheme of Euler and Tustin operators (Al-Alaoui, 1993; 1997), but we will use a different ratio

between both operators. The mentioned new operator, raised to power ±r, has the form

(Petráš, 2003a):

0D±r

kTG(z) =Y(z)

F(z)=

?2

T

?±r

CFE

⎨

?

1 − z−1

1 + z−1

?±r⎫

⎬

⎭

p,n

≈

?2

T

?±rPp(z−1)

Qn(z−1),(20)

(ω(z−1))±r=

?

1 + a

T

1 − z−1

1 + az−1

?±r

,(21)

245

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 8

8 Will-be-set-by-IN-TECH

where a is the ratio term and r is the fractional order. The ratio term a is the amount of phase

shift and this tuning knob is sufficient for most engineering problems being solved.

In expanding the above in rational functions, we will use the CFE. It should be pointed

out that, for control applications, the obtained approximate discrete-time rational transfer

function should be stable. Furthermore, for a better fit to the continuous frequency response,

it would be of high interest to obtain discrete approximations with poles an zeros interlaced

along the line z ∈ (−1,1) of the z plane. The direct discretization approximations proposed in

this paper enjoy the desired properties.

The result of such approximation for an irrational function,?G(z−1), can be expressed by

G(z−1) ? a0(z−1) +

a1(z−1) +

G(z−1) in the CFE form (Vinagre et al., 2000):

b1(z−1)

b2(z−1)

a2(z−1)+

b3(z−1)

a3(z−1)+...

= a0(z−1) +

b1(z−1)

a1(z−1)+

b2(z−1)

a2(z−1)+

...

b3(z−1)

a3(z−1)+

...

where aiand biare either rational functions of the variable z−1or constants. The application

of the method yields a rational function, G(z−1), which is an approximation of the irrational

function? G(z−1).

expressed as:

⎧

⎩

=

T

The resulting discrete transfer function, approximating fractional-order operators, can be

(ω(z−1))±r≈

?1 + a

?1 + a

T

?±r

?±rPp(z−1)

CFE

⎨

?

1 − z−1

1 + az−1

?±r⎫

?±rp0+ p1z−1+ ··· + pmz−p

⎬

⎭

p,q

Qq(z−1),=

?1 + a

T

q0+ q1z−1+ ··· + qnz−q,(22)

where CFE{u} denotes the continued fraction expansion of u; p and q are the orders of the

approximation and P and Q are polynomials of degrees p and q. Normally, we can set p =

q = n. A Matlab routine dfod1() for this described method (22) can be downloaded (see

(Petráš, 2003a)).

EXAMPLE 2.2.

derivative/integral). The value of approximation order n is truncated to n = 3 and weighting

factor a was chosen a = 1/3. Assume sampling period T = 0.001sec.

For r = 0.5 we have the following approximation of the fractional half-order derivative:

Here we present some results for fractional order r = ±0.5 (half-order

G(z−1) =985.9 − 1315z−1+ 328.6z−2+ 36.51z−3

27 − 18z−1− 3z−2+ z−3

A Matlab sequence for the the fractional half-order derivative approximation (23) follows:

(23)

sys=dfod1(3, 0.001, 1/3, 0.5)

bode(sys)

step(sys)

246

Engineering Education and Research Using MATLAB

Page 9

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab9

100

101

102

103

0

20

40

Frequency [Hz]

Magnitude [dB]

Bode plots

100

101

102

103

−50

0

50

Frequency [Hz]

Phase [deg]

s0.5: continuous analytical solution

s0.5: approximated discrete solution

(a) Bode plots

0 0.02 0.04

Time [sec]

0.060.08

0

20

40

60

80

100

Amplitude

Step response

s0.5: continuous analytical solution

s0.5: approximated discrete solution

(b) Unit step responses

Fig. 3. Characteristics of approximated fractional-order differentiator (23) obtained from (22)

for r = 0.5, n = 3, a = 1/3, and T = 0.001 sec

The Bode plots and unit step response of the digital fractional-orderdifferentiator (23) and the

analytical continuous solution of a fractional semi-derivative are depicted in Fig. 3. Poles and

zeros of the transfer function (23) lie in a unit circle.

For r = −0.5 we have the following approximation of the fractional half-order integral:

G(z−1) =0.739 − 0.493z−1− 0.0822z−2+ 0.0274z−3

27 − 36z−1+ 9z−2+ z−3

A Matlab sequence for the the fractional half-order integral approximation (24) is the

following:

(24)

sys=dfod1(3, 0.001, 1/3, -0.5)

bode(sys)

step(sys)

100

101

102

103

−40

−20

0

Frequency [Hz]

Magnitude [dB]

Bode plots

100

101

102

103

−50

0

50

Frequency [Hz]

Phase [deg]

s−0.5: continuous analytical solution

s−0.5: approximated discrete solution

(a) Bode plots

00.02 0.04

Time [sec]

0.060.08

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

Amplitude

Step response

s−0.5: continuous analytical solution

s−0.5: approximated discrete solution

(b) Unit step responses

Fig. 4. Characteristics of approximated fractional-order integrator (24) obtained from (22) for

r = −0.5, n = 3, a = 1/3, and T = 0.001 sec

247

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 10

10Will-be-set-by-IN-TECH

The Bode plots and unit step response of the digital fractional-order integrator (24) and the

analytical continuous solution of a fractional semi-derivative are depicted in Fig. 4. Poles and

zeros of the transfer function (24) lie in a unit circle.

For simulation purpose, here we also present the Oustaloup’s Recursive Approximation

algorithm (Oustaloup et al., 2000). The method is based on the approximation of a function of

the form:

H(s) = sr,

r ∈ R,

for the frequency range selected as (ωb,ωh) by a rational function:

r ∈ [−1;1]

(25)

? H(s) = Co

N

∏

k=−N

s + ω?

s + ωk

k

(26)

using the following set of synthesis formulas for zeros, poles and the gain:

ω?

k= ωb

?ωh

ωb

?k+N+0.5(1−r)

2N+1

,

ωk= ωb

?ωh

ωb

?k+N+0.5(1−r)

2N+1

,

Co=

?ωh

ωb

?−r

2

N

∏

k=−N

ωk

ω?

k

, (27)

where ωh,ωbare the high and low transitional frequencies.

algorithm in Matlab as a function ora_foc() is given in (Chen, 2003).

An implementation of this

EXAMPLE 2.3. Using the described Oustaloup’s-Recursive-Approximation (ORA) method

with:

ωb= 10−2,

the obtained approximation for fractional function H(s) = s−1

ωh= 102

(28)

2 nad for N = 3 is as follows:

? H(s) =0.03162s7+ 22.42s6+1940s5+2.292 × 104s4+ 3.755 × 104s3+ 8523s2+ 264.3s + 1

A Matlab sequence for the the fractional half order derivative approximation (29) follows:

s7+ 264.3s6+ 8523s5+ 3.755 × 104s4+ 2.292 × 104s3+ 1940s2+ 22.42s + 0.03162.

(29)

sys=ora_foc(-0.5,3,0.01,100)

bode(sys)

step(sys)

The Bode plots and the unit step response of the approximated half-order integrator (29)

obtained for the frequency range (28) and N = 3 are depicted in Fig. 5.

2.3.3 Podlubny’s matrix approach

This approach is based on the fact that operation of the fractional calculus can be expressed

by matrix (Podlubny et al., 2009). It follows from Podlubny (2000), that the left-sided

Riemann-Liouville or Caputo fractional derivative v(α)(t) = 0Dα

in all nodes of the equidistant discretization net t = jτ (j = 0,1,...,n) simultaneously with

the help of the upper triangular strip matrix B(α)

n

tv(t) can be approximated

as (Podlubny, 2000):

?

v(α)

n

v(α)

n−1... v(α)

1

v(α)

0

?T

= B(α)

n

?

vn vn−1 ... v1 v0

?T

, (30)

248

Engineering Education and Research Using MATLAB

Page 11

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab11

10−2

100

102

104

−50

0

50

Frequency [Hz]

Magnitude [dB]

Bode plots

10−2

100

102

104

−60

−40

−20

0

Frequency [Hz]

Phase [deg]

(a) Bode plots

0500 10001500

Time [sec]

2000 25003000 3500

0

5

10

15

20

25

30

35

Amplitude

Step response

(b) Unit step response

Fig. 5. Characteristics of approximated fractional-order integrator (29) obtained from (27) for

r = −0.5, frequency range (28) and N = 3

where

⎡

0

ω(α)

0

ω(α)

B(α)

n

=

1

τα

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎣

ω(α)

0

ω(α)

1

...... ω(α)

...

n−1ω(α)

...

ω(α)

...

...

ω(α)

0

0

n

ω(α)

1

n−1

...

...

ω(α)

1

ω(α)

0

00

0

ω(α)

1

...

0

0

···

0

0

···

···

0

?α

···

0

···

⎤

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎦

,(31)

ω(α)

j

= (−1)j

j

?

,

j = 0,1,...,n. (32)

Similarly,the right-sidedRiemann-LiouvilleorCaputo fractional derivative v(α)(t) =tDα

can be approximated in all nodes of the equidistant discretization net t = jτ (j = 0,1,...,n)

simultaneously with the help of the lower triangular strip matrix F(α)

bv(t)

n

(Podlubny, 2000):

?

v(α)

n

v(α)

n−1... v(α)

1

⎡

v(α)

0

?T

= F(α)

n

?

vn vn−1 ... v1 v0

?T, (33)

F(α)

n

=

1

τα

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎣

ω(α)

0

ω(α)

1

ω(α)

2

...

00

0

0

0

0

...

···

···

···

···

ω(α)

0

ω(α)

1

0

0

0

ω(α)

0

ω(α)

1

...

...

ω(α)

0

...

···

0

ω(α)

n−1

ω(α)

n

ω(α)

2

... ω(α)

ω(α)

1

ω(α)

n−1

2

ω(α)

0

⎤

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎦

.(34)

249

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 12

12 Will-be-set-by-IN-TECH

The symmetric Riesz derivative of order β can be approximated based on its definition as a

combination ofthe approximations(30)and (33)forthe leftand right-sidedRiemann-Liouville

derivatives, or using the centered fractional differences approximation of the symmetric

Riesz derivative suggested recently by Ortigueira (2006). The general formula is the same

(Podlubny et al., 2009):

?

v(β)

m

v(β)

m−1... v(β)

1

v(β)

0

?T

= R(β)

m

?

vm vm−1 ... v1 v0

?T

(35)

In the first case, the approximation for the left-sided Caputo derivative is taken one step

ahead, and the approximation for the right-sided Caputo derivative is taken one step back.

This leads to the matrix

R(β)

m =h−α

2

?

−1Um++1Um

?

(36)

In the second case (Ortigueira’s definition) we have the following symmetric matrix:

R(β)

m = h−β

⎡

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎣

ω(β)

0

ω(β)

1

ω(β)

2

...

ω(β)

1

ω(β)

0

ω(β)

1

...

...

ω(β)

2

ω(β)

1

ω(β)

0

...

ω(β)

3

ω(β)

2

ω(β)

1

...

···

··· ω(β)

··· ω(β)

···

ω(β)

0

ω(β)

1

ω(β)

m

m−1

m−2

···

ω(β)

1

ω(β)

0

ω(β)

m−1

ω(β)

m

ω(β)

2

... ω(β)

ω(β)

1

ω(β)

m−1

2

⎤

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎦

(37)

ω(β)

k

=

(−1)kΓ(β + 1) cos(βπ/2)

Γ(β/2− k + 1)Γ(β/2 + k + 1),

k = 0,1,...,m. (38)

Both these approximationsof symmetricRieszderivativesgive practically the same numerical

results and in the case of numerical solution of partial fractional differential equations lead to

a well-posed matrix of the resulting algebraic system.

Similarly, if in addition to fractional-order time derivative we also consider symmetric

fractional-order spatial derivatives, then we have to use all nodes at the considered time layer

from the leftmost to the rightmost spatial discretization node.

Let us consider the nodes (ih, jτ), j = 0,1,2,...,n, corresponding to all time layers at i-th

spatial discretization node. It has been shown in Podlubny (2000) that all values of α-th

order time derivative of u(x,t) at these nodes are approximated using the discrete analogue

of differentiation of arbitrary order (Podlubny et al., 2009):

?

u(α)

i,nu(α)

i,n−1... u(α)

i,2u(α)

i,1u(α)

i,0

?

= B(α)

n

?

ui,nui,n−1... ui,2ui,1ui,0

?T.(39)

In order to obtain a simultaneous approximation of α-th order time derivative of u(x,t) in all

nodes, we need to arrange all function values uijat the discretization nodes to the form of

250

Engineering Education and Research Using MATLAB

Page 13

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab13

a column vector (Podlubny et al., 2009):

unm=

⎡

⎢⎢⎢⎢⎢⎢⎢⎢

⎣

um,num−1,n ... u1,nu0,n

um,n−1um−1,n−1... u1,n−1u0,n−1

...

um,1um−1,1 ... u1,1u0,1

um,0um−1,0 ... u1,0u0,0

⎤

⎥⎥⎥⎥⎥⎥⎥⎥

⎦

T

In visual terms, we first take the nodes of n-th time layer, then the nodes of (n − 1)-th time

layer, and so forth, and put them in this order in a vertical column stack.

The matrix that transforms the vector Unmto the vector U(α)

of order α with respect to time variable can be obtained as a Kronecker product of the matrix

B(α)

the number of time steps), and the unit matrix Em (recall that m is the number of spatial

discretization nodes):

T(α)

n

Similarly, the matrix that transforms the vector U to the vector U(β)

derivative of order β with respectto spatial variable can be obtained as a Kroneckerproductof

the unit matrix En(recall that n is the number of spatial discretization nodes), and the matrix

R(β)

2006), (recall that m is the number of time steps):

t

of the partial fractional derivative

n , which corresponds to the fractional ordinary derivative of order α (recall that n is

mn= B(α)

⊗ Em. (40)

x

of the partial fractional

m, which corresponds to a symmetric Riesz ordinary derivative of order β (Ortigueira,

S(α)

mn= En⊗ R(β)

n .(41)

Having these approximations for partial fractional derivatives with respect to both variables,

we can immediately discretize the general form of the fractional diffusion equation by simply

replacing the derivatives with their discrete analogs. Namely, the equation (Podlubny et al.,

2009):

tu − χ∂βu

is discretized as

?

The initial and boundary conditions must be equal to zero.

auxiliary unknown function must be introduced, which satisfies the zero initial and boundary

conditions. In this way, the non-zero initial and boundary conditions moves to the right-hand

side of the equation for the new unknown function.

C

0Dα

∂|x|β= f(x,t)

(42)

B(α)

n

⊗ Em− χ En⊗ R(β)

m

?

unm= fnm.(43)

If it is not so, then an

3. Ordinary fractional differential equations

A general fractional-order system can be described by a fractional differential equation of the

form

anDαn

ty(t) + an−1Dαn−1

= bmDβm

t

y(t) + ... + a0Dα0

tu(t) + bm−1Dβm−1

ty(t) =

u(t) + ... + b0Dβ0

ttu(t), (44)

251

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 14

14Will-be-set-by-IN-TECH

where Dγ

fractional derivative (Podlubny, 1999). The correspondingtransfer function of incommensurate

real orders has the following form (Podlubny, 1999):

t

≡

0Dγ

t

denotes the Grünwald-Letnikov, the Riemann-Liouville or Caputo

G(s) =bmsβm+ ... + b1sβ1+ b0sβ0

ansαn+ ... + a1sα1+ a0sα0=Q(sβk)

P(sαk), (45)

where ak(k = 0,... n), bk(k = 0,... m) are constant, and αk(k = 0,... n), βk(k = 0,... m)

are arbitrary real or rational numbers and without loss of generality they can be arranged as

αn> αn−1> ... > α0, and βm> βm−1> ... > β0.

In the particular case of commensurate order systems, it holds that, αk= αk, βk= αk,(0 < α <

1),∀k ∈ Z, and the transfer function has the following form:

G(s) = K0∑M

∑N

k=0bk(sα)k

k=0ak(sα)k= K0Q(sα)

P(sα).(46)

With N > M, the function G(s) becomes a proper rational function in the complex variable sα

which can be expanded in partial fractions of the following form:

?

i=1

G(s) = K0

N

∑

Ai

sα+ λi

?

, (47)

where λi(i = 1,2,..., N) are the roots of the pseudo-polynomial P(sα) or the system poles

which are assumed to be simple without loss of generality. The analytical solution of the

system (47) can be expressed as

?

i=1

y(t) = L−1

K0

?

N

∑

Ai

sα+ λi

??

= K0

N

∑

i=1

AitαEα,α(−λitα), (48)

where Eμ,ν(z) is the Mittag-Leffler function defined as (3).

A fractional-order plant to be controlled can be described by a typical n-term linear

homogeneous fractional-order differential equation (FODE) in the time domain

anDαn

ty(t) + ··· + a1Dα1

ty(t) + a0Dα0

ty(t) = 0(49)

where ak(k = 0,1,··· ,n) are constant coefficients of the FODE; αk(k = 0,1,2,··· ,n) are real

numbers. Without loss of generality, assume that αn> αn−1> ... > α0≥ 0.

The analytical solution of the FODE (49) is given by general formula in the form (Podlubny,

1999):

y(t) =

1

an

∞

∑

m=0

(−1)m

m!

∑

k0+k1+...+kn−2=m

k0≥0;...,kn−2≥0

Em(t,−an−1

(m;k0,k1,... ,kn−2)

(50)

×

n−2

∏

i=0

?ai

an

?ki

an

;αn− αn−1,αn+

n−2

∑

j=0

(αn−1− αj)kj+ 1),

where (m;k0,k1,... ,kn−2) are the multinomial coefficients.

252

Engineering Education and Research Using MATLAB

Page 15

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab15

Consider a control function which acts on the FODE system (49) as follows:

anDαn

ty(t) +··· + a1Dα1

ty(t) + a0Dα0

ty(t) = u(t).(51)

By the Laplace transform, we can get a fractional transfer function:

G(s) =Y(s)

U(s)=

1

ansαn+ ··· + a1sα1+ a0sα0. (52)

The fractional-order linear time-invariant (LTI) system can also be represented by the

following state-space model:

0Dq

tx(t) = Ax(t) + Bu(t)

y(t) = Cx(t), (53)

where x ∈ Rn, u ∈ Rrand y ∈ Rpare the state, input and output vectors of the system

and A ∈ Rn×n, B ∈ Rn×r, C ∈ Rp×n, and q = [q1,q2,...,qn]Tare the fractional orders. If

q1= q2= ...qn ≡ α, system (53) is called a commensurate-order system, otherwise it is an

incommensurate-order system.

EXAMPLE 3.1. Let us consider a simple two-term fractional differential equation with zero

initial condition in general form:

aDα

ty(t) + by(t) = 1 (54)

Solution can be obtained by using the Laplace transform method. In the Laplace domain we

can express the solution as

Y(s) =

1/a

s(sα+ b/a)

(55)

and by using the useful relations (6) and (12), in the time domain we can write a general

solution

y(t) =1

aE0(t,−b

a;α,α + 1) ≡1

atαEα,α+1

?

−b

atα

?

. (56)

For obtaining the solution in Matlab we can use the following sequence of commands:

clear all; close all;

a=2; b=1; alpha=1.5;

t=0:0.001:20; % for time step 0.001 and computational time 20 sec

y=(1/a)*t.^(alpha).*mlf(alpha,alpha+1,((-b/a)*t.^(alpha)));

plot(t,y);

xlabel(’Time [sec]’);

ylabel(’y(t)’);

EXAMPLE 3.2. Let us consider a three-term fractional differential equation in the form

a2Dα2

ty(t) + a1Dα1

ty(t) + a0y(t) = u(t). (57)

253

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 16

16Will-be-set-by-IN-TECH

05101520

0

0.2

0.4

0.6

0.8

1

1.2

1.4

Time [sec]

y(t)

Fig. 6. Solution of the equation (55) for parameters: α = 1.5, a = 2, and b = 1, under zero

initial conditions, time step 0.001 and computation time 20 sec

Substituting (13) into the equation (57), one can write

a2

hα2

k

∑

j=0

q(α2)

j

y(tk− j) +a1

hα1

k

∑

j=0

q(α1)

j

y(tk− j)+ a0y(tk) = u(tk), (58)

where tk= kh (k = 1,2,..., N) and q(α)

After some rearrangement of the terms in relation (58) we can obtain the numerical solution

of the fractional differential equation (57) in the following form:

j

are binomial coefficients calculated according to (14).

y(tk) =

u(tk) −

a2

hα2∑k

j=1q(α2)

j

y(tk− j) −

a2

hα2+

a1

hα1∑k

j=1q(α1)

j

y(tk− j)

a1

hα1+ a0

, (59)

where k = 1,2,..., N for N = Tsim/h and where Tsimis the total time of the calculation. The

above approach is general and can be used for n-term fractional differential equation (44).

clear all; close all;

a2=0.8; a1=0.5; a0=1.0; alpha2=2.2; alpha1=0.9;

h=0.05; TSim=35;

n=round(TSim/h);

cp1=1; cp2=1; Y0=0; u=1.0;

for j=1:n

c1(j)=(1-(1+alpha1)/j)*cp1;

c2(j)=(1-(1+alpha2)/j)*cp2;

cp1=c1(j); cp2=c2(j);

end

Y(1)=Y0;

for i=2:n

Y(i)=(u - (a2)*h^(-alpha2)*memo(Y,c2,i)- ...

(a1)*h^(-alpha1)*memo(Y,c1,i))/(a2/(h^alpha2)+a1/(h^alpha1)+a0);

end

254

Engineering Education and Research Using MATLAB

Page 17

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab17

T=0:h:TSim;

plot(T,Y);

xlabel(’Time [sec]’); ylabel(’y(t)’);

function [yo] = memo(r, c, k)

%

temp = 0;

for j=1:k-1

temp = temp + c(j)*r(k-j);

end

yo = temp;

05 1015

Time [sec]

20253035

0

0.5

1

1.5

2

y(t)

Fig. 7. Solution of the equation (57) for parameters: a2= 0.8, a1= 0.5, a0= 1, α2= 2.2,

α1= 0.9 for u(t) = 1, under zero initial conditions, time step h = 0.05 and computation time

Tsim= 35 sec

EXAMPLE 3.3. Let us consider the following three-term fractional differential equations, also

called the Bagley-Torvik equation, in the form (Podlubny, 1999):

Ay

??(t) + BDα

ty(t) + Cy(t) = F(t), (60)

where F(t) = 8 for 0 ≤ t ≤ 1 and F(t) = 8 for t > 1, and with zero initial conditions

y(0) = y

In this case we will use a matrix approach and the following syntax of the Matlab functions

(Podlubny et al., 2008):

?(0) = 0.

clear all; close all;

alpha = 1.5; A = 1; B = 0.5; C = 1;

h=0.05;

TSim=40;

T=0:h:TSim;

N=TSim/h + 1;

M=zeros(N,N);

255

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 18

18 Will-be-set-by-IN-TECH

Dalpha = ban(alpha,N,h);

D2 = ban(2,N,h);

M=A*D2 + B*Dalpha + C*eye(size(Dalpha));

F=8*(T<=1)’;

M = eliminator(N,[1 2])*M*eliminator(N, [1 2])’;

F= eliminator(N,[1 2])*F;

Y=M\F;

Y0 = [0; 0; Y];

figure(1)

plot(T,Y0’)

xlabel(’Time [sec]’);

ylabel(’y(t)’);

0 10203040

−4

−2

0

2

4

6

Time [sec]

y(t)

Fig. 8. Solution of the equation (60) for parameters: A = 1, B = 0.5, C = 1, and α = 1.5 under

zero initial conditions, time step h = 0.05 and computation time 40 sec

EXAMPLE 3.4. The transfer function of the closed feedback control loop with the DC motor

(DCM) and the fractional-order controller designed for desired value of phase margin Φm=

45oand gain margin equal to infinity, has the following form (Petráš, 2009):

Gc(s) =Y(s)

W(s)=

Go(s)

1 + Go(s)=

GDCM(s)C(s)

1 + GDCM(s)C(s)=

0.05s + 1

0.05s2.5+ s1.5+ 0.05s + 1,

(61)

where Go(s) is the transfer function of the open control loop.

corresponds to the fractional differential equation:

Transfer function (61)

0.05D2.5

t y(t) + D1.5

t y(t) + 0.05y

?(t) + y(t) = 0.05w

?(t) + w(t)

(62)

The feedback control loop described above can be simulated in Matlab environment by using

the approximation technique described in previous section, namely Oustaloup’s recursive

approximation function ora_foc() for desired frequency range ωb= 10−2, ωh= 102, and

N = 6.

256

Engineering Education and Research Using MATLAB

Page 19

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab19

close all; clear all;

Gs_DCM=tf([0.08],[0.05 1 0]);

Cs=(0.625*ora_foc(0.5,6,0.01,100))+(12.5*ora_foc(-0.5,6,0.01,100));

Gs_close=(Gs_DCM*Cs)/(1+(Gs_DCM*Cs));

step(Gs_close,15);

Gs_open=(Gs_DCM*Cs);

figure; bode(Gs_open);

[Gm,Pm] = margin(Gs_open);

The results obtained via describedMatlab scripts are depicted in Fig.9. The continuous model

is shown with solid line. Phase margin is Φm≈ 44.9oand gain margin is infinity.

The discrete version of the continuous fractional-order transfer function can be obtained

by using the digital operator (21) and Matlab function for approximation of digital

fractional-order derivative/integral dfod1() for sampling time T = 1 sec, ratio a = 1/3,

and n = 5.

close all; clear all;

T=0.1; a=1/3;

z=tf(’z’,T,’variable’,’z^-1’)

Hz=((1+a)/T)*((1-z^-1)/(1+a*z^-1));

Gz_DCM=0.08/(Hz*(0.05*Hz+1));

Cz=0.625*dfod1(5,T,a,0.5)+12.5*dfod1(5,T,a,-0.5);

Gz_close=(Gz_DCM*Cz)/(1+(Gz_DCM*Cz));

step(Gz_close,15);

Gz_open=(Gz_DCM*Cz);

figure; bode(Gz_open);

[Gm,Pm] = margin(Gz_open);

The results obtained via described Matlab scripts are depicted in Fig. 9. The discrete model is

shown with dashed line. Phase margin is Φm≈ 45.1oand gain margin is infinity.

10−2

10−1

100

101

−200

0

200

400

Frequency [Hz]

Magnitude [dB]

Bode plots

10−2

10−1

100

101

−200

−100

0

100

Frequency [Hz]

Phase [deg]

continuous model

discrete model

(a) Bode plots

05 1015

0

0.2

0.4

0.6

0.8

1

1.2

1.4

Time [sec]

Amplitude

Step response

continuous model

discrete model

(b) Unit step responses

Fig. 9. Characteristics of fractional order transfer function (61)

257

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 20

20 Will-be-set-by-IN-TECH

4. Partial fractional differential equations

For the solution of partial differential equations with derivatives of any order (integer and

non-integer), with time and space fractional derivatives, we can use a matrix approach.

EXAMPLE 4.1. Let us consider the following one-dimensional fractional diffusion equation

with fractional derivatives with respect both to time and to the spatial variable:

C

0Dα

ty(x,t) − a2∂βy(x,t)

∂|x|β

= f(x,t)

(63)

with the initial condition y(x,0) = h(x) and the boundary conditions y(0,t) = y(L,t) =

K. Note that ∂βy(x,t)/∂|x|βis symmetric Riesz derivative. Let us consider the following

parameters: α = 1.2, β = 2.1, a2= 1, f(x,t) = 5, L = 2, Tsim= 3 sec and K = 0. The Matlab

code is (for more details see also (Podlubny et al., 2008; 2009)):

clear all; close all;

% set the input parameters:

alpha =1.2; beta=2.1; a2=1; f_x=5; L=2; TSim=3; K=0;

% set the calculation parameters:

m = 21; n =148; h = L/(m-1); tau = TSim/n;

% alpha-th order derivative with respect to time:

B1 = ban(alpha,n-1,tau)’;

% time derivative matrix:

TD = kron(B1, eye(m));

% beta-th order derivative with respect to x:

B2 = ransym(beta,m,h);

% spatial derivative matrix:

SD = kron(eye(n-1), B2);

% matrix corresponding to discretization in space and time:

SystemMatrix = TD - a2*SD;

S = eliminator (m, [1 m]);

SK = kron(eye(n-1), S);

SystemMatrix_without_columns_1_m = SystemMatrix * SK’;

% remove rows with ’1’ and ’m’ from SystemMatrix_without_columns_1_m

S = eliminator (m, [1 m]);

SK = kron(eye(n-1), S);

SystemMatrix_without_rows_columns_1_m = ...

SK * SystemMatrix_without_columns_1_m;

% initial conditions:

U0=zeros(1,m);

% right hand side:

F = f_x*ones(size(SystemMatrix_without_rows_columns_1_m,1),1);

% solution of the system:

258

Engineering Education and Research Using MATLAB

Page 21

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab21

Y = SystemMatrix_without_rows_columns_1_m\F;

% reshape solution array --

% values for k-th time step are in the k-th column of YS:

YS = reshape(Y,m-2,n-1);

YS = fliplr(YS);

% final solution (take into account the initial condition):

for k = 1:(n-1)

U (:,k) = (YS(:,k)+U0(2:(m-1))’);

end

% plot graph

[rows, columns] = size(U);

U = [ zeros(1, columns)+K; U;

U = [U0’ U];

[XX,YY]=meshgrid(tau*(0:n-1),h*(0:m-1));

mesh(XX,YY,U)

xlabel(’t’); ylabel(’x’); zlabel(’y(x,t)’);

title([’\alpha =’, num2str(alpha), ’,

zeros(1, columns)+K];

\beta = ’, num2str(beta)])

When we consider non-zero initial condition, e.g. in the form of auxiliary function y(x,0) =

h(x) = x(x − 1) and non-zero boundary conditions in the form of the constant K, where

y(0,t) = y(L,t) = K, we have to modify the following lines in above Matlab code:

K=2;

...

% initial conditions:

k = 1:m;

U0 = (k-1).*((m-1) - k + 1)*h^2 + K;

In Fig. 10(a) and Fig. 10(b) are depicted the solutions of the fractional partial differential

equation (63) for zero and non-zero initial and boundary conditions, respectively.

5. Nonlinear fractional differential equations

A general numerical solution of the nonlinear fractional differential equation in the form

aDq

ty(t) = f(y(t),t),

can be expressed by using the relations (13) and (14) as:

y(tk) = f (y(tk),tk)hq−

k

∑

j=v

c(q)

j

y(tk−j). (64)

For the memory term expressed by the sum, a “short memory" principle can be used. Then the

lower index of the sums in relations (64) will be v = 1 for k < (Lm/h) and v = k − (Lm/h) for

k > (Lm/h), or without using the “short memory" principle, we put v = 1 for all k.

259

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 22

22Will-be-set-by-IN-TECH

0

1

2

3

0

0.5

1

1.5

2

0

0.5

1

1.5

2

2.5

t

α =1.2, β = 2.1

x

y(t,x)

(a)

y(x,0) = 0 and y(0,t) = y(L,t) = 0

Forzero initialandboundary conditions:

0

1

2

3

0

0.5

1

1.5

2

0

1

2

3

4

5

6

t

α =1.2, β = 2.1

x

y(t,x)

(b) For non-zero initial and boundary conditions:

y(x,0) = x(x− 1) and y(0,t) = y(L,t) = 2

Fig. 10. Solution of the equation (63) for parameters: α = 1.2, β = 2.1, a = 1, and f(x,t)=5 for

L = 2 and Tsim= 3 sec

EXAMPLE 5.1.

the set of three nonlinear fractional differential equations, which are used for describing an

economical system. The fractional-order financial system is described as follows (Chen, 2008):

In this section, we will demonstrate the proposed numerical solution on

0Dq1

0Dq2

0Dq3

tx(t) = z(t) + (y(t) − a)x(t),

ty(t) = 1 − by(t) − x(t)2,

tz(t) = −x(t) − cz(t),

(65)

where the total order of the system is denoted by ¯ q = (q1,q2,q3), a is the saving amount, b is

the cost per investment, and c is the elasticity of demand of commercial market. The state

variables are: x(t) is the interest rate, y(t) is the investment demand, and z(t) is the price

index.

The numerical solution of the fractional-order financial system (65) has the following form

(Petráš, 2011):

x(tk) = (z(tk−1) − (y(tk−1) − a)x(tk−1))hq1−

k

∑

j=v

c(q1)

j

x(tk−j),

y(tk) =

?

1 − by(tk) − x2(tk)

?

hq2−

k

∑

j=v

c(q2)

j

y(tk−j),(66)

z(tk) = (−x(tk) − cz(tk−1))hq3−

k

∑

j=v

c(q3)

j

z(tk−j),

where Tsimis the simulation time, k = 1,2,3..., N, for N = [Tsim/h], and (x(0), y(0), z(0)) is

the start point (initial conditions). The binomial coefficients c(qi)

to relation (14).

j

, ∀i, are calculated according

260

Engineering Education and Research Using MATLAB

Page 23

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab23

Let us consider the following parameters of the system (65): a = 1.0, b = 0.1, c = 1.0, orders

q1= 1.1, q2= 0.9, q3= 0.8, computational time Tsim= 200 days, for time step h = 0.04166,

and initial conditions (x(0),y(0),z(0)) = (1,−1,1). We will use v = 1 in (66) for all k.

The Matlab code for the solution of system (65) follows:

close all; clear all;

[t, y]=FOFinanc([1 0.1 1],[1.1 0.9 0.8],200, [1 -1 1]);

plot3(y(:,1), y(:,2), y(:,3),’k’); % in 3D state space

xlabel(’x(t)’); ylabel(’y(t)’); zlabel(’z(t)’); grid;

figure; plot(y(:,1), y(:,2),’k’); % projection onto x-y plane

xlabel(’x(t)’); ylabel(’y(t)’);grid;

where routine FOFinanc() consists of the following code (Petráš, 2010):

function [T, Y]=FOFinanc(parameters, orders, TSim, Y0)

h=0.04166;

% number of calculated mesh points:

n=round(TSim/h);

%orders of derivatives, respectively:

q1=orders(1); q2=orders(2); q3=orders(3);

% constants of financial system:

a=parameters(1); b=parameters(2); c=parameters(3);

% binomial coefficients calculation:

cp1=1; cp2=1; cp3=1;

for j=1:n

c1(j)=(1-(1+q1)/j)*cp1;

c2(j)=(1-(1+q2)/j)*cp2;

c3(j)=(1-(1+q3)/j)*cp3;

cp1=c1(j); cp2=c2(j); cp3=c3(j);

end

% initial conditions setting:

x(1)=Y0(1); y(1)=Y0(2); z(1)=Y0(3);

% calculation of phase portraits /numerical solution/:

for i=2:n

x(i)=(z(i-1)+(y(i-1)-a)*x(i-1))*h^q1 - memo(x, c1, i);

y(i)=(1-b*y(i-1)-x(i)^2)*h^q2 - memo(y, c2, i);

z(i)=(-x(i)-c*z(i-1))*h^q3 - memo(z, c3, i);

end

for j=1:n

Y(j,1)=x(j);Y(j,2)=y(j);

end

T=0:h:TSim;

Y(j,3)=z(j);

Supporting function memo() was already introduced in previous section of this chapter.

In Fig. 11 are depicted the simulation results of the financial system (65) for the following

parameters: a = 1, b = 0.1, and c = 1.0, orders q1= 1.1, q2= 0.9, q3= 0.8, computational

time 200 days, and for time step h = 0.04166 (i.e. approximately one hour sampling).

261

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 24

24Will-be-set-by-IN-TECH

−5

0

5

−2

0

2

4

−2

−1

0

1

2

y(t)

x(t)

z(t)

(a) State trajectory in 3D state space

−3−2−10123

−1

0

1

2

3

4

x(t)

y(t)

(b) State trajectory projected onto x-y plane

Fig. 11. Simulation result of the fractional-order financial system (65) in state space for the

initial conditions (x(0),y(0),z(0)) = (1,−1,1)

6. Conclusion

In this chapter are presented the methods for calculation of the fractional derivative and

fractional integral together with methods for solution of the fractional differential equations

in Matlab.Those methods are based on the numerical approximation of the fractional

derivatives and integral in the continuos time, discrete time and frequency domains. For

each mentioned methods are presented illustrative examples with a Matlab code. Moreover,

all described problems can be solved also in Simulink environment but such approach was

omitted in this chapter. Obviously the described problems could be solved via other methods

and also by different Matlab functions but we shown the way how one can create its own

Fractional Calculus Toolbox for Matlab from functions, which are freely downloadable from the

MathWorks, Inc. Matlab Central File Exchange. It depends on the problem which should

be solved in Matlab. Except above-mentioned open source routines, there are very useful

and effective Matlab functions for solution and analysis of the fractional calculus problems,

which are described in (Monje et al., 2010). Especially helpful is the linear fractional-order

differential equations solver fode_sol() and also the set of functions already published in

paper (Chen et al., 2009).

It is worth mentioning that there are many additional useful functions at the Matlab

Central File Exchange web site, which are not used in this chapter.

variable-order, distributed-order, and random-order fractional equations, predictor corrector

numerical method, impulse and step responses invariant discretization of fractional-order

differentiators/integrators as well as various fractional-order digital filters.

For instance

7. References

Al-Alaoui, M. A. (1993). Novel digital integrator and differentiator, Electron. Lett., Vol. 29,

376–378.

Al-Alaoui, M. A. (1997). Filling the gap between the bilinear and the backward difference

transforms: An interactive design approach, Int. J. Elect. Eng. Edu., Vol. 34, 331–337.

Bayat, F. M. (2007). Fractional Differentiator, MathWorks, Inc. Matlab Central File Exchange,

URL: www.mathworks.com/matlabcentral/fileexchange/13858.

262

Engineering Education and Research Using MATLAB

Page 25

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab25

Caponetto, R.; Dongola, G.; Fortuna, L. and Petráš, I. (2010). Fractional Order Systems: Modeling

and Control Applications, World Scientific, Singapore.

Chen, Y. Q. and Moore, K. L. (2002). Discretization Schemes for Fractional-Order

Differentiators and Integrators, IEEE Trans. On Circuits and Systems - I: Fundamental

Theory and Applications,Vol. 49, No. 3, 363–367.

Chen, Y.Q.(2003).Oustaloup–Recursive–Approximation

Differentiators,MathWorks,Inc.

www.mathworks.com/matlabcentral/fileexchange/3802.

Chen, Y. Q. (2008). Generalized Mittag-Leffler Function, MathWorks, Inc. Matlab Central File

Exchange, URL: www.mathworks.com/matlabcentral/fileexchange/20849.

Chen, Y. Q.; Petráš, I. and Xue, D. (2009). Fractional order control - A tutorial, Proc. of the

American Control Conference, pp. 1397–1411, June 10-12, 2009, St. Louis, USA.

Chen, W. Ch. (2008). Nonlinear dynamic and chaos in a fractional-order financial system,

Chaos, Solitons and Fractals, Vol. 36, 1305–1314.

CRONE ResearchGroup. (2010). CRONE Toolbox, URL: www.ims-bordeaux.fr/CRONE/toolbox/.

Dorˇ cák, L’. (1994). Numerical Models for the Simulation of the Fractional-Order Control

Systems, UEF-04-94, The Academy of Sciences, Inst. of Experimental Physic, Košice,

Slovakia.

Djrbashian, M.M.(1993). HarmonicAnalysisandBoundaryValueproblemsintheComplexDomain,

Birkhäuser Verlag, Basel.

Lubich, Ch. (1986). Discretized fractional calculus, SIAM J. Math. Anal., Vol. 17, 704–719.

Magin, R. L. (2006). Fractional Calculus in Bioengineering, Begell House Publishers.

Miller, K. S. and Ross, B. (1993). An Introduction to the Fractional Calculus and Fractional

Differential Equations, John Wiley and Sons. Inc., New York.

Monje, C. A.; Chen, Y. Q.; Vinagre, B. M.; Xue, D. and Feliu, V. (2010). Fractional-order Systems

and Controls, Series: Advances in Industrial Control, Springer.

Oldham, K. B. and Spanier, J. (1974). The Fractional Calculus, Academic Press, New York.

Ortigueira, M. D. (2006). Riesz potential operators and inverses via fractional centered

derivatives, Int. J. Math. Math. Sci., Article ID 48391, 1–12.

Oustaloup, A. (1995). La Derivation Non Entiere: Theorie, Synthese et Applications, Hermes, Paris.

Oustaloup, A.; Levron, F.; Mathieu, B. and Nanot, F. M. (2000). Frequency-band complex

noninteger differentiator: characterization and synthesis, IEEE Trans. on Circuits and

Systems I: Fundamental Theory and Applications I, Vol. 47, 25–39.

Petráš, I. (2003a). Digital Fractional Order Differentiator/integrator – IIR type, MathWorks,

Inc.Matlab CentralFileExchange,

/fileexchange/3672.

Petráš, I. (2003b). Digital Fractional Order Differentiator/integrator – FIR type, MathWorks,

Inc.MatlabCentralFileExchange,

/fileexchange/3673.

Petráš, I. (2009). Fractional-Order Feedback Control of a DC Motor, Journal of Electrical

Engineering, Vol. 60, No. 3, 117–128.

Petráš, I. (2010). Fractional Order Chaotic Systems, MathWorks, Inc. Matlab Central File

Exchange, URL: www.mathworks.com/matlabcentral/fileexchange/27336.

Petráš, I. (2011). Fractional-Order Nonlinear Systems: Modeling, Analysis and Simulation Series:

Nonlinear Physical Science, Springer, HEP.

Podlubny, I. (1999). Fractional Differential Equations, Academic Press, San Diego.

for

File

Fractional

Exchange,

Order

URL:MatlabCentral

URL:

www.mathworks.com/matlabcentral

URL:

www.mathworks.com/matlabcentral

263

Fractional Derivatives, Fractional Integrals, and Fractional Differential Equations in Matlab

Page 26

26 Will-be-set-by-IN-TECH

Podlubny, I. (2000). Matrix approach to discrete fractional calculus, Fractional Calculus and

Applied Analysis, Vol. 3, 359–386.

Podlubny, I. and Kacenak, M. (2005). Mittag-Leffler Function, MathWorks, Inc. Matlab Central

File Exchange, URL: www.mathworks.com/matlabcentral/fileexchange/8738.

Podlubny, I.; Skovranek, T. and Vinagre, B. M. (2008). Matrix Approach to Discretization

of ODEs and PDEs of Arbitrary Real Order, MathWorks, Inc. Matlab Central File

Exchange, URL: www.mathworks.com/matlabcentral/fileexchange/22071.

Podlubny, I.; Chechkin. A.; Skovranek, T.; Chen, Y. Q. and Vinagre, B. M. J. (2009). Matrix

approach to discrete fractional calculus II: Partial fractional differential equations,

Journal of Computational Physics, Vol. 228, 3137–3153.

Valério, D. (2005). Toolbox Ninteger for MatLab, v. 2.3, MathWorks, Inc. Matlab Central File

Exchange, URL: www.mathworks.com/matlabcentral/fileexchange/8312.

Vinagre, B. M.; Podlubny, I.; Hernández, A. and Feliu, V. (2000). Some approximations of

fractional order operators used in control theory and applications, Fractional Calculus

and Applied Analysis, Vol. 3, 231–248.

Vinagre, B. M.; Chen, Y. Q. and Petráš, I. (2003). Two direct Tustin discretization methods for

fractional-order differentiator/integrator, J. Franklin Inst., Vol. 340, 349–362.

Sierociuk, D. (2005). Fractional Order Discrete State–Space System Simulink Toolkit User

Guide, www.ee.pw.edu.pl/˜dsieroci/fsst/fsst.htm.

Sheng, H.; Li, Y. and Chen, Y. Q. (2011). Application of numerical inverse Laplace transform

algorithms in fractional calculus, J. Franklin Inst., Vol. 348, 315–330.

Xue, D. (2010). Computational Aspect of Fractional-Order Control Problems, Tutorial

Workshop on Fractional Order Dynamic Systems and Controls, Proceedings

of the WCICA’2010,Jinan, China. (URL: mechatronics.ece.usu.edu/foc/cdc10tw

/code-matlab-simulink /xdy_foccode.rar).

264

Engineering Education and Research Using MATLAB