Skip to main content
Log in

Finite difference formulas in the complex plane

  • Original Paper
  • Published:
Numerical Algorithms Aims and scope Submit manuscript

Abstract

Among general functions of two variables f(x, y), analytic functions f(z) with z = x + iy form a very important special case. One consequence of analyticity turns out to be that 2-D finite difference (FD) formulas can be made remarkably accurate already for small stencil sizes. This article discusses some key properties of such complex plane FD formulas. Application areas include numerical differentiation, interpolation, contour integration, and analytic continuation.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7

Similar content being viewed by others

Notes

  1. Chapter 1 of [12] gives several algorithms for computing FD weights in 1-D on either equi-spaced or irregularly spaced nodes, with its later chapters focusing on non-Cartesian node layouts in multiple dimensions.

  2. cf., (3) below.

  3. The reverse statement that the CR equations imply analyticity requires only slight “fine print,” to rule out cases such as \(f(z)=e^{-1/z^{4}},\) for which the CR equations hold also at the point of discontinuity z = 0.

  4. As surveyed in text books on analytic functions, e.g., [3, 13].

  5. Chapter 1 in [12] provides a summary of FD methods, including method 1. Method 2 produces the identical linear system to solve (differing only in how the equations are scaled).

  6. Such as the Painlevé transcendents, cf., [14].

  7. See for ex. [12], Section 1.2.2.

  8. See for ex. [13], Theorem 2.12.

  9. Given the stencil size for u, this weight set is not unique, but it becomes unique if we impose the expected symmetries in the two directions.

  10. Method 1 can similarly be adapted to provide highly accurate FD formulas for derivatives of harmonic functions.

  11. This is a key reason why these formulas can be highly effective also near singularities, as illustrated in Figs. 2 and 3.

  12. Here, and later in (21) and (22), one stencil node is assumed located at z = 0, with zk a different node.

  13. Hermite-FD formulas approximate the pth derivative, p ≥ 2, using both function and first derivative values: \(f^{(p)}(0)\approx {\sum }_{k=-n}^{n}b_{k}f(k)+{\sum }_{k=-n}^{n}c_{k}f^{\prime }(k)\). Their infinite order PS limit is similar to that of regular FD-PS methods, as analyzed in [2].

  14. Multiprecision Computing Toolbox for MATLAB, http://www.advanpix.com/, Advanpix LLC, Yokohama, Japan.

