1 Introduction

During the last decades, fractional derivatives have been utilized in increasingly many application areas, as surveyed for ex. in [3, 23]. Regarding their numerical evaluations, previously available methods have generally suffered from low convergence rates. For functions that are analytic along a path connecting the fractional derivative’s base and evaluation points, the approach presented here converges faster than \(O(h^{22})\), where h is the grid spacing, thereby easily providing close to machine precision \(10^{-15}\) accuracy.

1.1 Concept of Present Method

A fractional derivative takes the form of an integral between a base point and an evaluation point. In the case that function values are available on an equispaced grid in the complex plane, we show here that the quadrature method developed in [6, 7] generalizes to the fractional derivative case, which features an end point singularity. Since the method is here applied to analytic functions, there is a wide choice of integration paths. We use straight line segments that follow grid lines, together with \(5\times 5\)-sized ‘correction stencils’ at each path corner and at the base and evaluation points.

1.2 Outline of Paper

Section 2 starts with an introductory description of fractional derivatives and of complex plane finite difference (FD) approximations of regular derivatives. We focus on Caputo derivatives, since this type commonly preferred in the context of differential equations. Such derivatives of analytic functions again become analytic functions, with the base point typically becoming a branch point of the derivative. Sections 3 and 4 review the complex plane quadrature method described in [6, 7] and generalize this to the situation with the end point singularity in the integrand. The case when the base- and evaluation points are only a few grid points apart requires a somewhat different method, discussed in Sect. 5. Other special cases arise when the function to be differentiated has singularities, discussed in Sect. 6. Some previous numerical methods, in particular the Grünwald-Letnikov formula, are briefly commented on in Sect. 7. Following Conclusions, two appendices give examples of correction stencil weights and illustrate computed fractional derivatives in a number of cases, respectively. The latter is supplemented by displays of convergence rates as the grid spacing h is reduced. In contrast to the case of regular (integer order) derivatives, it is less common that fractional derivatives of elementary functions are available in closed form. The examples in the last appendix where chosen among with analytic results available, in order to readily confirm theoretically predicted convergence rates and that machine precision accuracies indeed are reached.

2 Some Background Materials

2.1 Fractional Derivatives

The history of fractional derivatives is almost as old as that of regular (integer order) derivatives.Footnote 1 However, most applications as well as computational approaches are much more recent. An aspect that still has received very little attention is accurate numerical computation of fractional derivatives of analytic functions. We find in this study that for this task, a very effective computational approach becomes available.

One standard reference for the main types of fractional derivatives is the monograph [20] (briefly summarized in [14]). The two most commonly used definitions are

Riemann-Liouville:

$$\begin{aligned} _{a}^{RL}D_{t}^{\alpha }f(t)=\frac{1}{\Gamma (n-\alpha )}\;\frac{d^{n}}{dt^{n}}\int _{a}^{t}\frac{f(\tau )}{(t-\tau )^{\alpha +1-n}}d\tau ,\qquad n-1<\alpha <n \end{aligned}$$
(1)

and Caputo [2]:

$$\begin{aligned} _{a}^{C}D_{t}^{\alpha }f(t)=\frac{1}{\Gamma (n-\alpha )}\;\int _{a}^{t}\frac{\frac{d^{n}}{d\tau ^{n}}f(\tau )}{(t-\tau )^{\alpha +1-n}}d\tau ,\qquad n-1<\alpha <n. \end{aligned}$$
(2)

With no loss of generality, we let the base point a be located at \(a=0\) and (initially) assume that the evaluation point t satisfies \(t>0\) (later t will be generalized to an arbitrarily placed point z in the complex plane). The two definitions are closely related:

$$\begin{aligned} _{0}^{RL}D_{t}^{\alpha }f(t)={}_{0}^{C}D_{t}^{\alpha }f(t)+\sum _{k=0}^{n-1}\frac{t^{k-\alpha }}{\Gamma (k+1-\alpha )}f^{(k)}(0). \end{aligned}$$
(3)

In a complex z-plane, the derivatives \(f^{(k)}(0)\) can be approximated very effectively from grid-based values for f(z) [9]. Our present focus on Caputo rather than on Riemann-Liouville derivatives is largely motivated by the simplicity these offer in the contexts of Laplace transforms and in formulating initial conditions for ODEs, as described in [20], Chapter 4 and [14], Chapters 2,4.Footnote 2 We simplify the notation by writing \(_{0}^{C}D_{z}^{\alpha }f(z)\) as \(D^{\alpha }f(z)\). Since, for m integer, \(D^{\alpha +m}f(z)=D^{\alpha }D^{m}f(z),\) we furthermore focus on \(n=1\), i.e., \(0<\alpha <1\).

