1 Introduction

Fractional differential equations have become a common description tool across a variety of applications (see, e.g., the classical references [23, 36] for an introduction). For this reason, their numerical solution has been the subject of many researches (see, e.g. [1, 24, 25, 34, 35, 37, 38]), with the development of corresponding software (see, e.g., [21, 27, 28]). In this context, the present contribution is addressed for solving initial value problems for fractional differential equations (FDE-IVPs) in the form

$$\begin{aligned} y^{(\alpha )}(t) = f(y(t)), \qquad t\in [0,T],\qquad y(0) = y_0\in \mathbb {R}^m, \end{aligned}$$
(1)

where, for the sake of brevity, we have omitted the argument t for f. Here, for  \(\alpha \in (0,1)\),  \(y^{(\alpha )}(t) \equiv D^\text{\AA }y(t)\)  is the Caputo fractional derivative:Footnote 1

$$\begin{aligned} D^\alpha g(t) = \frac{1}{\varGamma (1-\alpha )} \int _0^t (t-x)^{-\alpha } \left[ \frac{\textrm{d}}{\textrm{d}x}g(x)\right] \textrm{d}x, \end{aligned}$$
(2)

The Riemann-Liouville integral associated to (2) is given by:

$$\begin{aligned} I^\alpha g(t) = \frac{1}{\varGamma (\alpha )}\int _0^t (t-x)^{\alpha -1} g(x)\textrm{d}x. \end{aligned}$$
(3)

Consequently, the solution of (1) can be formally written as:

$$\begin{aligned} y(t) = y_0 + I^{\alpha } f(y(t)) \equiv y_0 + \frac{1}{\varGamma (\alpha )}\int _0^t (t-x)^{\alpha -1} f(y(x))\textrm{d}x, \qquad t\in [0,T]. \end{aligned}$$
(4)

The numerical method we shall consider, relies on Fractional HBVMs (FHBVMs), a class of methods recently introduced in [8], as an extension of Hamiltonian Boundary Value Methods (HBVMs), special low-rank Runge-Kutta methods originally devised for Hamiltonian problems (see, e.g., [10, 11]), and later extended along several directions (see, e.g., [2, 4, 6, 8, 9, 12]), including the numerical solution of FDEs. A main feature of HBVMs is the fact that they can gain spectrally accuracy, when approximating ODE-IVPs [3, 19, 20], and such a feature has been recently extended to the FDE case [8].

With this premise, the structure of the paper is as follows: in Section 2 we recall the main facts about the numerical solution of FDE-IVPs proposed in [8]; in Section 3 we provide full implementation details for the Matlab\(^{\copyright }\) code fhbvm used in the numerical tests; in Section 4 we report an extensive experimentation of the code, providing some comparisons with another existing one; at last, a few conclusions are given in Section 5.

2 Fractional HBVMs

To begin with, in order to obtain a piecewise approximation to the solution of the problem, we consider a partition of the integration interval in the form:

$$\begin{aligned} t_n = t_{n-1} + h_n, \qquad n=1,\dots ,N, \end{aligned}$$
(5)

where  \(h_n>0\),  \(n=1,\dots ,N\),  and such that

$$\begin{aligned} t_0=0, \qquad t_N= T\equiv \sum _{n=1}^N h_n. \end{aligned}$$
(6)

Further, by setting

$$\begin{aligned} y_n(ch_n) \,:=\, y(t_{n-1}+ch_n), \qquad c\in [0,1],\qquad n=1,\dots ,N, \end{aligned}$$
(7)

the restriction of the solution of (1) on the interval \([t_{n-1},t_n]\), and taking into account (4) and (56), one obtains, for \(t\equiv t_{n-1}+ch_{n}\), \(c\in [0,1]\),

$$\begin{aligned} y(t) ~\equiv ~y_n(ch_n)= & y_0 + \frac{1}{\varGamma (\alpha )}\int _0^{t_{n-1}+ch_n} (t_{n-1}+ch_n-x)^{\alpha -1} f(y(x))\textrm{d}x \nonumber \\= & ~y_0 + \frac{1}{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} \int _{t_{\nu -1}}^{t_\nu } (t_{n-1}+ch_n-x)^{\alpha -1}f(y(x))\textrm{d}x \nonumber \\ & \qquad + ~\frac{1}{\varGamma (\alpha )} \int _{t_{n-1}}^{t_{n-1}+ch_n} (t_{n-1}+ch_n-x)^{\alpha -1}f(y(x))\textrm{d}x \nonumber \\= & ~y_0 + \frac{1}{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} \int _0^{h_\nu } (t_{n-1}-t_{\nu -1}+ch_n-x)^{\alpha -1}f(y_\nu (x))\textrm{d}x \nonumber \\ & \qquad + ~\frac{1}{\varGamma (\alpha )} \int _0^{ch_n} (ch_n-x)^{\alpha -1}f(y_n(x))\textrm{d}x \nonumber \\= & ~y_0 + \frac{1}{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} h_\nu ^\alpha \int _0^1 \left( \frac{t_{n-1}-t_{\nu -1}}{h_\nu }+c\frac{h_n}{h_\nu }-\tau \right) ^{\alpha -1}f(y_\nu (\tau h_\nu ))\textrm{d}\tau \nonumber \\ & \qquad + ~\frac{h_n^\alpha }{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}f(y_n(\tau h_n))\textrm{d}\tau \nonumber \\= & ~y_0 + \frac{1}{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} h_\nu ^\alpha \int _0^1 \left( \sum _{i=\nu }^{n-1} \frac{h_i}{h_\nu }+c\frac{h_n}{h_\nu }-\tau \right) ^{\alpha -1}f(y_\nu (\tau h_\nu ))\textrm{d}\tau \nonumber \\ & \qquad + ~\frac{h_n^\alpha }{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}f(y_n(\tau h_n))\textrm{d}\tau , \qquad c\in [0,1]. \end{aligned}$$
(8)

To make manageable the handling of the ratios \(h_i/h_\nu \), \(i=\nu ,\dots ,n\), \(\nu =1,\dots ,n-1\), we shall hereafter consider the following choices for the mesh (56):

  • Graded mesh. In order to cope with possible singularities in the derivative of the vector field at the origin, we consider the graded mesh

    $$\begin{aligned} h_n = r h_{n-1} \equiv r^{n-1} h_1, \qquad n=1\dots ,N, \end{aligned}$$
    (9)

    where \(r>1\) and \(h_1>0\) satisfy, by virtue of (56),

    $$\begin{aligned} h_1\frac{r^N-1}{r-1} = T. \end{aligned}$$
    (10)

    As a result, one obtains that (8) becomes:

    $$\begin{aligned} y_n(ch_n)= & y_0~ + \nonumber \\ & \frac{h_1^\alpha }{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} r^{\alpha (\nu -1)} \int _0^1 \left( \frac{r^{n-\nu }-1}{r-1}+cr^{n-\nu }-\tau \right) ^{\alpha -1}f(y_\nu (\tau r^{\nu -1}h_1))\textrm{d}\tau \nonumber \\ & \qquad + ~\frac{h_1^\alpha r^{\alpha (n-1)}}{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}f(y_n(\tau r^{n-1}h_1))\textrm{d}\tau \nonumber \\=: & ~\phi _{n-1}^\alpha (c;h_1,r,y) \,+\, \frac{h_1^\alpha r^{\alpha (n-1)}}{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}f(y_n(\tau r^{n-1}h_1))\textrm{d}\tau , \nonumber \\ & \qquad \qquad c\in [0,1]. \end{aligned}$$
    (11)
  • Uniform mesh. This case is equivalent to allowing \(r=1\) in (9). Consequently, from (56) we derive

    $$\begin{aligned} h_n \equiv h_1 := \frac{T}{N}, \quad n=1,\dots ,N, \quad \Rightarrow \quad t_n = nh_1, \quad n=0,\dots ,N. \end{aligned}$$
    (12)

    As a result, (8) reads:

    $$\begin{aligned} y_n(ch_n)\equiv & y_n(ch_1) \nonumber \\= & y_0 + \frac{h_1^\alpha }{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} \int _0^1 \left( n-\nu +c-\tau \right) ^{\alpha -1}f(y_\nu (\tau h_1))\textrm{d}\tau \nonumber \\ & \qquad + ~\frac{h_1^\alpha }{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}f(y_n(\tau h_1))\textrm{d}\tau \nonumber \\\equiv & ~\phi _{n-1}^\alpha (c;h_1,1,y) \,+\, \frac{h_1^\alpha }{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}f(y_n(\tau h_1))\textrm{d}\tau , \nonumber \\ & \qquad \qquad c\in [0,1]. \end{aligned}$$
    (13)