References

  1. Abate, J., Dubner, H.: A new method for generating power series expansion of functions. SIAM J. Numer. Anal. 5, 102–112 (1968)

    Article  MathSciNet  Google Scholar 

  2. Abrahamsen, D., Fornberg, B.: On the infinite order limit of Hermite-based finite difference schemes. SIAM J. Numer. Anal. 59(4), 1857–1874 (2021)

    Article  MathSciNet  Google Scholar 

  3. Ahlfors, L. V.: Complex Analysis. McGraw-Hill, New York (1966)

    MATH  Google Scholar 

  4. Birkhoff, G., Young, D.: Numerical quadrature of analytic and harmonic functions. J. Math. Phys. 29, 217–221 (1950)

    Article  MathSciNet  Google Scholar 

  5. Bornemann, F.: Accuracy and stability of computing high-order derivatives of analytic functions by Cauchy integrals. Found. Comput. Math. 11, 1–63 (2011). https://doi.org/10.1007/s10208--010--9075--z

    Article  MathSciNet  Google Scholar 

  6. Fornberg, B.: Numerical differentiation of analytic functions. ACM Trans. Math. Softw. 7(4), 512–526 (1981)

    Article  MathSciNet  Google Scholar 

  7. Fornberg, B.: A Practical Guide to Pseudospectral Methods. Cambridge University Press (1996)

  8. Fornberg, B.: Euler-Maclaurin expansions without analytic derivatives. Proc. Royal Soc. Lond. Ser. A 476(20200441). https://doi.org/10.1098/rspa.2020.0441 (2020)

  9. Fornberg, B.: Contour integrals of analytic functions given on a grid in the complex plane. IMA J. Numer. Anal. 41, 814–825 (2021). https://doi.org/10.1093/imanum/draa024

    Article  MathSciNet  Google Scholar 

  10. Fornberg, B.: Generalizing the trapezoidal rule in the complex plane. Numer. Algorithm. 87, 187–202 (2021)

    Article  MathSciNet  Google Scholar 

  11. Fornberg, B.: Improving the accuracy of the trapezoidal rule. SIAM Rev. 63(1), 167–180 (2021)

    Article  MathSciNet  Google Scholar 

  12. Fornberg, B., Flyer, N.: A Primer on Radial Basis Functions with Applications to the Geosciences, CBMS-NSF, vol. 87. SIAM, Philadelphia (2015)

    Book  Google Scholar 

  13. Fornberg, B., Piret, C.: Complex Variables and Analytic Functions: An Illustrated Introduction. SIAM, Philadelphia (2020)

    MATH  Google Scholar 

  14. Fornberg, B., Weideman, J. A. C.: A numerical methodology for the Painlevé equations. J. Comput. Phys. 230, 5957–5973 (2011)

    Article  MathSciNet  Google Scholar 

  15. Hinojosa, J. H., Mickus, KL: Hilbert transform of gravity gradient profiles: Special cases of the general gravity-gradient tensor in the Fourier transform domain. Geophysics 67(3), 766–769 (2002)

    Article  Google Scholar 

  16. Huybrechs, D.: Stable high-order quadrature rules with equidistant points. Comput. Appl. Math. 231, 933–947 (2009)

    Article  MathSciNet  Google Scholar 

  17. LeVeque, R. J.: Finite Difference Methods for Ordinary and Partial Differential Equations. SIAM, Philadelphia (2007)

    Book  Google Scholar 

  18. Lyness, J. N., Moler, C. B.: Numerical differentiation of analytic functions. SIAM J. Numer. Anal. 4, 202–210 (1967)

    Article  MathSciNet  Google Scholar 

  19. Lyness, J. N., Sande, G.: Algorithm 413-ENTCAF and ENTCRE: Evaluation of normalized Taylor coefficients of an analytic function. Comm. ACM 14(10), 669–675 (1971)

    Article  Google Scholar 

  20. Richardson, L.F.: On the approximate arithmetical solution by finite differences of physical problems involving differential equations, with an application to the stresses in a masonry dam. Proc. R. Soc. A. 83, 307–357. https://doi.org/10.1098/rspa.1910.0020 (1910)

  21. Trefethen, L. N.: Spectral Methods in MATLAB. SIAM, Philadelphia (2000)

    Book  Google Scholar 

  22. Trefethen, L. N.: Approximation Theory and Approximation Practice, SIAM, Philadelphia. 2013 extended edition (2019)

  23. Trefethen, L. N.: Quantifying the ill-conditioning of analytic continuation. BIT Numer. Math. 60, 901–915 (2020)

    Article  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Bengt Fornberg.

Additional information

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Appendices

Appendix 1: Code examples for the two weights algorithms

Let the task be to determine the weight set for the second derivative (i.e., L = d2/dz2) at the center of a 5 × 5 stencil. The next two sections illustrate how this can be done with the two methods described in Section 2. Comments indicate how to generalize to other node layouts and linear operators.

1.1 Method 1: MATLAB code

figure b

For node spacing h, we replace x = -2,2; by x = (-2,2)⋆h;. This code produces the same matrix as shown below for the Mathematica code, but as floating point numbers. Since the linear system is of Vandermonde type, it is prone to numerical ill-conditioning. In the present test case, using standard double precision, about 4 digits get lost, leading to coefficient errors up to about 10− 12. Since the loss increases rapidly with stencil size, either exact rational or extended precision arithmetic is recommended (available in all common symbolic algebra packages). When using MATLAB, both are available through its symbolic toolbox; the latter also with the Advanpix toolboxFootnote 14.

1.2 Method 2: Mathematica code

The following three Mathematica statements

figure c

compute the FD weights in closed form (with h as before denoting the node spacing). The further statement

figure d