2.2 Fractional Derivatives of Analytic Functions

Functions f(z) with \(z=x+iy\) are analytic if \(\frac{df}{dz}=\lim _{\triangle z\rightarrow 0}\frac{f(z+\triangle z)-f(z)}{\triangle z}\) is uniquely defined, no matter from which direction in the complex plane \(\triangle z\) approaches zero. Analyticity has a large number of important consequences, as surveyed in complex variables textbooks, e.g., [1, 11]. Most of the commonly used functions in applied mathematics generalize from the real axis to analytic functions over parts or all of the complex plane.

Theorem 1

The fractional derivative

$$\begin{aligned} D^{\alpha }f(z)=\frac{1}{\Gamma (1-\alpha )}\int _{0}^{z}\frac{f'(\tau )}{(z-\tau )^{\alpha }}d\tau ,\quad 0<\alpha <1 \end{aligned}$$
(4)

of an analytic function f(z) is again an analytic function.

Proof

We give two arguments below:

By Taylor expansion: With f(z) analytic around the base point \(z=0\), it has around this point a convergent Taylor expansion. Since for \(m\in {\mathbb {N}},\) \(D^{\alpha }z^{m}=\frac{\Gamma (m+1)}{\Gamma (m+1-\alpha )}z^{m-\alpha }\), a ratio test argument gives that \(D^{\alpha }f(z)=z^{-\alpha }\cdot \left\{ \begin{array}{l} \text {Taylor series with same}\\ \text {radius of convergence} \end{array}\right\} \). The fractional derivative introduces a branch point at the base point, but is otherwise analytic within at least the same circle of convergence.

By integration by parts: Let \(g(z)=D^{\alpha }f(z)\). Integration by parts in (4) gives \(g(z)=\frac{1}{\Gamma (2-\alpha )}\left( f'(0)\,z^{1-\alpha }+\int _{0}^{z}f''(\tau )\,(z-\tau )^{1-\alpha }d\tau \right) \) and therefore \(g'(z)=\frac{1}{\Gamma (1-\alpha )} \left( \frac{f'(0)}{z^{\alpha }}+\int _{0}^{z}\frac{f''(\tau )}{(z-\tau )^{\alpha }}d\tau \right) \). This derivative being well defined is a sufficient condition for g(z) to be analytic. Alternatively, we can note that \(g'(z)=\,_{0}^{RL}D_{z}^{\alpha }f'(z)\), which again is well defined. \(\square \)

2.3 Complex Plane FD Approximations

This section recalls briefly some observations from [9], in parts earlier described in [6, 7]. Complex plane FD stencils with \(N=(2n+1)\times (2n+1)\) nodes (\(n=1,2,\ldots \)) on a grid with spacing h will, for the \(p{\text {th}}\) derivative (\(p=1,2,3,\ldots \)), be accurate of order \(O(h^{N-p})\).Footnote 3 As examples of such stencils, Table 1 illustrates the weights in the cases of \(n=1\) and \(n=2\) for the first two derivatives. The order of accuracy for the shown \(3\times 3\) stencils are \(O(h^{8})\) and \(O(h^{7})\), and for the \(5\times 5\) stencils \(O(h^{24})\) and \(O(h^{23})\), respectively.

One major difference from traditional (real axis) FD approximations is that complex plane FD weights decrease in magnitude very much faster with the distance from the stencil’s center. With stencil nodes at \(z_{k}=\mu +i\,\nu ,\) \(-n\le \mu ,\nu \le +n\), the decay rate contains again an algebraic factor, but now further multiplied by the extremely rapidly decreasing factor \(e^{-\,\frac{\pi }{2}(\mu ^{2}+\nu ^{2})}\). This makes the approximations remain highly localized even when their stencil sizes / accuracy orders are increased.Footnote 4

Table 1 The weights in \(3\times 3\) and \(5\times 5\) size stencils for the first two derivatives

3 Complex Plane FD Approximations for a Fractional Derivative

The present task is to numerically evaluate

$$\begin{aligned} D^{\alpha }f(z)=\frac{1}{\Gamma (1-\alpha )}\int _{0}^{z}\frac{f'(\tau )}{(z-\tau )^{\alpha }}d\tau \, \end{aligned}$$
(5)

for \(0<\alpha <1\). Assuming that f(t) is analytic and singularity free along the integration path that we choose, two issues prevent the trapezoidal rule (TR) end correction approach from [6] to be immediately applicable to the numerical evaluation of (5):

  1. (i)

    The factor \(\frac{1}{(z-\tau )^{\alpha }}\) causes a singularity at the upper end of the integration interval, and

  2. (ii)

    The numerator of the integrand is \(f'(\tau )\) rather than \(f(\tau )\).Footnote 5

3.1 End Corrections—Concept

Before embarking on derivations of end correction stencils for numerical integration, we illustrate their concept with two examples. The integral (5) is over a finite interval, and the path from 0 to z (complex) can be changed to line segments following grid lines horizontally and vertically in the complex plane. With insights from [6, 7], placing a correction stencil at each sub-interval end point, together with applying the trapezoidal rule (TR) in-between gives for analytic functions the accuracy \(O(h^{N+1})\), where N is the total number of nodes in each of the correction stencils.Footnote 6 For short intervals, the stencils at the two ends may overlap.

For both conceptual descriptions and derivations, it is simplest to consider the semi-infinite interval \([0,\infty ]\). In the case of \(\int _{0}^{\infty }f(z)dz\), one finds

$$\begin{aligned} \int _{0}^{\infty }f(z)dz=h\;\left[ \begin{array}{ccc} \genfrac(){0.0pt}1{-0.0020}{-0.0019i} &{} \;\genfrac(){0.0pt}1{0}{-0.0187i}\; &{} \left( {\begin{array}{c}0.0020\\ -0.0019i\end{array}}\right) \\ \\ \genfrac(){0.0pt}1{-0.0150}{+0i} &{} \left( {\begin{array}{c}0.5000\\ +0i\end{array}}\right) &{} \genfrac(){0.0pt}1{0.0150}{+0i}\\ \\ {\genfrac(){0.0pt}1{-0.0020}{+0.0019i}} &{} {\genfrac(){0.0pt}1{0}{+0.0187i}} &{} {\left( {\begin{array}{c}0.0020\\ +0.0019i\end{array}}\right) } \end{array}\right] f+h\sum _{k=1}^{\infty }f(kh)+O(h^{10}). \end{aligned}$$
(6)

The stencil is centered at the origin \(z=0\), and its entries are here rounded to four decimal places. These entries, as well as those for its \(5\times 5\) counterpart (accurate to \(O(h^{26})\)), were given in exact rational form in [6]. Apart from the central stencil entry 1/2 (alternatively included in the TR sum), the entries are numerically very small, but nevertheless greatly increase the accuracy order from \(O(h^{2})\) for the standard TR.

In the case of \(0<\alpha <1\), the upper end point in (5) is singular. After changing variable to move the singularity to \(z=0\), an integration by part is needed to get f(z) instead of \(f'(z)\).Footnote 7 Additionally, the interval [0, h] needs to be separated out to avoid subtracting infinities at the origin (arising from the integration by parts). The present novelty is that similarly accurate end corrections are again available. For example, in the case of \(\alpha =1/2\) (with the correction weight matrix again centered at \(z=0\)):

$$\begin{aligned} \int _{h}^{\infty }\frac{f(z)}{z^{3/2}}dz=h^{-1/2}\left[ \begin{array}{ccc} \left( {\begin{array}{c}0.0181\\ +0.0159i\end{array}}\right) &{} \;\left( {\begin{array}{c}0.0218\\ +0.1433i\end{array}}\right) \; &{} \left( {\begin{array}{c}-0.0182\\ +0.0210i\end{array}}\right) \\ \\ \left( {\begin{array}{c}0.1286\\ +0i\end{array}}\right) &{} \left( {\begin{array}{c}1.3027\\ +0i\end{array}}\right) &{} \left( {\begin{array}{c}-0.1685\\ +0i\end{array}}\right) \\ \\ \left( {\begin{array}{c}0.0181\\ -0.0159i\end{array}}\right) &{} \;\left( {\begin{array}{c}0.0218\\ -0.1433i\end{array}}\right) \; &{} \left( {\begin{array}{c}-0.0182\\ -0.0210i\end{array}}\right) \end{array}\right] f+h\sum _{k=1}^{\infty }\,\frac{f(kh)}{(kh)^{3/2}}+O(h^{17/2}).\nonumber \\ \end{aligned}$$
(7)

With \(5\times 5\) stencils, the accuracy orders increases to \(O(h^{49/2})\). End correction stencils of these kinds provide the key tools utilized below for accurate evaluation of (5). Appendix A shows the counterpart matrices to those in (6) and (7) for some different values of \(0<\alpha <1\), and also the \(n=2\) (size \(5\times 5\)) counterpart to the matrix in (7).

3.2 End Corrections—Explicitly

The task has become to numerically approximate

$$\begin{aligned} I=\int _{0}^{\,z}\frac{f'(\tau )}{(z-\tau )^{\alpha }}d\tau \end{aligned}$$
(8)

for \(0<\alpha <1\) and \(z>0\). Following the splitting of the interval [0, z] into \([0,z-h]\) and \([z-h,z]\) and integration by parts for the first of these sub-intervals, we obtain

$$\begin{aligned} \begin{array}{cccc} I= &{} \underbrace{\left\{ -\frac{f(0)}{z^{\alpha }}\right\} } &{} \underbrace{-\alpha \left\{ \int _{0}^{\,z-h}\frac{f(\tau )}{(z-\tau )^{\alpha +1}}d\tau \right\} } &{} \underbrace{+\left\{ \frac{f(z-h)}{h^{\alpha }}+\int _{z-h}^{\,z}\frac{f'(\tau )}{(z-\tau )^{\alpha }}d\tau \right\} }\\ &{} \text {Left End} &{} \text {interval} &{} \text {right end} \end{array}. \end{aligned}$$
(9)

For the central ‘interval’ part, we consider the trapezoidal rule (TR)-like approximationFootnote 8:

$$\begin{aligned} \int _{0}^{\,z-h}\frac{f(\tau )}{(z-\tau )^{\alpha +1}}d\tau \approx h\sum _{k=1}^{\left[ \frac{z}{h}\right] -1}\frac{f(kh)}{(z-kh)^{\alpha +1}}. \end{aligned}$$
(10)

For the discussion that follows, we introduce the notation \(b(\tau )=\frac{f(\tau )}{(z-\tau )^{\alpha +1}}\) and \(c(\sigma )=f(z-\sigma )\) such that the ends of the original integration interval [0, z] correspond to \(\tau =0\) and \(\sigma =0\), respectively. We will next show how to obtain the weights in these correction stencils at the two ends.

3.2.1 Left End

We assume for now that the function \(f(\tau )\) and, with that, also \(b(\tau )\) is regular around \(\tau =0\).Footnote 9 Since (10) amounts to a TR approximation, the correction approach sketched out in Sect. 3.1 applies. Following the methodology in [6, 7], we replace \(b(\tau )=\frac{f(\tau )}{(z-\tau )^{\alpha +1}}\) in (10) by \(e^{\xi \tau }\), obtaining from (9) and (10)

$$\begin{aligned} S_{1}&=-\alpha \left\{ \int _{0}^{\infty }e^{\xi \tau }d\tau -h\sum _{k=1}^{\infty }e^{\xi kh}\right\} =\alpha \,h\;\sum _{k=0}^{\infty }\frac{\zeta (-k)}{k!}(h\xi )^{k}. \end{aligned}$$
(11)

In this Taylor expansion (convergent for \(\left| h\xi \right| <2\pi \)), the terms for \(k=2,4,6,\ldots \) vanish, as these correspond to the trivial zeros of the zeta function.Footnote 10 The approach described below in Sect. 3.3 will convert this series expansion to weights in an end correction stencil.

3.2.2 Right End

We here changed notation by \(z-\tau =\sigma \), and therefore \(f(\tau )=f(z-\sigma )=c(\sigma ).\) The end correction strategy, now replacing \(c(\sigma )\) by \(e^{\xi \sigma }\) in (10), leads us to consider (for \(\text {Re }\xi <0\)):

From the ‘interval’ part of (9):

$$\begin{aligned} S_{2}\quad&=-\alpha \left\{ \int _{h}^{\infty }\frac{e^{\xi \sigma }}{\sigma ^{\alpha +1}}d\sigma \right\} +\alpha \left\{ h\sum _{k=1}^{\infty }\frac{e^{\xi kh}}{(kh)^{\alpha +1}}\right\} \end{aligned}$$
(12)
$$\begin{aligned}&=-\alpha \left\{ (-\xi )^{\alpha }\Gamma (-\alpha )+h^{-\alpha }\sum _{k=0}^{\infty }\frac{1}{k!(\alpha -k)}(h\xi )^{k}\right\} \end{aligned}$$
(13)
$$\begin{aligned}&\quad +\alpha \left\{ (-\xi )^{\alpha }\Gamma (-\alpha )+h^{-\alpha }\sum _{k=0}^{\infty }\frac{\zeta (1+\alpha -k)}{k!}(h\xi )^{k}\right\} . \end{aligned}$$
(14)

It is critically important to what follows that the fractional power of \(\xi \), present in both (13) and (14), cancels when summed. The expression for \(S_{2}\) is thus a Taylor series in \(h\xi \) (again convergent for \(\left| h\xi \right| <2\pi \)). Without the terms with the fractional \(\xi \)-powers canceling, FD-based end correction would not have been possible since these, described further in Sect. 3.3, can only eliminate terms with integer powers of \(\xi \).

From the ‘right end’ part of (9):

$$\begin{aligned} S_{3}=\frac{e^{\xi h}}{h^{\alpha }}-\int _{0}^{h}\frac{\xi \,e^{\xi \sigma }}{\sigma ^{\alpha }}d\sigma =\alpha \,h^{-\alpha }\sum _{k=1}^{\infty }\frac{1}{k!(\alpha -k)}(h\xi )^{k}. \end{aligned}$$
(15)

We note that this sum \(S_{3}\) exactly cancels the sum in (13).

The calculation of I as given in (8) (and thereby also of \(D^{\alpha }(z)\)) now amounts to calculating the sum in (10) and then correcting this with stencils corresponding to the expansions above in integer powers of \(\xi \). Next section describes the conversion of these Taylor expansions to FD correction stencil weights.

3.3 Converting Taylor Expansions in \(\xi \) to Stencil Weights

With use of nodes located at \(z_{k},\) \(k=1,\ldots ,N\),Footnote 11 the task is to find weights \(w_{k}\) at these nodes, such that as many leading terms in an error expansion \(S(\xi )=\sum _{k=0}^{\infty }\alpha _{k}\xi ^{k}\) can be matched (and thus canceled by subtraction). Applying such a stencil also to the function \(e^{\xi \,z}\), the key idea is to make \(\sum _{k=1}^{N}w_{k}e^{\xi z_{k}}=\sum _{k=0}^{\infty }\alpha _{k}\xi ^{k}\) agree to as many powers of \(\xi \) as possible. Taylor expanding the exponentials and equating powers of \(\xi \) gives (when truncated to N terms)

$$\begin{aligned} \left[ \begin{array}{ccccc} 1 &{} 1 &{} \cdots &{} \cdots &{} 1\\ z_{1} &{} z_{2} &{} \cdots &{} \cdots &{} z_{N}\\ z_{1}^{2} &{} z_{2}^{2} &{} \cdots &{} \cdots &{} z_{N}^{2}\\ \vdots &{} \vdots &{} &{} &{} \vdots \\ z_{1}^{N-1} &{} z_{2}^{N-1} &{} \cdots &{} \cdots &{} z_{N}^{N-1} \end{array}\right] \left[ \begin{array}{c} w_{1}\\ w_{2}\\ w_{3}\\ \vdots \\ w_{N} \end{array}\right] =\left[ \begin{array}{c} 0!\alpha _{0}\\ 1!\alpha _{1}\\ 2!\alpha _{2}\\ \vdots \\ (n-1)!\alpha _{N-1} \end{array}\right] . \end{aligned}$$
(16)

Since the coefficients in each of the \(S_{1},S_{2},S_{3}\)-expansions have a factorial in their denominators, the factorials in the right hand side vector of (16) immediately cancel out. This linear system for finding the correction stencil weights \(w_{k}\) has a Vandermonde-type coefficient matrix, and is therefore always non-singular (assuming the nodes \(z_{k}\) are distinct). As described previously in [10] and here illustrated in Fig. 1, the weights in quadrature end correction stencils grow rapidly with n (stencil size), making sizes above \(n=3\) in most cases impractical.Footnote 12

Fig. 1
figure 1

The \(N=(2n+1)\times (2n+1)\) stencil weights \(\left\{ w_{j}\right\} _{j=1}^{(2n+1)^{2}}\) illustrated for the first few values of n in the case of singularity-free end corrections. The color is determined by the magnitude of each \(w_{j}\) and the arrow inside each node shows their argument

In the descriptions in the next two Sects. 4 and 5, we continue to focus on the case when the base point (B) is at the origin, but let the evaluation point (E) be at some arbitrary grid point location in the complex plane (rather than only along the positive real axis; denoting its location by z).

4 Evaluation Point z Well Separated from Base Point: z Complex

We assume again that f(z) is non-singular at the base point \(z=0\). The main idea is to follow horizontal and vertical grid lines from B to E, as used for contour integrals in [6, 7] (i.e., with correction stencils also at each path corner). A key consideration is that no correction stencil, either centered at B or at a path corner point, can be close to E (as the integrand has a singularity there, and these correction stencils would then become inaccurate). Following this strategy, Fig. 2a, b illustrate suitable paths for two cases of E in the first quadrant. The dashed lines show branch cuts of the integrand in (1), (2), typically directed from E to the right. In case E is close to the negative real axis, Parts (c), (d) of the figure illustrate why the fractional derivative will have a branch line extending to the left from B (caused by the integrand being different in the two cases, when approaching E from the right).

Fig. 2
figure 2

a, b: Suitable integration paths when E is located in the first quadrant, c, d Paths for when E is located just above and just below the negative real axis, illustrating why the negative real axis becomes a branch line for a fractional derivative, with the origin as a branch point

Depending on the direction by which an interval end point is arrived at, the order of weights in the stencil will change as illustrated in Fig. 3 and a different factor of \(\left( \frac{h}{\triangle x+i\,\triangle y}\right) ^{\alpha }\) will also have to be applied to the stencil (e.g. when the evaluation point is reached from right to left, \(\triangle x=-h\) and \(\triangle y=0\) giving a factor of \((-1)^{\alpha }\).)

Fig. 3
figure 3

Illustration of how an end correction rotates with the direction of its line of integration

Fig. 4
figure 4

Computational strategy for when the evaluation point E is too close to the base point B for the approach in Sects. 3 and 4 to provide machine accuracy. This region is marked by the large circles (and by red circles in the later Relative error parts of Figs. 5, 6, 7, 8, 9, 10, 11 and 12). Parts (a) and (b) in the present figure illustrate the cases described in Sects. 5.1 and 6.1, respectively

5 Evaluation Point Close to Base Point

The end correction approach described by (6) assumes that f(z) is smooth (can be well represented by a polynomial approximation) near the end point \(z=0\). When z in (10) is only a few grid points away from zero, the integrand \(\frac{f(\tau )}{(z-\tau )^{\alpha +1}}\) violates this, necessitating a different strategy, as is illustrated in Fig. 4a. We find the midpoint between B and E and approximate the Taylor expansion of f(z) centered at this midpoint. The resulting fractional derivative integral can then be evaluated analytically, term by term. Two practical issues this gives rise to are described next.

Fig. 5
figure 5

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }e^{z}\) with \(\alpha =5/7\) and \(h=0.04\). The exact value is \(D^{\alpha }e^{z}=e^{z}\left( 1-\frac{\Gamma (1-\alpha ,z)}{\Gamma (1-\alpha )}\right) \). For the red circle in the last subplot of Figs. 5, 6, 7, 8, 9, 10, 11 and 12, see the explanation in the caption of Fig. 4

Fig. 6
figure 6

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }z^{3}\) with \(\alpha =0.2\) and \(h=0.04\). The exact value is \(D^{\alpha }z^{3}=\frac{6\,z^{3-\alpha }}{\Gamma (4-\alpha )}\)

Fig. 7
figure 7

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }\cos \left( \frac{\pi }{2}z\right) \) with \(\alpha =\nicefrac {1}{2}\) and \(h=\nicefrac {1}{10}\). The exact value is \(D^{1/2}\cos \left( \frac{\pi }{2}z\right) =\sqrt{\pi }(\cos \left( \frac{\pi }{2}z\right) S(\sqrt{z})-\sin \left( \frac{\pi }{2}z\right) C(\sqrt{z}))\), where S(z) and C(z) are respectively the Fresnel sine and cosine integral functions. All except for the error plots have been cropped in the imaginary direction for better clarity

5.1 Numerically Stable Way to Approximate the Taylor Coefficients

The linear system that provides Taylor coefficients from grid data is of Vandermonde type, and the task is generally very ill-conditioned. However, if the data points are equispaced around a circle centered at the expansion point, the Vandermonde matrix becomes a scaled version of the DFT (Discrete Fourier Transform) matrix, which is orthogonal, and thus perfectly conditioned. This motivates the choice of grid points marked blue in Fig. 4, as an approximation to this perfect circle case. For our standard choice of \(n=2\) (i.e., \(5\times 5\) size correction stencils), the ‘rule of thumb’ we have followed is to apply the midpoint procedure within a radius of 10h from the origin.Footnote 13

Fig. 8
figure 8

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }\frac{1}{1+z^{2}}\) with \(\alpha =0.5\) and \(h=1/20\). The exact value is \(D^{1/2}\frac{1}{1+z^{2}}=\frac{-8\,z^{3/2}\,_{3}F_{2}\left( 1,3/2,2;5/4,7/4;-z^{2}\right) }{3\sqrt{\pi }}\). The larger apparent error at some spots around the unit circle (in particular near the singularities at \(z=\pm i\)) and along some horizontal and vertical lines are caused by inaccuracies in the algorithm used for evaluating the \(_{3}F_{2}\) reference solution (with this issue arising again in Fig. 11)

Fig. 9
figure 9

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }z^{2.5}\) with \(\alpha =0.5\) and \(h=1/10\). The exact value is \(D^{1/2}z^{2.5}=\frac{15\sqrt{\pi }}{16}z^{2}\), which is entire. The fractional derivative of a function that features a branch point can have significant effects on it. For instance, if the function has an algebraic singularity \(\beta \), the branch point will be canceled if \(\beta -\alpha \) is an integer, as in this case. If \(\beta -\alpha \) is not an integer, as in Fig. 10, a branch point will be introduced at the origin, along with a branch cut (the position of the cut is arbitrary)

Fig. 10
figure 10

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }z^{2.89}\) with \(\alpha =0.12\) and \(h=1/10\). The exact value is \(D^{0.12}z^{2.89}=\frac{\Gamma (3.89)}{\Gamma (3.77)}z^{2.77}\), which features a branch point at the origin, and a branch cut along the negative real axis