Remark 1

As is clear, in order to obtain an accurate approximation of the solution, it is important to establish which kind of mesh (graded or uniform) is appropriate. Besides this, also a proper choice of the parameters \(h_1\), r, and N in (910) is crucial. Both aspects will be studied in Section 3.1.

2.1 Quasi-polynomial approximation

We now discuss a piecewise quasi-polynomial approximation to the solution of (1),

$$\sigma (t)\approx y(t), \qquad t\in [0,T],$$

such that

$$\begin{aligned} \sigma _n(ch_n) \,:=\, \sigma (t_{n-1}+ch_n), \qquad c\in [0,1],\qquad n=1,\dots ,N, \end{aligned}$$
(14)

is the approximation to \(y_n(ch_n)\), defined in (7). According to [8], such approximation will be derived through the following steps:

  1. 1.

    expansion of the vector field, in each sub-interval \([t_{n-1},t_n]\), \(n=1,\dots ,N\), (recall (56)) along a suitable orthonormal polynomial basis;

  2. 2.

    truncation of the infinite expansion, in order to obtain a local polynomial approximation.

Let us first consider the expansion of the vector field along the orthonormal polynomial basis, w.r.t. the weight function

$$\begin{aligned} \omega (x) = \alpha (1-x)^{\alpha -1}, \qquad s.t.\qquad \int _0^1 \omega (x)\,\textrm{d}x=1, \end{aligned}$$
(15)

resulting into a scaled and shifted family of Jacobi polynomials:Footnote 2

$$ P_j(x) := \sqrt{\frac{2j+\alpha }{\alpha }} \,\overline{P}_j^{\,(\alpha -1,0)}(2x-1), \qquad x\in [0,1], \qquad j=0,1,\dots , $$

such that

$$\begin{aligned} \int _0^1 \omega (x) P_i(x)P_j(x)\textrm{d}x = \delta _{ij}, \qquad i,j=0,1,\dots . \end{aligned}$$
(16)

In so doing, for \(n=1,\dots ,N\), one obtains:

$$\begin{aligned} f(y_n(ch_n)) = \sum _{j\ge 0} P_j(c)\gamma _j(y_n), \qquad c\in [0,1], \end{aligned}$$
(17)

with (see (15))

$$\begin{aligned} \gamma _j(y_n) = \int _0^1\omega (\tau ) P_j(\tau )f(y_n(\tau h_n))\textrm{d}\tau , \qquad j=0,1,\dots . \end{aligned}$$
(18)

Consequently, the FDE (1), can be rewritten as:

$$\begin{aligned} y_n^{(\alpha )}(ch_n) = \sum _{j\ge 0} P_j(c)\gamma _j(y_n), \quad c\in [0,1],\quad n=1,\dots ,N, \qquad y_1(0) = y_0. \end{aligned}$$
(19)

The approximation is derived by truncating the infinite series in (17) to a finite sum with s terms, thus replacing (19) with a series of local problems, whose vector field is a polynomial of degree s:

$$\begin{aligned} \sigma _n^{(\alpha )}(ch_n) = \sum _{j=0}^{s-1} P_j(c)\gamma _j(\sigma _n), \quad c\in [0,1],\quad n=1,\dots ,N, \qquad \sigma _1(0) = y_0, \end{aligned}$$
(20)

with \(\gamma _j(\sigma _n)\) defined similarly as in (18):

$$\begin{aligned} \gamma _j(\sigma _n) = \int _0^1\omega (\tau )P_j(\tau )f(\sigma _n(\tau h_n))\textrm{d}\tau , \qquad j=0,\dots ,s-1. \end{aligned}$$
(21)

As a consequence, (11) will be approximated as:

$$\begin{aligned} \sigma _n(ch_n)~= \nonumber \\ & y_0\,+\,\frac{h_1^\alpha }{\varGamma (\alpha )}\sum _{\nu =1}^{n-1} r^{\alpha (\nu -1)} \int _0^1 \left( \frac{r^{n-\nu }-1}{r-1}+cr^{n-\nu }-\tau \right) ^{\alpha -1}\,\sum _{j=0}^{s-1} P_j(\tau )\gamma _j(\sigma _\nu )\textrm{d}\tau \nonumber \\ & \qquad + ~\frac{h_1^\alpha r^{\alpha (n-1)}}{\varGamma (\alpha )} \int _0^c (c-\tau )^{\alpha -1}\sum _{j=0}^{s-1} P_j(\tau )\gamma _j(\sigma _n)\textrm{d}\tau ~=~y_0\,+ \nonumber \\ & \,h_1^\alpha \sum _{\nu =1}^{n-1} r^{\alpha (\nu -1)}\sum _{j=0}^{s-1}\left[ \frac{1}{\varGamma (\alpha )} \int _0^1 \left( \frac{r^{n-\nu }-1}{r-1}+cr^{n-\nu }-\tau \right) ^{\alpha -1} P_j(\tau )\textrm{d}\tau \right] \gamma _j(\sigma _\nu ) \nonumber \\ & \qquad + ~h_1^\alpha r^{\alpha (n-1)} \sum _{j=0}^{s-1}\left[ \frac{1}{\varGamma (\alpha )}\int _0^c (c-\tau )^{\alpha -1} P_j(\tau )\textrm{d}\tau \right] \gamma _j(\sigma _n) \nonumber \\ & =:~y_0\,+\,h_1^\alpha \sum _{\nu =1}^{n-1} r^{\alpha (\nu -1)}\sum _{j=0}^{s-1} J_j^\alpha \left( \frac{r^{n-\nu }-1}{r-1}+cr^{n-\nu }\right) \gamma _j(\sigma _\nu ) \nonumber \\ & \qquad +~h_1^\alpha r^{\alpha (n-1)} \sum _{j=0}^{s-1}I^\alpha P_j(c)\,\gamma _j(\sigma _n) \nonumber \\ & =:~\phi _{n-1}^{\alpha ,s}(c;h_1,r,\sigma ) ~+~ h_1^\alpha r^{\alpha (n-1)}\sum _{j=0}^{s-1} I^\alpha P_j(c)\,\gamma _j(\sigma _n), \qquad c\in [0,1], \end{aligned}$$
(22)