displays this set of weights in a standard matrix format:

figure e

Appendix 2: Stencils of size 5 × 5 for the first four derivatives

$$ f^{\prime}(0)=\frac{1}{h}\left[\begin{array}{ccccc} \frac{1+i}{477360} & \frac{4(-1-i)}{29835} & \frac{i}{1326} & \frac{4(1-i)}{29835} & \frac{-1+i}{477360}\\ \frac{4(-1-i)}{29835} & \frac{8(-1-i)}{351} & \begin{array}{c} \\ \end{array}\frac{-8i}{39}\begin{array}{c} \\ \end{array} & \frac{8(1-i)}{351} & \frac{4(1-i)}{29835}\\ \frac{1}{1326} & \frac{-8}{39} & 0 & \frac{8}{39} & \frac{-1}{1326}\\ \frac{4(-1+i)}{29835} & \frac{8(-1+i)}{351} & \begin{array}{c} \\ \end{array}\frac{8i}{39}\begin{array}{c} \\ \end{array} & \frac{8(1+i)}{351} & \frac{4(1+i)}{29835}\\ \frac{1-i}{477360} & \frac{4(-1+i)}{29835} & \frac{-i}{1326} & \frac{4(1+i)}{29835} & \frac{-1-i}{477360} \end{array}\right]f+O(h^{24}), $$
$$ f^{\prime\prime}(0)=\frac{1}{h^{2}}\left[\begin{array}{ccccc} \frac{-i}{477360} & \frac{8(-1+3i)}{149175} & \frac{1}{1326} & \frac{8(-1-3i)}{149175} & \frac{i}{477360}\\ \frac{8(1+3i)}{149175} & \frac{16i}{351} & \begin{array}{c} \\ \end{array}\frac{-16}{39}\begin{array}{c} \\ \end{array} & \frac{-16i}{351} & \frac{8(1-3i)}{149175}\\ \frac{-1}{1326} & \frac{16}{39} & 0 & \frac{16}{39} & \frac{-1}{1326}\\ \frac{8(1-3i)}{149175} & \frac{-16i}{351} & \begin{array}{c} \\ \end{array}\frac{-16}{39}\begin{array}{c} \\ \end{array} & \frac{16i}{351} & \frac{8(1+3i)}{149175}\\ \frac{i}{477360} & \frac{8(-1-3i)}{149175} & \frac{1}{1326} & \frac{8(-1+3i)}{149175} & \frac{-i}{477360} \end{array}\right]f+O(h^{23}), $$
$$ f^{(3)}(0)=\frac{1}{h^{3}}\left[\begin{array}{ccccc} \frac{-1+i}{636480} & \frac{8(7-i)}{248625} & \frac{-i}{884} & \frac{8(-7-i)}{248625} & \frac{1+i}{636480}\\ \frac{8(1-7i)}{248625} & \frac{8(1-i)}{117} & \begin{array}{c} \\ \end{array}\frac{16i}{13}\begin{array}{c} \\ \end{array} & \frac{8(-1-i)}{117} & \frac{8(-1-7i)}{248625}\\ \frac{1}{884} & \frac{-16}{13} & 0 & \frac{16}{13} & \frac{-1}{884}\\ \frac{8(1+7i)}{248625} & \frac{8(1+i)}{117} & \begin{array}{c} \\ \end{array}\frac{-16i}{13}\begin{array}{c} \\ \end{array} & \frac{8(-1+i)}{117} & \frac{8(-1+7i)}{248625}\\ \frac{-1-i}{636480} & \frac{8(7+i)}{248625} & \frac{i}{884} & \frac{8(-7+i)}{248625} & \frac{1-i}{636480} \end{array}\right]f+O(h^{22}), $$
$$ f^{(4)}(0)=\frac{1}{h^{4}}\left[\begin{array}{ccccc} \frac{1}{318240} & \frac{32(-9-13i)}{1243125} & \frac{-1}{442} & \frac{32(-9+-13i)}{1243125} & \frac{1}{318240}\\ \frac{32(-9+-13i)}{1243125} & \frac{-32}{117} & \begin{array}{c} \\ \end{array}\frac{64}{13}\begin{array}{c} \\ \end{array} & \frac{-32}{117} & \frac{32(-9-13i)}{1243125}\\ \frac{-1}{442} & \frac{64}{13} & \frac{-92937}{5000} & \frac{64}{13} & \frac{-1}{442}\\ \frac{32(-9-13i)}{1243125} & \frac{-32}{117} & \begin{array}{c} \\ \end{array}\frac{64}{13}\begin{array}{c} \\ \end{array} & \frac{-32}{117} & \frac{32(-9+-13i)}{1243125}\\ \frac{1}{318240} & \frac{32(-9+-13i)}{1243125} & \frac{-1}{442} & \frac{32(-9-13i)}{1243125} & \frac{1}{318240} \end{array}\right]f+O(h^{21}). $$