Fig. 11
figure 11

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D^{\alpha }\sqrt{1+z^{2}}\) with \(\alpha =0.4\) and \(h=1/20\). The exact value is \(D^{0.4}\sqrt{1+z^{2}}=\frac{z^{1.6}\,_{3}F_{2}\left( 1/2,1,3/2;1.3,1.8;-z^{2}\right) }{0.96\,\Gamma (0.6)}\)

Fig. 12
figure 12

Plots of the real, imaginary, magnitude, phase portrait, and relative error of \(D_{z}^{\alpha }\log (1+z)\) with \(\alpha =0.5\) and \(h=1/20\). The exact value is \(D^{1/2}\log (1+z)=\frac{2}{\sqrt{\pi }}\mathrm{\frac{asinh\left( \sqrt{z}\right) }{\sqrt{1+z}}}\)

5.2 Analytic Form of the Resulting Integrals

The key formula here is

$$\begin{aligned} \int _{-b}^{b}\frac{z^{k}}{(b-z)^{\alpha }}dz=-(2b)^{1-\alpha }(-b)^{k}d_{k}, \end{aligned}$$
(17)

where

$$\begin{aligned} d_{0}=\frac{1}{\alpha -1},\qquad d_{k}=\frac{k\,d_{k-1}+1}{\alpha -(k+1)},\quad k=1,2,3,\ldots . \end{aligned}$$