where (see (3))

$$\begin{aligned} I^\alpha P_j(c) = \frac{1}{\varGamma (\alpha )}\int _0^c (c-\tau )^{\alpha -1}P_j(\tau )\textrm{d}\tau ,\qquad j=0,\dots ,s-1, \end{aligned}$$
(23)

is the Riemann-Liouville integral of \(P_j(c)\), and, for \(x\ge 1\):

$$\begin{aligned} J_j^\alpha (x) = \frac{1}{\varGamma (\alpha )}\int _0^1 (x-\tau )^{\alpha -1}P_j(\tau )\textrm{d}\tau , \qquad j=0,\dots ,s-1. \end{aligned}$$
(24)

The efficient numerical evaluation of the integrals (23) and (24) will be explained in detail in Section 3.2.

Remark 2

We observe that, for \(c=x=1\), by virtue of (1516) one has:

$$\begin{aligned} I^\alpha P_j(1) = J_j^\alpha (1) = \frac{\delta _{j0}}{\varGamma (\alpha +1)}, \qquad j=0,\dots ,s-1. \end{aligned}$$
(25)

Similarly, when using a uniform mesh, by means of similar steps as above, (13) turns out to be approximated by:

$$\begin{aligned} \sigma _n(ch_n)~= \nonumber \\ & y_0\,+\,h_1^\alpha \sum _{\nu =1}^{n-1} \sum _{j=0}^{s-1} J_j^\alpha \left( n-\nu +c\right) \gamma _j(\sigma _\nu ) \,+\, h_1^\alpha \sum _{j=0}^{s-1}I^\alpha P_j(c)\,\gamma _j(\sigma _n) \nonumber \\\equiv & ~\phi _{n-1}^{\alpha ,s}(c;h_1,1,\sigma ) ~+~ h_1^\alpha \sum _{j=0}^{s-1} I^\alpha P_j(c)\,\gamma _j(\sigma _n), \qquad c\in [0,1].\qquad \end{aligned}$$
(26)

In both cases, the approximation at \(t_n\) is obtained, by setting \(c=1\) and taking into account (25), as:

$$\begin{aligned} \sigma _n(h_n)= & \phi _{n-1}^{\alpha ,s}(1;h_1,r,\sigma ) \,+\, \frac{h_1^\alpha r^{\alpha (n-1)}}{\varGamma (\alpha +1)}\gamma _0(\sigma _n) \nonumber \\\equiv & \phi _{n-1}^{\alpha ,s}(1;h_1,r,\sigma ) \,+\, \frac{h_n^\alpha }{\varGamma (\alpha +1)}\gamma _0(\sigma _n), \end{aligned}$$
(27)

which formally holds also in the case of a uniform mesh (see (12)) by setting \(r=1\).

2.2 The fully discrete method

Quoting Dahlquist and Björk [22], “as is well known, even many relatively simple integrals cannot be expressed in finite terms of elementary functions, and thus must be evaluated by numerical methods”. In our framework, this obvious statement means that, in order to obtain a numerical method, at step n the Fourier coefficients \(\gamma _j(\sigma _n)\) in (21) need to be approximated by means of a suitable quadrature formula. Fortunately enough, this can be done up to machine precision by using a Gauss-Jacobi formula of order 2k based at the zeros of \(P_k(c)\), \(c_1,\dots ,c_k\), with corresponding weights (see (15))

$$b_i = \int _0^1 \omega (c)\ell _i(c)\textrm{d}c, \qquad \ell _i(c) = \prod _{j\ne i}\frac{c-c_j}{c_i-c_j}, \qquad i=1,\dots ,k,$$

by choosing a value of k, \(k\ge s\), large enough. In other words,

$$\begin{aligned} \gamma _j^n \,:=\, \sum _{i=1}^k b_i P_j(c_i) f(\sigma _n(c_ih_n)) \,\doteq \, \gamma _j(\sigma _n), \qquad j=0,\dots ,s-1, \end{aligned}$$
(28)

where \(\,\doteq \,\) means equal within machine precision. Because of this, and for sake of brevity, we shall continue using \(\sigma _n\) to denote the fully discrete approximation (compare with (22), or with (26), in case \(r=1\)):Footnote 3

$$\begin{aligned} \sigma _n(ch_n) = \phi _{n-1}^{\alpha ,s}(c;h_1,r,\sigma ) + h_n^\alpha \sum _{j=0}^{s-1} I^\alpha P_j(c)\gamma _j^n, \qquad c\in [0,1]. \end{aligned}$$
(29)

As is clear, the coefficientes \(\gamma _j^\nu \), \(j=0,\dots ,s-1\), \(\nu =1,\dots ,n-1\), needed to evaluate \(\phi _{n-1}^{\alpha ,s}(c;h_1,r,\sigma )\), have been already computed at the previous time-steps.

We observe that, from (28), in order to compute the (discrete) Fourier coefficients, it is enough evaluating (29) only at the quadrature abscissae \(c_1,\dots ,c_k\). In so doing, by combining (28) and (29), one obtains a discrete problem in the form:

$$\begin{aligned} \gamma _j^n= & \sum _{i=1}^k b_i P_j(c_i) f\left( \phi _{n-1}^{\alpha ,s}(c_i;h_1,r,\sigma ) + h_n^\alpha \sum _{\ell =0}^{s-1} I^\alpha P_\ell (c_i)\gamma _\ell ^n\right) , \nonumber \\ & j~=~0,\dots ,s-1. \end{aligned}$$
(30)

Once it has been solved, according to (27), the approximation of \(y(t_n)\) is given by:

$$\begin{aligned} \bar{y}_n \,:=\, \sigma _n(h_n) \,=\,\phi _{n-1}^{\alpha ,s}(1;h_1,r,\sigma ) \,+\, \frac{h_n^\alpha }{\varGamma (\alpha +1)}\gamma _0^n. \end{aligned}$$
(31)

It is worth noticing that the discrete problem (30) can be cast in vector form, by introducing the (block) vectors

$$\gamma ^n = \left( \begin{array}{c} \gamma _0^n\\ \vdots \\ \gamma _{s-1}^n\end{array}\right) \in \mathbb {R}^{sm},\qquad \phi _{n-1}^{\alpha ,s} = \left( \begin{array}{c} \phi _{n-1}^{\alpha ,s}(c_1;h_1,r,\sigma )\\ \vdots \\ \phi _{n-1}^{\alpha ,s}(c_k;h_1,r,\sigma )\end{array}\right) \in \mathbb {R}^{km},$$

and the matrices

$$ \mathcal {P}_s = \left( \begin{array}{ccc} P_0(c_1) & \dots & P_{s-1}(c_1)\\ \vdots & & \vdots \\ P_0(c_k) & \dots & P_{s-1}(c_k)\end{array}\right) , \quad \mathcal {I}_{s}^{\alpha } = \left( \begin{array}{ccc} I^\alpha P_0(c_1)& \dots & I^\alpha P_{s-1}(c_1)\\ \vdots & & \vdots \\ I^\alpha P_0(c_k) & \dots & I^\alpha P_{s-1}(c_k)\end{array}\right) \quad \in \mathbb {R}^{k\times s},$$
$$\varOmega = \left( \begin{array}{ccc} b_1\\ & \ddots \\ & & b_k\end{array}\right) \in \mathbb {R}^{k\times k}, $$

as:

$$\begin{aligned} \gamma ^n = \mathcal {P}_s^\top \varOmega \otimes I_m f\left( \phi _{n-1}^{\alpha ,s} +h_n^\alpha \mathcal {I}_s^\alpha \otimes I_m\gamma ^n\right) , \end{aligned}$$
(32)

with the obvious notation for the function f, evaluated in a vector of (block) dimension k, of denoting the (block) vector of dimension k containing the function f evaluated in each (block) entry. As observed in [8], the (block) vector

$$\begin{aligned} Y \,:=\, \phi _{n-1}^{\alpha ,s} +h_n^\alpha \mathcal {I}_s^\alpha \otimes I_m\gamma ^n\in \mathbb {R}^{km}, \end{aligned}$$
(33)

appearing at the r.h.s. in (32) as argument of f, satisfies the equation

$$\begin{aligned} Y ~=~ \phi _{n-1}^{\alpha ,s} +h_n^\alpha \mathcal {I}_s^\alpha \mathcal {P}_s^\top \varOmega \otimes I_m\, f(Y), \end{aligned}$$
(34)

obtained combining (32) and (33). Consequently, it can be regarded as the stage vector of a Runge-Kutta type method with Butcher tableau

$$\begin{aligned} \begin{array}{c|c} {\varvec{c}}& \mathcal {I}^\alpha _s \mathcal {P}_s^\top \varOmega \\ \hline & {\varvec{b}}^\top \end{array}, \qquad {\varvec{b}}=\left( \begin{array}{ccc} b_1,&\dots ,&b_k\end{array}\right) ^\top , \qquad {\varvec{c}}=\left( \begin{array}{ccc} c_1,&\dots ,&c_k\end{array}\right) ^\top . \end{aligned}$$
(35)

Remark 3

Though the two formulations (32) and (34) are equivalent each other, nevertheless, the former has (block) dimension s independently of the considered value of k (\(k\ge s\)), which is the (block) dimension of the latter. Consequently, in the practical implementation of the method, the discrete problem (32) is the one to be preferred, since it is independent of the number of stages.

When \(\alpha =1\), the Runge-Kutta method (35) reduces to a HBVM(ks) method [3, 5, 9,10,11,12, 19, 20]. Consequently, we give the following definition [8].

Definition 1

The method defined by (35) (i.e., (3132)) is called fractional HBVM with parameters (k, s). In short, FHBVM(ks).

The efficient numerical solution of the discrete problem (32) will be considered in Section 3.4.

3 Implementation issues

In this section we report all the implementation details used in the Matlab\(^{\copyright }\) code fhbvm, which will be used in the numerical tests reported in Section 4.

3.1 Graded or uniform mesh?

The first relevant problem to face is the choice between a graded or a uniform mesh and, in the former case, also choosing appropriate values for the parameters r, N, and \(h_1\) in (910). We start considering a proper choice of this latter parameter, i.e., \(h_1\) which, in turn, will allow us to choose the type of mesh, too. For this purpose, the user is required to provide, in input, a convenient integer value \(M>1\), such that, if a uniform mesh is appropriate, then the stepsize is given by:

$$\begin{aligned} h = \frac{T}{M}. \end{aligned}$$
(36)

It is to be noted that, since the code is using a method with spectral accuracy in time, the value of M should be as small as possible. That said, we set \(h_1^0=h\) and apply the code on the interval \([0,h_1^0]\) both in a single step, and by using a graded mesh of 2 sub-intervals defined by a value of \(r:=\hat{r}\equiv 3\). As a result, the two sub-intervals, obtained by solving (10) for \(h_1\), with

$$ r=3, \qquad N=2, \qquad T=h_1^0,$$

are Footnote 4

$$[0,h_1^0/4], \qquad [h_1^0/4,h_1^0].$$

In so doing, we obtain two approximations to \(y(h_1^0)\), say \(y_1\) and \(y_2\). According to the analysis in [8], if Footnote 5

$$\begin{aligned} \Vert (y_1-y_2)./(1+|y_2|)\Vert _\infty \le \text{ tol }, \end{aligned}$$
(37)

with tol  a suitably small tolerance,Footnote 6 then this means the stepsize \(h_1:=h_1^0\) is appropriate. Moreover, in such a case, a uniform mesh with \(N\equiv M\) turns out to be appropriate, too.

Conversely, the procedure is repeated on the sub-interval \([0,h_1^1] \equiv [0,h_1^0/4]\), and so forth, until a convenient initial stepsize \(h_1\) is obtained. This process can be repeated up to a suitable maximum number of times that, considering that at each iteration the current guess of \(h_1\) is divided by 4, allows for a substantial reduction of the initial value (36). Clearly, in such a case, a graded mesh is needed. At the end of this procedure, we have then chosen the initial stepsize \(h_1\) which, if the procedure ends at the \(\ell \)-th iteration, for a convenient \(\ell >1\), is given by:

$$\begin{aligned} h_1 = 4^{1-\ell } h \equiv 4^{1-\ell } \frac{T}{M}. \end{aligned}$$
(38)

We need now to appropriately choose the parameters r and N in (910). To simplify this choice, we require that the last stepsize in the mesh be equal to (36). Consequently, we would ideally satisfy the following requirements:

$$h_1\frac{r^N-1}{r-1} = T, \qquad h_1r^{N-1} = \frac{T}{M},$$

which, by virtue of (38), become

$$4^{1-\ell }\frac{r^N-1}{r-1}=M, \qquad 4^{1-\ell }r^{N-1}=1.$$

Combining the two equations then gives:

$$\begin{aligned} r = \frac{M-4^{1-\ell }}{M-1}>1, \qquad N = 1 +\log _r(4^{\ell -1}). \end{aligned}$$
(39)

As is clear, this value of N is not an integer, in general, so that we shall choose, instead:

$$\begin{aligned} N = \lceil 1 +\log _r(4^{\ell -1})\rceil . \end{aligned}$$
(40)

Remark 4

From (40), and considering that \(Nh_1<T\) (conversely, a uniform mesh could have been used) and, by virtue of (38), one has:

$$\begin{aligned} 2\le N < 4^{\ell -1}M. \end{aligned}$$
(41)

As is clear, using the value of N in (40) in place of that in (39) implies that we need to recompute r, so that the requirement (now \(h_1\), N, and T are given)

$$\begin{aligned} h_1\frac{r^N-1}{r-1}=T \end{aligned}$$
(42)

is again fulfilled. Equation (42) can be rewritten as

$$\begin{aligned} r = \left[ 1 + (r-1)\beta \right] ^{1/N} =: \psi (r), \qquad \beta := \frac{T}{h_1}>1, \end{aligned}$$
(43)

thus inducing the iterative procedure

$$\begin{aligned} r_0>1 \quad (given), \qquad r_{i+1} = \psi (r_i), \qquad i=0,1,\dots . \end{aligned}$$
(44)

As a convenient choice for \(r_0\), one can use the guess for r defined in (39). The following result can be proved.

Theorem 1

There exists a unique \(\bar{r}>1\) satisfying \(\bar{r}=\psi (\bar{r})\), and the iteration (44) globally converges to this value over the interval \((1, +\infty )\).

Proof

A direct computation shows that:

$$\begin{aligned} \psi (1)=1, \qquad \psi '(r)>0, ~\text {for~} r>1, \\ \psi '(1)=\frac{\beta }{N}>1,~ \lim _{r\rightarrow +\infty } \psi '(r)=0, \qquad \psi ''(r)<0, ~\text {for~} r>1. \end{aligned}$$
(45)