For this stencil size, one can approximate up through f(24)(0) which then becomes first-order accurate.

Appendix 3

Following up on Section 8, we consider again

$$ \phi(z)=\prod\limits_{\eta=1}^{N}(z-z_{\eta})=\prod\limits_{\begin{array}{c} \mu=-n,\ldots,+n\\ \nu=-n,\ldots,+n \end{array}}(z-(\mu+i \nu)), $$

and note that

$$ \phi^{\prime}(z_{k})=\prod\limits_{\begin{array}{c} \eta=1\\ \eta\neq k \end{array}}^{N}(z_{k}-z_{\eta}). $$
(24)

We next refer to Fig. 8, with a schematic illustration in the n = 4 case (with a total of N = (2n +-1)2 = 81 nodes), and μ = 2, ν = 1, i.e., zk = 2 + i (marked by a triangle, in contrast to z = 0 marked by a square). The value for \(\phi ^{\prime }(0)\), according to (24), is obtained by a product over all nodes inside the large solid square (omitting its center node). If the corresponding product for \(\phi ^{\prime }(z_{k})\) had used the nodes inside the dashed square (again omitting the center node), it would have evaluated to the same result. However, it does not, but a calculation for \(\log |\phi ^{\prime }(0)|\) becomes a calculation for \(\log |\phi ^{\prime }(z_{k})|\) if we to it add the sums

$$ S_{1}=\sum\limits_{z_{\eta}\textrm{ in rectangle }1}\log|z_{\eta}|,\qquad S_{2}=\sum\limits_{z_{\eta}\textrm{ in rectangle }2}\log|z_{\eta}| $$

and subtract

$$ S_{3}=\sum\limits_{z_{\eta}\textrm{ in rectangle }3}\log|z_{\eta}|,\qquad S_{4}=\sum\limits_{z_{\eta}\textrm{ in rectangle }4}\log|z_{\eta}|. $$

Each of these four sums is readily estimated to leading order. Along the center line of each of the four narrow rectangles (marked 1, 2, 3, 4 in the figure), we can approximate the sum by suitable use of the integral relation

$$ \begin{array}{@{}rcl@{}} {{\int}_{a}^{b}}\log(x^{2}+y^{2})dx&=&2y\left( \arctan\frac{b}{y}-\arctan\frac{a}{y}\right)+b\left( \log(b^{2}+y^{2})-2\right)\\&&-a\left( \log(a^{2}+y^{2})-2\right) \end{array} $$
Fig. 8
figure 8

Illustration of the node sets used in the estimate of the sums S1,…, S4, as described in Appendix 10

together with multiplying each integral by the width (orthogonal to the center line) of the respective rectangle. After straightforward algebra, this gives

$$ S_{1}+S_{2}-S_{3}-S_{4}=\frac{\pi}{2}(\mu^{2}+\nu^{2})-\frac{1}{2n}(\mu^{2}+\nu^{2})+O\left( \frac{1}{n^{2}}\right), $$
(25)

from with (20) then follows.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Fornberg, B. Finite difference formulas in the complex plane. Numer Algor 90, 1305–1326 (2022). https://doi.org/10.1007/s11075-021-01231-5

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s11075-021-01231-5

Keywords

Mathematics Subject Classification 2010