This formula can be obtained for example by repeated integration by parts. Applying it to the Taylor terms obtained as described above produces the value of the fractional derivative at the evaluation point.

6 Some Special Cases

6.1 Function f(z) Singular at the Base Point \(z=0\)

If f(z) features a branch point at \(z=0\), such as \(f(z)=z^{\beta }g(z)\), where g(z) is analytic at the origin, the methods described above require some minor modifications. When the evaluation point is in the vicinity of the base point, we can Taylor expand g(z) around the origin (c.f., Fig. 4b) and apply the formula \(D^{\alpha }z^{\beta +k}=\frac{\Gamma (1+\beta +k)z^{\beta +k-\alpha }}{\Gamma (1+\beta +k-\alpha )}\) to each term of \(z^{\beta }g(z)\). On the other hand, when evaluation and base points are far from each other, a new correction stencil at the origin must be computed. The new weights will be applied to the function from which the singular term has been extracted, so will be applied to the values of g(z). In order to compute those weights, we will follow the same procedure as in Sect. 3.2.2, and obtain similarly to (12)

$$\begin{aligned} \int _{0}^{\infty }e^{\xi \sigma }\sigma ^{\beta }d\sigma -h\sum _{k=1}^{\infty }e^{\xi kh}(kh)^{\beta }=-h^{1+\beta }\,\sum _{k=0}^{\infty }\frac{\zeta (-\beta -k)}{k!}(h\xi )^{k}. \end{aligned}$$
(18)