From (45) we deduce that the (positive) mapping \(\psi (r)\) is strictly increasing and admits \((1,+\infty )\) as invariant set, since \(r>1\) implies \(\psi (r)>\psi (1)=1\).

From (46) we additionally deduce that \(\psi (r)\) is concave and \(\psi (r)>r\) for \(r\in (1,1+\varepsilon )\), with \(\varepsilon >0\) sufficiently small. These properties and the fact that \(\psi '(r) \rightarrow 0\), for \(r\rightarrow +\infty \), imply that:

  • the equation \(r=\psi (r)\) admits a unique solution  \(\bar{r}>1\)  and  \(\psi '(\bar{r})<1\);

  • \(\psi \big ((1,\bar{r})\big ) \subset (1,\bar{r})\)  and  \(\psi \big ((\bar{r},+\infty )\big ) \subset (\bar{r},+\infty )\)  (since \(\psi \) is increasing);

  • \(\psi (r)>r\)  for  \(1<r<\bar{r}\)  and  \(\psi (r)<r\)  for  \(r>\bar{r}\).

From the two latter properties we conclude that, for any \(r_0>1\), the sequence generated by (44) converges monotonically to \(\bar{r}\). \(\square \)

Consequently, we have derived the parameters \(h_1\) in (38), N in (40), and r satisfying (42) of the graded mesh (910), the latter one obtained by a few iterations of (44).

Remark 5

In the actual implementation of the code, we allow the use of a uniform mesh also when \(\ell =2\) steps of the previous procedure are required, provided that M has a moderate value (say, \(M\le 5\)). Consequently, for the final mesh, \(h_1=h/4\), \(r=1\), and \(N=4M\).

3.2 Approximating the fractional integrals

The practical implementation of the method requires the evaluation of the following integrals (recall (30) and the definitions (2324)):

$$\begin{aligned} I^\alpha P_j(c_i),\qquad i=1,\dots ,k,\quad j=0,\dots ,s-1, \end{aligned}$$
(46)

and

$$\begin{aligned} J_j^\alpha \left( \frac{r^\nu -1}{r-1}+c_ir^\nu \right) , \qquad i=1,\dots ,k,\quad j=0,\dots ,s-1, \quad \nu =1\dots ,N-1, \end{aligned}$$
(47)

in case a graded mesh is used, or

$$\begin{aligned} J_j^\alpha (\nu +c_i), \qquad i=1,\dots ,k,\quad j=0,\dots ,s-1, \quad \nu =1\dots ,N-1, \end{aligned}$$
(48)

in case a uniform mesh is used.

It must be emphasized that all such integrals ((47) and (48), or (47) and (49)), can be pre-computed once for all, for later use. For their computation, in the first version of the software, we adapted an algorithm based on [5] which, however, required a quadruple precision, for the considered values of k and s. In this respect, the use of the standard vpa of Matlab\(^{\copyright }\), which is based on a symbolic computation, turned out to be too slow. For this reason, hereafter we describe two new algorithms for computing the above integrals, which result to be quite satisfactory, when using the standard double precision IEEE. Needless to say that, since vpa is no more required, they turn out to be much faster than the previous ones.

Let us describe, at first, the computation of (47). One has, by considering that \(k\ge s\) and \(c_i\in (0,1)\):

$$\begin{aligned} I^\alpha P_j(c_i)= & \frac{1}{\varGamma (\alpha )}\int _0^{c_i}(c_i-\tau )^{\alpha -1}P_j(\tau )\textrm{d}\tau \\= & \,\frac{c_i^{\alpha -1}}{\varGamma (\alpha )}\int _0^{c_i}\left( 1-\frac{\tau }{c_i}\right) ^{\alpha -1}P_j(\tau )\textrm{d}\tau \,=\,\frac{c_i^\alpha }{\varGamma (\alpha )}\int _0^1\left( 1-\xi \right) ^{\alpha -1}P_j(\xi c_i)\textrm{d}\xi \\= & \,\frac{c_i^\alpha }{\varGamma (\alpha +1)}\int _0^1\alpha \left( 1-\xi \right) ^{\alpha -1}P_j(\xi c_i)\textrm{d}\xi \,\equiv \, \frac{c_i^\alpha }{\varGamma (\alpha +1)}\sum _{\ell =1}^k b_\ell P_j(c_ic_\ell ),\\ & \qquad \qquad j=0,\dots ,s-1, \end{aligned}$$

where the last equality holds because the Jacobi quadrature formula has order 2k. Clearly, for each \(i=1,\dots ,k\), all the above integrals can be computed in vector form in “one shot”, by using the usual three-term recurrence to compute the Jacobi polynomials.

Concerning the integrals (48-49), let us now consider the evaluation of a generic \(J_j^\alpha (x)\), \(j=0,\dots ,s-1\), for \(x>1\). In this respect, there is numerical evidence that, for \(x\ge 1.1\), a high-order Gauss-Legendre formula is able to approximate the required integral to full machine precision. Since we will use a value of \(s=20\), we consider, for this purpose, a Gauss-Legendre formula of order 60, which turns out to be fully accurate. Instead, for \(x\in (1,1.1)\), one has:

$$\begin{aligned} J_j^\alpha (x)= & \frac{1}{\varGamma (\alpha )}\int _0^1 (x-\tau )^{\alpha -1}P_j(\tau )\textrm{d}\tau \nonumber \\= & \frac{1}{\varGamma (\alpha )}\left[ \int _0^x (x-\tau )^{\alpha -1}P_j(\tau )\textrm{d}\tau ~-~ \int _1^x(x-\tau )^{\alpha -1}P_j(\tau )\textrm{d}\tau \right] \nonumber \\= & \frac{x^{\alpha -1}}{\varGamma (\alpha )}\int _0^x \left( 1-\frac{\tau }{x}\right) ^{\alpha -1}P_j(\tau )\textrm{d}\tau \nonumber \\ & \qquad ~-~ \frac{(x-1)^{\alpha -1}}{\varGamma (\alpha )}\int _0^{x-1}\left( 1-\frac{c}{x-1}\right) ^{\alpha -1}P_j(1+c)\textrm{d}c \nonumber \\= & \frac{x^\alpha }{\varGamma (\alpha )}\int _0^1 (1-\xi )^{\alpha -1}P_j(\xi x)\textrm{d}\xi - \frac{(x-1)^\alpha }{\varGamma (\alpha )}\int _0^1 (1-\xi )^{\alpha -1}P_j(1+\xi (x-1))\textrm{d}\xi \nonumber \\= & \frac{x^\alpha }{\varGamma (\alpha +1)}\int _0^1 \alpha (1-\xi )^{\alpha -1}P_j(\xi x)\textrm{d}\xi \nonumber \\ & \qquad ~-~ \frac{(x-1)^\alpha }{\varGamma (\alpha +1)}\int _0^1 \alpha (1-\xi )^{\alpha -1}P_j(1+\xi (x-1))\textrm{d}\xi \nonumber \\\equiv & \frac{x^\alpha }{\varGamma (\alpha +1)}\sum _{\ell =1}^k b_\ell P_j(c_\ell x)~-~ \frac{(x-1)^\alpha }{\varGamma (\alpha +1)}\sum _{\ell =1}^k b_\ell P_j(1+c_\ell (x-1)), \nonumber \\ & \qquad \qquad j=0,\dots ,s-1, \end{aligned}$$

again, due to the fact that the quadrature is exact for polynomials of degree at most \(s-1\). Also in this case, for each fixed \(x>1\), all the integrals can be computed in “one shot” by using the three-term recurrence of the Jacobi polynomials.

We observe that the previous expression is exact also for \(x=1\), since \(J_j^\alpha (1)=\delta _{j0}/\varGamma (\alpha +1)\).

3.3 Error estimation

An estimate of the global error can be derived by computing the solution on a doubled mesh. In other words, if (see (31))

$$\bar{y}_n\,\approx \, y(t_n), \qquad n=0,\dots ,N,$$

with \(t_n\) as in (56), are the obtained approximations, then

$$e_n \,:=\, y(t_n)-\bar{y}_n \,\approx \, \hat{y}_{2n}-\bar{y}_n, \qquad n=0,\dots ,N,$$

where \(\hat{y}_n\approx y(\hat{t}_n)\), \(n=0,\dots ,2N\), is the solution computed on a doubled mesh.

When a uniform mesh (12) is used, the doubled mesh is simply given by:

$$\hat{t}_n = n\frac{h_1}{2}\equiv n\frac{T}{2N}, \qquad n=0,\dots ,2N.$$

Conversely, when a graded mesh (910) is considered, the doubled mesh is given by:

$$\hat{t}_n = \hat{t}_{n-1} + \hat{h}_n, \qquad \hat{h}_n = \hat{r} \hat{h}_{n-1}\equiv \hat{r}^{n-1}\hat{h}_1, \qquad n=1,\dots ,2N,$$

with \(\hat{t}_0=0\), and

$$\hat{r} = \sqrt{r}, \qquad \hat{h}_1 = h_1\frac{\hat{r}-1}{r-1}.$$

The choice of \(\hat{h}_1\) is done for having

$$\hat{h}_1\frac{\hat{r}^{2N}-1}{\hat{r}-1} = \hat{h}_1\frac{r^N-1}{\hat{r}-1} \equiv h_1\frac{r^N-1}{r-1}=T,$$

according to (10).

3.4 The nonlinear iteration

At last, we describe the efficient numerical solution of the discrete problem (32), which has to be solved at the n-th integration step. As is clear, the very formulation of the problem induces a straightforward fixed-point iteration:

$$\begin{aligned} \gamma ^{n,\ell } = \mathcal {P}_s^\top \varOmega \otimes I_m f\left( \phi _{n-1}^{\alpha ,s} +h_n^\alpha \mathcal {I}_s^\alpha \otimes I_m\gamma ^{n,\ell -1}\right) ,\qquad n=1,2,\dots , \end{aligned}$$
(49)

which can be conveniently started from \(\gamma ^{n,0}=\textbf{0}\). The following straightforward result holds true.

Theorem 2

Assume f be Lipchitz with constant L in in the interval \([t_{n-1},t_n]\). Then, the iteration (50) is convergent for all timesteps \(h_n\) such that

$$h_n^\alpha L\Vert \mathcal {P}_s^\top \varOmega \Vert \Vert \mathcal {I}_s^\alpha \Vert < 1.$$

Proof

See [8, Theorem 2].\(\square \)

Nevertheless, as is easily seen, also the simple equation

$$y^{(\alpha )} = -\lambda y, \qquad t\in [0,T], \qquad y(0)=1, \qquad T,\lambda \gg 1,$$

whose solution is almost everywhere close to 0, after an initial transient, suffers from stepsize limitations, if the fixed-point iteration (50) is used, since it has to be everywhere proportional to \(\lambda ^{-1/\alpha }\).

In order to overcome this drawback, a Newton-type iteration is therefore needed. Hereafter, we consider the so-called blended iteration which has been at first studied in a series of papers [7, 14, 16, 17]. It has been implemented in the Fortran codes BIM [15], for ODE-IVPs, and BIMD [18], for ODE-IVPs and linearly implicit DAEs, and in the Matlab code hbvm [10, 13], for solving Hamiltonian problems. We here consider its adaption for solving (32). By neglecting, for sake of brevity, the time-step index n, we then want to solve the equation:

$$\begin{aligned} G(\gamma ) := \gamma - \mathcal {P}_s^\top \varOmega \otimes I_m f\left( \phi ^{\alpha ,s} +h^\alpha \mathcal {I}_s^\alpha \otimes I_m\gamma \right) = {\varvec{0}}. \end{aligned}$$
(50)

By setting \(f_0'\) the Jacobian of f evaluated at the first entry of \(\phi ^{\alpha ,s}\), \(I=I_s\otimes I_m\), and

$$\begin{aligned} X_s^\alpha := \mathcal {P}_s^\top \varOmega \mathcal {I}_s^\alpha , \end{aligned}$$
(51)

the application of the simplified Newton method then reads:

$$\begin{aligned} \mathrm {solve:} & \left( I - h^\alpha X_s^\alpha \otimes f_0' \right) \varDelta \gamma ^\ell = -G(\gamma ^\ell ) \equiv {\varvec{\eta }}^\ell , \nonumber \\ \mathrm {set:} & \gamma ^{\ell +1}=\gamma ^\ell +\varDelta \gamma ^\ell ,\qquad \ell =0,1,\dots . \end{aligned}$$
(52)

Even though this iteration has the advantage of using a coefficient matrix which is constant at each time-step, nevertheless, its dimension may be large, when either s or m are large. To study a different iteration, able to get rid of this problem, let us decouple the linear system into the various eigenspaces of \(f_0'\), thus studying the simpler problem

$$\begin{aligned} \mathrm {solve:} & \left( I_s - h^\alpha \mu X_s^\alpha \right) \varDelta \gamma ^\ell = -g(\gamma ^\ell )\equiv \eta ^\ell , \\ \mathrm {set:} & \gamma ^{\ell +1}=\gamma ^\ell +\varDelta \gamma ^\ell ,\qquad \ell =0,1,\dots , \end{aligned}$$

with all involved vectors of dimension s, and \(\mu \in \sigma (f_0')\) a generic eigenvalue of \(f_0'\), and an obvious meaning of \(g(\gamma ^\ell )\). By setting \(q=h^\alpha \mu \), the iteration then reads:

$$\begin{aligned} \mathrm {solve:} & \left( I_s - q X_s^\alpha \right) \varDelta \gamma ^\ell = \eta ^\ell , \nonumber \\ \mathrm {set:} & \gamma ^{\ell +1}=\gamma ^\ell +\varDelta \gamma ^\ell ,\qquad \ell =0,1,\dots . \end{aligned}$$
(53)

Hereafter, we consider the iterative solution of the linear system in (54). A linear analysis of convergence (in the case the r.h.s. is constant) is then made, as at first suggested in [31,32,33], and later refined in [14, 17]. Consequently, skipping the iteration index \(\ell \), let us consider the linear system to be solved:

$$ \left( I_s - q X_s^\alpha \right) \varDelta \gamma = \eta ,$$

and its equivalent formulation, derived considering that matrix (52) is nonsingular, and with \(\xi >0\) a parameter to be later specified,

$$ \xi \left( (X_s^\alpha )^{-1} - q I_s \right) \varDelta \gamma = \xi (X_s^\alpha )^{-1}\eta =: \eta _1.$$

Further, we consider the blending of the previous two equivalent formulations with weights \(\theta (q)\) and \(I_s-\theta (q)\), where, by setting \(O\in \mathbb {R}^{s\times s}\) the zero matrix,

$$\theta (q) := I_s(1-\xi q)^{-1}\left\{ \begin{array}{cc} \approx I_s, & \quad q\approx 0,\\ \rightarrow O, & q\rightarrow \infty .\end{array}\right. $$

In so doing, one obtains the linear system

$$\begin{aligned} M(q)\varDelta \gamma = \eta _1+\theta (q)(\eta -\eta _1) =: \eta (q), \end{aligned}$$
(54)

with the coefficient matrix,

$$M(q) = \xi \left( (X_s^\alpha )^{-1} - q I_s \right) + \theta (q)\left[ \left( I_s - q X_s^\alpha \right) -\xi \left( (X_s^\alpha )^{-1} - q I_s \right) \right] ,$$

such that [14]:

$$M(q) \approx \left\{ \begin{array}{cc} I_s, & q\approx 0,\\ -\xi qI_s,& |q|\gg 1.\end{array}\right. $$

This naturally induces the splitting matrix

$$\begin{aligned} N(q) := I_s(1-\xi q)\equiv \theta (q)^{-1}, \end{aligned}$$
(55)

defining the blended iteration

$$\begin{aligned} \varDelta \gamma _i = \left[ I_s-\theta (q)M(q)\right] \varDelta \gamma _{i-1} +\theta (q)\eta (q), \qquad i=1,2,\dots . \end{aligned}$$
(56)

This latter iteration converges iff the spectral radius of the iteration matrix,

$$\begin{aligned} \rho \left( I_s-\theta (q)M(q)\right) =: \rho (q) <1. \end{aligned}$$
(57)

The iteration is said to be A-convergent if (58) holds true for all \(q\in \mathbb {C}^-\), the left-half complex plane, and L-convergent if, in addition, \(\rho (q)\rightarrow 0\), as \(q\rightarrow \infty \). Since [14]

$$\theta (0)M(0)=I_s, \qquad \theta (q)M(q)\rightarrow I_s, \quad q\rightarrow \infty ,$$

the blended iteration is L-convergent iff it is A-convergent. For this purpose, we shall look for a suitable choice of the positive parameter \(\xi >0\). Considering that \(\theta (q)\) is well defined for all \(q\in \mathbb {C}^-\), the following statement easily follows from the maximum modulus theorem.

Theorem 3

The blended iteration is L-convergent iff the maximum amplification factor,

$$\rho ^* := \max _{x>0} \rho (\textrm{i}x) \le 1.$$

The following result also holds true.

Theorem 4

The eigenvalues of the iteration matrix \(I_s-\theta (q)M(q)\) are given by:

$$\frac{q(\lambda -\xi )^2}{\lambda (1-q\xi )^2}, \qquad \lambda \in \sigma (X_s^\alpha ).$$

Consequently, the maximum amplification factor is given by:

$$\begin{aligned} \rho ^* = \max _{\lambda \in \sigma (X_s^\alpha )} \frac{|\lambda -\xi |^2}{2\xi |\lambda |}. \end{aligned}$$
(58)

Proof

See [14, Theorem 2 and (25)], by considering that

$$\max _{q\in \mathbb {C}^-} \frac{q(\lambda -\xi )^2}{\lambda (1-q\xi )^2} ~\equiv ~ \max _{x>0}\frac{x|\lambda -\xi |^2}{|\lambda |(1+x^2\xi ^2)}$$

is obtained at \(x=\xi ^{-1}\), so that (59) follows. \(\square \)

Slightly generalizing the arguments in [14], we then consider the following choice of the parameter \(\xi \),

$$\begin{aligned} \xi = \textrm{argmin}_{\mu \in \sigma (X_s^\alpha )} \max _{\lambda \in \sigma (X_s^\alpha )} \frac{|\lambda -|\mu ||^2}{2|\mu ||\lambda |}, \end{aligned}$$
(59)

which is computed once forall, and always provides, in our experiments, an L-convergent iteration. In particular, the code fhbvm uses, at the moment, \(k=22\) and \(s=20\): the corresponding maximum amplification factor (59) is depicted in Fig. 1, w.r.t. the order \(\alpha \) of the fractional derivative, thus confirming this.

Fig. 1
figure 1

Maximum amplification factor (5960), \(k=22\) and \(s=20\)

Coming back to the original problem (53), starting from the initial guess \(\varDelta \gamma ={\varvec{0}}\), and updating the r.h.s. as soon as a new approximation to \(\gamma \) is available, one has that the iteration (5557) simplifies to:

$$\begin{aligned} {\varvec{\eta }}^\ell= & -G(\gamma ^\ell ) \nonumber \\ {\varvec{\eta }}_1^\ell= & \xi (X_s^\alpha )^{-1}\otimes I_m\, {\varvec{\eta }}^\ell \nonumber \\ \gamma ^{\ell +1}= & \gamma ^\ell +I_s\otimes \varTheta \left[ {\varvec{\eta }}_1^\ell + I_s\otimes \varTheta \left( {\varvec{\eta }}^\ell -{\varvec{\eta }}_1^\ell \right) \right] , \qquad \ell =0,1,\dots , \end{aligned}$$
(60)

with \(\xi \) chosen according to (60), and

$$\begin{aligned} \varTheta = \left( I_m- h^\alpha \xi f_0'\right) ^{-1}. \nonumber \end{aligned}$$
(61)

Consequently, only the factorization of one matrix, having the same dimension m of the problem, is needed. Moreover, the initial guess \(\gamma ^0={\varvec{0}}\) can be conveniently considered in (61).

Remark 6

It is worth mentioning that, due to the properties of the Kronecker product, the iteration (61) can be compactly cast in matrix form, thus avoiding an explicit use of the Kronecker product. This implementation has been considered in the code fhbvm used in the numerical tests.

Actually, according to Theorem 2, in the code fhbvm we automatically switch between the fixed-point iteration (50) or the blended iteration (61), depending on the fact that

$$h^\alpha \Vert f_0'\Vert \Vert \mathcal {P}_s^\top \varOmega \Vert \Vert \mathcal {I}_s^\alpha \Vert \le tol,$$

with \(tol<1\) a suitable tolerance.

4 Numerical Tests

In this section we report a few numerical tests using the Matlab\(^{\copyright }\) code fhbvm: the code implements a FHBVM(22,20) method using all the strategies discussed in the previous section. The calling sequence of the code is:

[t,y,stats,err] = fhbvm( fun, y0, T, M )

In more details,

  • In input:

    • fun is the identifier (or the function handling) of the function evaluating the r.h.s. of the equation (also in vector mode), its Jacobian, and the order \(\alpha \) of the fractional derivative (see help fhbvm for more details);

    • y0 is the initial condition;

    • T is the final integration time;

    • M is the parameter in (36) (it should be as small as possible);

  • In output:

    • t,y contain the computed mesh and solution;

    • stats (optional) is a vector containing the following time statistics:

      1. 1.

        the pre-processing time for computing the parameters \(h_1\), r, and N (see Section  ()) and the fractional itegrals (47), and (48) or (49);

      2. 2.

        the time for solving the problem;

      3. 3.

        the pre-processing time for computing the fractional itegrals (47), and (48) or (49) for the error estimation;

      4. 4.

        the time for solving the problem on the doubled mesh, for the error estimation;

    • err (optional), if specified, contains the estimate of the absolute error. This estimate, obtained on a doubled mesh, is relatively costly: for this reason, when the parameter is not specified, the solution on the doubled mesh is not computed.

For the first two problems, we shall also make a comparison with the Matlab\(^{\copyright }\) code flmm2 [27],Footnote 7 in order to emphasize the potentialities of the new code. All numerical tests have been done on a M2-Silicon based computer with 16GB of shared memory, using Matlab\(^{\copyright }\) R2023b.

The comparisons will be done by using a so called Work Precision Diagram (WPD), where the execution time (in sec) is plotted against accuracy. The accuracy, in turn, is measured through the mixed error significant computed digits (mescd) [39], defined, by using the same notation seen in (37), as Footnote 8

$${\texttt {mescd}} := -\log _{10} \max _{i=0,\dots ,N} \Vert (y(t_i)-\bar{y}_i)./(1+|y(t_i)|)\Vert _\infty ,$$

being \(t_i\), \(i=0,\dots ,N\), the computational mesh of the considered solver, and \(y(t_i)\) and \(\bar{y}_i\) the corresponding values of the solution and of its approximation.

4.1 Example 1

The first problem [28] is given by:

$$\begin{aligned} \nonumber y^{(\alpha )}= & -|y|^{1.5} +\frac{8!}{\varGamma (9-\alpha ) }t^{8-\alpha } - 3\frac{\varGamma (5+\alpha /2)}{\varGamma (5-\alpha /2)}t^{4-\alpha /2} + \left( \frac{3}{2}t^{\alpha /2} - t^4 \right) ^3 \nonumber \\ & ~+ \frac{9}{4}\varGamma (\alpha +1), \qquad t\in [0,1], \qquad y(0)=0, \end{aligned}$$
(62)

whose solution is

$$ y(t) = t^8-3\,t^{4+\alpha /2}+\frac{9}{4}\,t^{\alpha }. $$

We consider the value \(\alpha =0.3\), and use the codes with the following parameters, to derive the corresponding WPD:

  • flmm2 :  \(h=10^{-1}2^{-\nu }\), \(\nu =1,\dots ,20\);

  • fhbvm :  \(M=2,3,4,5\).

Figure 2 contains the obtained results: as one may see, flmm2 reaches less than 12 mescd, since by continuing reducing the stepsize, at the 15-th mesh doubling the error starts increasing. On the other hand, the execution time essentially doubles at each new mesh doubling. Conversely, fhbvm can achieve full machine accuracy by employing a uniform mesh with stepsize \(h_1=1/M\), with M very small, thus using very few mesh points. As a result, fhbvm requires very short execution times.

Fig. 2
figure 2

Work-precision diagram for problem (62), \(\alpha =0.3\)

4.2 Example 2

We now consider the following linear problem:

$$\begin{aligned} \nonumber y^{(0.5)}= & \left( \begin{array}{rr}-50 & ~0 \\ -49 & ~-1\end{array}\right) y, \qquad t\in [0,20],\\ y(0)= & (2,\, 3)^\top , \end{aligned}$$
(63)

having solution

$$y(t) = \left( \begin{array}{c} 2\,E_{0.5}\left( -50\cdot t^{0.5}\right) \\[1mm] 2\,E_{0.5}\left( -50\cdot t^{0.5}\right) +E_{0.5}\left( - t^{0.5}\right) \end{array}\right) ,$$

with \(E_{0.5}\) the Mittag-Leffler function.Footnote 9 We use the codes with the following parameters, to derive the corresponding WPD:

  • flmm2 :  \(h=10^{-1}2^{-\nu }\), \(\nu =1,\dots ,20\);

  • fhbvm :  \(M=5,\dots ,10\).

Figure 3 contains the obtained results, from which one deduces that flmm2 achieves about 5 mescd (with a run time of about 85 sec), whereas fhbvm has approximately 13 mescd, with an execution time of about 1 sec. Further, in Fig. 4, we plot the true and estimated (absolute) errors for fhbvm in the case \(M=10\) (corresponding to a computational mesh made up of 251 mesh-points, with an initial stepsize \(h_1\approx 7.3\cdot 10^{-12}\), and a final stepsize \(h_{250}\approx 2\)): as one may see from the figure, there is a substantial agreement between the two errors.

Fig. 3
figure 3

Work-precision diagram for problem (63)

Fig. 4
figure 4

True and estimated absolute errors for fhbvm solving problem (63), \(M=10\)

4.3 Example 3

We now consider the following nonlinear problem [8]:

$$\begin{aligned} y_1^{(1/3)}(t)= & \frac{t}{10}\left( y_1^3 - \left( \sqrt{y_2}+1\right) ^3\right) + \frac{\varGamma (5/3)}{\varGamma (4/3)}t^{1/3}, \nonumber \\ y_2^{(1/3)}(t)= & \frac{1}{3}\left( y_2^3 - ( y_1-1)^6 \right) + \varGamma (7/3)t,\qquad t\in [0,1], \nonumber \\ y(0)= & (1,\, 0)^\top , \end{aligned}$$
(64)

having solution

$$y(t) = \left( \begin{array}{c} t^{2/3}+1 \\ t^{4/3}\end{array}\right) .$$

This problem is relatively simple and, in fact, both flmm2 and fhbvm solve it accurately. We use it to show the estimated error by using fhbvm with parameter \(M=2\), which produces a graded mesh with 41 mesh-points, with \(h_1\approx 1.8\cdot 10^{-12}\) and \(h_{40}\approx 0.49\). The absolute errors (true and estimated) for each component are depicted in Fig. 5, showing a perfect agreement for both of them.

In this case, the evaluation of the solution requires \(\approx 0.04\) sec, and the error estimation requires \(\approx 0.11\) sec.

Fig. 5
figure 5

True and estimated absolute errors for fhbvm solving problem (64), \(M=2\)

4.4 Example 4

At last, we consider the following fractional Brusselator model:

$$\begin{aligned} y_1^{(0.7)}= & 1-4y_1+y_1^2y_2, \nonumber \\ y_2^{(0.7)}= & 3y_1-y_1^2y_2, \qquad t\in [0,5], \nonumber \\ y(0)= & (1.2,\,2.8)^\top , \end{aligned}$$
(65)

By solving this problem using fhbvm with parameter \(M=5\), a graded mesh of 46 points is produced, with \(h_1\approx 6.1\cdot 10^{-5}\) and \(h_{45}\approx 0.98\). The maximum estimated error in the computed solution is less than \(3.5\cdot 10^{-13}\), whereas the phase-plot of the solution is depicted in Fig. 6.

In this case, the evaluation of the solution requires \(\approx 0.04\) sec, and the error estimation requires \(\approx 0.14\) sec.

Fig. 6
figure 6

Phase-plot of the computed solution by using fhbvm solving problem (65), \(M=5\)

5 Conclusions

In this paper we have described in full details the implementation of the Matlab\(^{\copyright }\) code fhbvm, able to solving systems of FDE-IVPs. The code is based on a FHBVM(22,20) method, as described in [8]. We have also provided comparisons with another existing Matlab\(^{\copyright }\) code, thus confirming its potentialities. In fact, due to the spectral accuracy in time of the FHBVM(22,20) method, the generated computational mesh, which can be either a uniform or a graded one, depending on the problem at hand, requires relatively few mesh points. This, in turn, allows to reduce the execution time due to the evaluation of the memory term required at each step.

We plan to further develop the code fhbvm, in order to provide approximations at prescribed mesh points, as well as to allow selecting different FHBVM(ks), \(k\ge s\), methods [8]. At last, we plan to extend the code to cope with values of the fractional derivative, \(\alpha \), greater than 1.