Figures 9 and 10 show no loss of accuracy compared to the cases when f(z) is non-singular at the base point. If \(\beta \) is a negative integer, f(z) has a pole at the origin. Then \(D^{\alpha }z^{\beta }\) diverges, as also reflected by the last sum in (18) containing a term with \(\zeta (1)=\infty \).

6.2 Function f(z) with Poles in the Complex Plane

The integral diverges if f(z) features a pole along the integration path. We will therefore choose integration paths that go beside poles while not crossing branch cuts. The integrals whose evaluation points are located at or within n nodes of the poles will diverge. Integrals following paths to some evaluation point \(z_{0}\), on the different sides of a pole \(z_{p}\) will differ by \(\frac{2\pi i}{\Gamma (1-\alpha )}\mathrm{Residue\left( \frac{f'(z)}{(z_{0}-z)^{\alpha }},\{z,z_{p}\}\right) }\). Fractional derivatives of a function with poles will therefore feature branch points where the poles of f are located. The path of the branch cut is arbitrary and points in Fig. 8 (showing the fractional derivative of \(f(z)=\frac{1}{1+z^{2}}\)) away from the origin. Function values on different sheets are further illustrated in Figs. 13 and 14, again for \(f(z)=\frac{1}{1+z^{2}}\).

6.3 Functions f(z) with Branch Cuts in the Complex Plane

Apart from some additional care being needed to not integrate across any branch cut, the methods described above apply. One case is illustrated in Fig. 11.

7 Previously Available Computational Approaches

Previously described numerical approaches for calculating fractional derivatives based only on function values consider only the case of real-valued evaluation points. They fall in three main categories:

  1. 1.

    Function values are given on an equispaced grid,

  2. 2.

    Function values are required at prescribed non-equispaced locations [12],Footnote 14 and

  3. 3.

    Function values can be arbitrarily spaced [19, 21, 24].

Further references and discussions can be found for example in [4, 22]. Chapter 2 of the monograph [16] also contains an extensive survey of numerical methods for fractional derivatives. These are in many cases based on approximating f(t) by global or by piecewise polynomials, using either equi-spaced or Gaussian quadrature-type node sets. We will not make any attempt here to survey these numerous algorithm proposals, but refer readers to the references above. Concerns about several methods include slow rates of convergence under refinement, or restrictive assumptions (such as that the Taylor expansion of f(z), centered at the base or evaluation points, converges across the full interval of interest).

Grünwald-Letnikov formula: The sum

$$\begin{aligned} _{a}^{GL}\triangle _{h}^{\alpha }f(t)=\sum _{j=0}^{\left[ \frac{t-a}{h}\right] }(-1)^{j}\left( {\begin{array}{c}\alpha \\ j\end{array}}\right) f(t-jh)\; \end{aligned}$$
(19)

satisfies

$$\begin{aligned} \lim _{h\rightarrow 0}\frac{_{a}^{GL}\triangle _{h}^{\alpha }f(t)}{h^{\alpha }}\;=\;_{a}^{RL}D^{\alpha }f(t). \end{aligned}$$

It has a long history (introduced in 1868). Numerical usage of it is described for ex. in [20], Chapter 7. Following the idea (11)–(15) and again using \(f(z)=e^{\xi z}\) gives

$$\begin{aligned} GL&=-\frac{1}{h^{\alpha }}\sum _{k=0}^{\infty }(-1)^{k}\left( {\begin{array}{c}\alpha \\ k\end{array}}\right) e^{\xi kh}=\left( \frac{e^{h\xi }-1}{h}\right) ^{\alpha }\nonumber \\&=\xi ^{\alpha }\left( -1+\frac{1}{2}\alpha (h\xi )^{1}-\frac{1}{24}\alpha (1+3\alpha )(h\xi )^{2}+\frac{1}{48}\alpha ^{2}(1+\alpha )(h\xi )^{3}-+\ldots \right) . \end{aligned}$$
(20)

The leading term \(-\xi ^{\alpha }\) agrees with the exact result, but the next term reflects an error of size \(O(h^{1})\). Since all terms in the expansion (20) contain fractional powers of \(\xi \), there is in this case no opportunity for FD-type end corrections.

8 Concluding Discussion

The approach for calculating fractional derivatives introduced here (trapezoidal rule along grid lines together with end corrections) is both highly accurate (better than \(O(h^{20})\) convergence rate) and computationally fast. Grid resolutions typical for ‘reasonably resolved’ functional displays suffice for double precision accuracy. Future opportunities for investigations include

  1. (i)

    Numerical evaluation of certain special functions. Cases listed in Table 17.1 in [15] include functions such as \(_{1}F_{1}(a;c;z)\) and \(_{2}F_{1}(a;b;c;z)\) expressed as fractional derivatives of elementary functions.

  2. (ii)

    Generalizations to cases when the functional data is available only along the real axis.Footnote 15