1 Introduction

In this work we present a new approach to the compression of Dirichlet-to-Neumann (DtN) maps of infinite waveguides with layered inclusions. This approach is inspired by rational approximation techniques from model order reduction (see, e.g., [4]), in this case the RKFIT algorithm for nonlinear rational approximation [9]. As a prototypical problem we consider the infinite finite difference (FD) scheme

$$\begin{aligned} 2h^{-1}\left[ h^{-1}({{\varvec{u}}_1 - {\varvec{u}}_0}) + {\varvec{b}} \right]= & {} (A+c_0 I) {\varvec{u}}_0 \end{aligned}$$
$$\begin{aligned} h^{-1}\left[ h^{-1}({{\varvec{u}}_{j+1} - {\varvec{u}}_j}) - h^{-1}({{\varvec{u}}_{j} - {\varvec{u}}_{j-1}}) \right]= & {} (A+c_j I) {\varvec{u}}_j , \ \ j = 1,2,\ldots \qquad \end{aligned}$$

where either \({\varvec{u}}_0\in \mathbb {C}^N\) or \({\varvec{b}}\in \mathbb {C}^N\) is given, \(A\in \mathbb {C}^{N\times N}\) is Hermitian, \(c_j=0\) for all \(j>L\), and the solution \(\{{\varvec{u}}_j\}_{j=0}^\infty \subset \mathbb {C}^N\) is assumed to be bounded. This problem arises from the FD discretization of the three-dimensional (indefinite) Helmholtz equation

$$\begin{aligned} \nabla ^2 u + (k_\infty ^2 - c(x)) u = 0 \end{aligned}$$

for \((x,y,z)\in [0,+\infty )\times [0,1]\times [0,1]\) with a compactly supported offset function c(x) for the wave number \(k_\infty \) and appropriate boundary conditions. Here, the matrix A corresponds to the discretization of the transverse differential operator \(-\partial _{yy}^2 - \partial _{zz}^2 - k_\infty ^2\) at \(x=0\) and is Hermitian indefinite. The variation of the wave number in the x-direction is modelled by varying coefficients \(c_j\), with the “effective” wave number \(\sqrt{k_\infty ^2-c_j}\) at each grid point. The DtN operator F for (1.1) is defined by the relationship \(F {\varvec{u}}_0={\varvec{b}}.\)

Since (1.1) is a linear recurrence, \(F=f_h(A)\) is a matrix function in A. If \(c_j\equiv 0\), the DtN function for (1.1) at \(x=0\) is \(f_h(\lambda ) = \sqrt{\lambda + (h\lambda /2)^2}\). As \(h\rightarrow 0\) we obtain the DtN function \(f(\lambda ) = \sqrt{\lambda }\) for the continuous problem. In this case, a near-optimal rational approximant to f can be constructed analytically [12, 13, 16]. More precisely, let the eigenvalues of A be contained in the union of two intervals \(K = [a_1,b_1] \cup [a_2,b_2]\) with \(a_1<b_1<0<a_2<b_2\). Then [12] gives an explicit construction of a compound Zolotarev rational function \(r_n^{(Z)}\) of type \((n,n-1)\) such that

$$\begin{aligned} \max _{\lambda \in K} | 1 - r_n^{(Z)}(\lambda )/f(\lambda ) | \asymp \exp \left( - 2\pi ^2n /{\log \left( 256{a_1 b_2}/({a_2 b_1})\right) } \right) \ \text {as} \ n\rightarrow \infty \end{aligned}$$

for sufficiently large interval ratios \(a_1/b_1\) and \(b_2/a_2\). It is also shown in [12] that the convergence factor in (1.2) is optimal. Hence, the approximation error \(\Vert f(A) - r_n^{(Z)}(A) \Vert _2 \le C \max _{\lambda \in K} | 1 - r_n^{(Z)} (\lambda )/f(\lambda ) | \) decays exponentially at the same optimal rate. Interestingly, the continued fraction form of \(r_n^{(Z)}\) gives rise to a geometrically meaningful three-point FD scheme. By “geometrically meaningful” we mean that the complex grid points align on a curve in the complex plane which can be interpreted as a “smooth” deformation of the original x-coordinate axis. This is similar to the celebrated perfectly matched layers (PMLs) which are introduced via complex coordinate stretching [3, 5, 11, 14].

The analytic approach just outlined is essentially limited to DtN functions such as \(\sqrt{\lambda }\) and \(\sqrt{\lambda + (h\lambda /2)^2}\). Here we aim to overcome this limitation by numerically computing a low-order rational approximant \(r_n(A)\approx f_h(A)\) and converting it into a sparse representation in form of a three-point finite difference scheme.Footnote 1 Our approach is applicable even in cases where the DtN map to be approximated is highly irregular due to the presence of scattering poles.

An illustrating example is given in Fig. 1, where the top panels show the amplitude/phase of the solution of a waveguide problem on \([0,+\infty )\times [0,1]\), truncated and discretized by \(300\times 150\) points. The step size is \(h=1/150\) in both coordinate directions. For this problem we have chosen \(k_\infty =14\) and \(c_j = -9^2\) for the grid points \(j=0,1,\ldots ,L=150\). An absorbing boundary condition has been fitted to the right end of the domain to mimic the infinite extension \(x\rightarrow \infty \). The modulus of the associated DtN function \(f_h\) is shown in the bottom of Fig. 1 (solid red curve). This function has several singularities between and close to the eigenvalues of the transverse FD matrix A (the eigenvalue positions are indicated by the black dots). In particular, one eigenvalue \(\lambda _j\approx 50.5\) is extremely close to a singularity of \(f_h\), which can be associated with the near-resonance observed in the left portion of the waveguide. These singularities make it impossible to construct a uniform approximant \(r_n\approx f_h\) over the negative and positive spectral subintervals of A. Nevertheless, the RKFIT approximant \(r_n\) of order \(n=8\), also shown in the bottom of Fig. 1 (dashed blue curve), has a relative accuracy \(\Vert f_h(A) {\varvec{u}}_0 - r_n(A){\varvec{u}}_0\Vert _2 / \Vert f_h(A) {\varvec{u}}_0\Vert _2 \approx 1.4\times 10^{-6}\) for the DtN map. We see that \(r_n\) achieves this high accuracy by being close to \(f_h\) in the vicinity of the eigenvalues of A, but not necessarily in between them. This remarkable spectral adaptation is achieved without requiring a spectral decomposition of A explicitly; RKFIT merely requires matrix-vector products with the DtN map.

Fig. 1
figure 1

A waveguide with varying wave number in the x-direction (piecewise constant over the first 150 grid points and the remaining grid points until infinity). The top row shows the amplitude and phase of the solution, with the position of the coefficient jump highlighted by vertical dashed line. The bottom shows a plot of the exact DtN function \(f_h\) (solid red line) over the spectral interval of the indefinite matrix A. The plot is logarithmic on both axes, with the x-axis showing a negative and positive part of the real axis, glued together by the gray linear part in between. The RKFIT approximant of degree \(n=8\) (dotted blue curve) exhibits spectral adaptation to some of A’s eigenvalues (black dots)

Our RKFIT approach is also applicable when A is non-Hermitian, which may result from absorbing boundary conditions in the transversal plane. We demonstrate in several experiments that the RKFIT-FD grids are exponentially accurate as an approximation to the full FD scheme, with only a small number of grid points required for practical accuracy. As a result of spectral adaptation effects, the Nyquist limit of two grid points per wavelength does not fully apply to RKFIT-FD grids. For the problem in Fig. 1, for example, we computed an RKFIT-FD grid of only \(n=8\) points which accurately (to about six digits of relative accuracy) mimics the response of the full variable-coefficient waveguide discretized by 300 grid points in the x-direction. This is a significant compression of the full grid.

The rest of this paper is structured as follows: in Sect. 2 we derive analytic expressions of DtN maps for constant- and variable-coefficient media. We relate the optimization of these DtN maps to approximation problems. Section 3 establishes a new connection between rational Krylov spaces and FD grids. In Sect. 4 we tailor the RKFIT algorithm to our specific application. Sections 5 and 6 study the convergence behaviour of the algorithm. In Sect. 7 we discuss the numerical results and compare them to the Nyquist limit and other (spectral) discretization schemes. In the “Appendix” we give a rational approximation interpretation of the Nyquist limit and explain why this limit is not necessarily strict for RKFIT-FD grids.

2 From DtN maps to continued fractions and FD grids

There is an intimate connection between FD grids and rational functions. To see this, let us first consider the scalar ODE \(u''(x) = \lambda u(x)\) on \(x\ge 0\) and its FD discretization

$$\begin{aligned} h^{-1}\left[ h^{-1}(u_{j+1}-u_j) - h^{-1}(u_j-u_{j-1})\right] = \lambda u_j, \quad j = 1,2,\ldots , \end{aligned}$$

where \(\lambda \) and \(u_0\) are given constants and we demand that \(u_n\) remains bounded as \(n\rightarrow \infty \). This linear recurrence is a scalar version of (1.1b) with \(c\equiv 0\). It can easily be solved by computing the roots of the characteristic polynomial \(p(t) = (t^2 - (2+h^2\lambda ) t + 1)/h^2\) and choosing the solution \(u_j = ( 1 + {h^2\lambda }/{2} - h\sqrt{\lambda +h^2\lambda ^2/4} )^j \cdot u_0\). Indeed this is the only solution that decays for \(\lambda > 0\). Moreover, this solution is bounded under the conditionFootnote 2\(\lambda \ge -4/h^2\) and unbounded for \(\lambda < -4/h^2\).

We can use the explicit solution \(\{u_j\}\) to extract interesting information about the problem. For example, from the FD relation \( 2h^{-1} \left[ h^{-1}(u_1 - u_0) + b \right] = \lambda u_0\), the scalar version of (1.1a), we obtain an approximation b to the Neumann boundary data \(-u'(x=0)\) for the continuous analogue of the FD scheme. Eliminating \(u_1\) using the above formula, we can directly relate \(u_0\) and b via \(b = \sqrt{ \lambda + {h^2\lambda ^2}/{4}}\, u_0 =: f_h(\lambda ) u_0\). We refer to \(f_h\) as the DtN function or discrete impedance function. By letting \(h\rightarrow \infty \) we recover the DtN relation \(b = \sqrt{\lambda } u_0 =: f(\lambda ) u_0\) and indeed \(b = -u'(0)\) for the continuous solution \(u(x) = \exp (-x\sqrt{\lambda }) u_0\).

Now let us turn to the variable-coefficient problem (1.1) in scalar form:

$$\begin{aligned} 2h^{-1}\left[ h^{-1}({u}_1 - {u}_0) + b \right]= & {} (\lambda +c_0) {u}_0 \end{aligned}$$
$$\begin{aligned} h^{-1}\left[ h^{-1} ({u}_{j+1} - {u}_j) - h^{-1}(u_{j} - u_{j-1}) \right]= & {} (\lambda +c_j) {u}_j , \quad j = 1,2,\ldots .\qquad \end{aligned}$$

By eliminating the grid points with indices \(j>L\) (where \(c_j=0\)) we find the DtN relation \(b/u_0 = f_h(\lambda )\) in continued fraction form

$$\begin{aligned} f_h(\lambda ) = \frac{h (\lambda +c_0)}{2} + \frac{1}{h + \frac{1}{ h (\lambda +c_1) + \frac{1}{h + \cdots + \frac{1}{ h (\lambda +c_L) + \frac{1}{h + \frac{1}{\frac{h\lambda }{2} + \sqrt{\lambda + \frac{h^2 \lambda ^2}{4}}}}}}}}. \end{aligned}$$

In view of the original vector-valued problem (1.1), the role of \(\lambda \) is played by the eigenvalues of the matrix A. When employing a rational approximant \(r_n\approx f_h\) it hence seems reasonable to be accurate on the spectral region of A. For example, if A is diagonalizable as \(A = X \mathrm {diag}(\lambda _1,\lambda _2,\ldots , \lambda _N) X^{-1}\), we have \(\Vert f_h(A) - r_n(A) \Vert _2 \le \Vert X\Vert _2 \Vert X^{-1}\Vert _2 \max _{1\le j \le N} |f_h(\lambda _j) - r_n(\lambda _j) |\). Hence if the condition number \(\kappa (X) = \Vert X\Vert _2 \Vert X^{-1}\Vert _2\) is moderate, we can bound the accuracy of \(r_n(A)\) using a scalar approximation problem on the eigenvalues \(\lambda _j\). The rational approximant \(r_n\) can be viewed as a reduced order model of (2.2) where the spectral parameter \(\lambda \) of the transversal operator is an equivalent of the temporal (Laplace) frequency in linear time invariant dynamical systems (see, e.g., [4]).

3 From FD grids to rational Krylov spaces

The crucial observation for optimizing the rational approximant \(r_n \approx f_h\) of a DtN function, or equivalently its associated FD grid, is that the grid steps do not need to be equispaced, and not even real-valued. Consider the FD scheme

$$\begin{aligned} {\widehat{h}_0}^{-1}\left[ ({u}_1 - {u}_0) + b \right]= & {} \lambda {u}_0 \end{aligned}$$
$$\begin{aligned} {\widehat{h}_j}^{-1}\left[ h_{j+1}^{-1} ({u}_{j+1} - {u}_j) - h_{j}^{-1}({u}_{j} - {u}_{j-1}) \right]= & {} \lambda {u}_j , \quad j = 1,\ldots ,n-1 \end{aligned}$$

with arbitrary complex-valued primal and dual grid steps \(h_j\) and \(\widehat{h}_{j-1}\) (\(j=1,2,\ldots ,n\)), respectively. The continued fraction form of the associated DtN maps, derived in exactly the same manner as for the case of constant h in Sect. 2, is

$$\begin{aligned} r_n(\lambda ) = \widehat{h}_0 \lambda + \frac{1}{h_1 + \frac{1}{\widehat{h}_1 \lambda + \frac{1}{h_2 + \cdots + \frac{1}{\widehat{h}_{n-1} \lambda + \frac{1}{h_n}} }}}. \end{aligned}$$

This is a rational function of type \((n,n-1)\), i.e., a quotient \(p_n/q_{n-1}\) of polynomials of degree n and \(n-1\), respectively. By choosing the free grid steps we can optimize it for our purposes. In particular, we can tune (3.1) so that it implements a rational approximation to any DtN map, even if the associated analytic DtN function \(f_h\) is complicated. To this end, we need a robust method for computing such rational approximants and a numerical conversion into continued fraction form.

The vector form of (3.1) is

$$\begin{aligned} {\widehat{h}_0}^{-1}\left[ h_1^{-1}({\varvec{u}}_1 - {\varvec{u}}_0) + {\varvec{b}} \right]= & {} A {\varvec{u}}_0 \end{aligned}$$
$$\begin{aligned} {\widehat{h}_j}^{-1}\left[ h_{j+1}^{-1} ({\varvec{u}}_{j+1} - {\varvec{u}}_j) - h_{j}^{-1}({\varvec{u}}_{j} - {\varvec{u}}_{j-1}) \right]= & {} A {\varvec{u}}_j , \quad j = 1,\ldots ,n-1.\qquad \end{aligned}$$

Again, \({\varvec{b}} = r_n(A){\varvec{u}}_0\) with a rational function \(r_n=p_n/q_{n-1}\) whose continued fraction form (3.2) involves the grid steps \(h_j\) and \(\widehat{h}_{j-1}\). The vectors \({\varvec{u}}_j\) and \({\varvec{b}}= r_n(A) {\varvec{u}}_0\) satisfy a rational Krylov decomposition

$$\begin{aligned} A U_{n+1}\underline{\widetilde{K}_n} = U_{n+1} \underline{\widetilde{H}_n}, \end{aligned}$$

where \(U_{n+1} = [ \, r_n(A){\varvec{u}}_0\, |\, {\varvec{u}}_{0}\, |\, {\varvec{u}}_{1}\, |\, \cdots \, |\, {\varvec{u}}_{n-1}\, ]\in \mathbb {C}^{N\times (n+1)}\) and \(\underline{\widetilde{K}_n}, \underline{\widetilde{H}_n}\in \mathbb {C}^{(n+1)\times n}\) are

$$\begin{aligned} \underline{\widetilde{K}_n} = \begin{bmatrix} 0 &{} \\ \widehat{h}_0 &{} &{} &{} \\ &{} \widehat{h}_1 &{} &{} \\ &{} &{} \ddots &{} \\ &{} &{} &{} \widehat{h}_{n-1} \\ \end{bmatrix}, \ \underline{\widetilde{H}_n} = \begin{bmatrix} 1 &{} \\ { -h_1^{-1}} &{} { h_1^{-1}} &{} &{} \\ { h_1^{-1}} &{} { -h_1^{-1} - h_2^{-1}} &{} \ddots &{} \\ &{} \ddots &{} \ddots &{} h_{n-1}^{-1} \\ &{} &{} h_{n-1}^{-1} &{} -h_{n-1}^{-1} - h_n^{-1} \\ \end{bmatrix}. \end{aligned}$$

The entries in \((\underline{\widetilde{H}_n},\underline{\widetilde{K}_n})\) encode the recursion coefficients in (3.1) and the columns of \(U_{n+1}\) all correspond to rational functions in A multiplied by the vector \({\varvec{u}}_0\). More precisely,

$$\begin{aligned} \mathrm {colspan}(U_{n+1}) = q_{n-1}(A)^{-1} \mathrm {span} \{ {\varvec{u}}_0, A{\varvec{u}}_0, \ldots , A^n {\varvec{u}}_0 \} \end{aligned}$$

for some denominator polynomial \(q_{n-1}\) of degree at most \(n-1\) and with no roots at any of A’s eigenvalues. Such a space is also known as a rational Krylov space [18]. In the next section we will show how to generate decompositions of the form (3.4) numerically and how to interpret them as FD grids.

4 The RKFIT approach

Assume that \(F,A \in \mathbb {C}^{N\times N}\) are given matrices and \({\varvec{v}}\in \mathbb {C}^N\) with \(\Vert {\varvec{v}} \Vert _2=1\). Our aim is to find a rational approximant \(r_n(A){\varvec{v}}\) such that

$$\begin{aligned} \Vert F{\varvec{v}} - r_n(A){\varvec{v}} \Vert _2 \rightarrow \min . \end{aligned}$$

For the purpose of this paper, F is the linear DtN map and the sought rational function \(r_n = p_{n}/q_{n-1}\) is of type \((n,n-1)\). As (4.1) is a nonconvex optimization problem it may have many solutions, exactly one solution, or no solution at all. However, this difficulty has not prevented the development of algorithms for the (approximate) solution of (4.1); see [9] for a discussion of various algorithms. The RKFIT algorithm [7, 9] is particularly suited for this task and in this section we shall briefly review it and adapt it to our application.

4.1 Search and target spaces

Given a set of poles \(\xi _1,\xi _2,\ldots ,\xi _{n-1}\in \mathbb {C}\) and an associated nodal polynomial \(q_{n-1}(\lambda ) = \prod _{j=1}^{n-1} (\lambda - \xi _j)\), RKFIT makes use of two spaces, namely an n-dimensional search space \(\mathscr {V}_{n}\) defined as \(\mathscr {V}_{n} := q_{n-1}(A)^{-1} \mathscr {K}_{n}(A,{\varvec{v}})\), and an \((n+1)\)-dimensional target space \(\mathscr {W}_{n+1}\) defined as \(\mathscr {W}_{n+1} := q_{n-1}(A)^{-1} \mathscr {K}_{n+1}(A,{\varvec{v}})\). Here, \(\mathscr {K}_{j}(A,{\varvec{v}}) = \mathrm {span} \{ {\varvec{v}},A{\varvec{v}},\) \(\ldots ,A^{j-1}{\varvec{v}} \}\) is the standard (polynomial) Krylov space of dimension j for the matrix A and starting vector \({\varvec{v}}\). Let \(V_{n}\in \mathbb {C}^{N\times n}\) and \(W_{n+1}\in \mathbb {C}^{N\times (n+1)}\) be orthonormal bases for \(\mathscr {V}_{n}\) and \(\mathscr {W}_{n+1}\), respectively.

The space \(\mathscr {V}_{n}\) is a rational Krylov space with starting vector \({\varvec{v}}\) and the poles \(\xi _1,\ldots ,\xi _{n-1}\), i.e., a linear space of type \((n-1,n-1)\) rational functions \((p_j/q_{n-1})(A){\varvec{v}}\), all sharing the same denominator \(q_{n-1}\). As a consequence, we can arrange the columns of \(V_{n}\) such that \(V_{n} {\varvec{e}}_1 = {\varvec{v}}\) and a rational Krylov decomposition

$$\begin{aligned} A V_{n} \underline{K_{n-1}} = V_{n} \underline{H_{n-1}} \end{aligned}$$

is satisfied. The existence of such a decomposition under the assumption that \(\mathscr {V}_{n}\) is a rational Krylov space is shown in [7,  Thm. 2.5]. For a given sequence of poles \(\xi _1,\ldots ,\xi _{n-1}\), decompositions of this form are computed by Ruhe’s rational Krylov sequence (RKS) algorithm [18,  Section 2] and its variant described in [8,  Algorithm 2.1]. Here, \((\underline{H_{n-1}},\underline{K_{n-1}})\) is an unreduced upper Hessenberg pair of size \(n\times (n-1)\), i.e., both \(\underline{H_{n-1}}\) and \(\underline{K_{n-1}}\) are upper Hessenberg matrices which do not share a common zero element on the subdiagonal. The following result, established in [7,  Thm. 2.5], relates the generalized eigenvalues of the lower \((n-1)\times (n-1)\) submatrices of \((\underline{H_{n-1}},\underline{K_{n-1}})\), the poles of the rational Krylov space, and its starting vector.

Theorem 4.1

The generalized eigenvalues of the lower \((n-1)\times (n-1)\) submatrices of \((\underline{H_{n-1}},\underline{K_{n-1}})\) of (4.2) are the poles \(\xi _1,\ldots ,\xi _{n-1}\) of the rational Krylov space \(\mathscr {V}_{n}\) with starting vector \({\varvec{v}}\).

Conversely, let a decomposition \(A\widehat{V}_n \underline{\widehat{K}_{n-1}} = \widehat{V}_{n} \underline{\widehat{H}_{n-1}}\) with \(\widehat{V}_n\in \mathbb {C}^{N\times n}\) of full column rank and an unreduced upper Hessenberg pair \((\underline{\widehat{H}_{n-1}},\underline{\widehat{K}_{n-1}})\) be given. Assume further that none of the generalized eigenvalues \(\widehat{\xi }_j\) of the lower \((n-1)\times (n-1)\) submatrices of \((\underline{\widehat{H}_{n-1}},\underline{\widehat{K}_{n-1}})\) coincides with an eigenvalue of A. Then the columns of \(\widehat{V}_n\) form a basis for a rational Krylov space with starting vector \(\widehat{V}_n{\varvec{e}}_1\) and poles \(\widehat{\xi }_j\).

4.2 Pole relocation and projection step

The main component of RKFIT is a pole relocation step based on Theorem 4.1. Assume that a guess for the denominator polynomial \(q_{n-1}\) is available and orthonormal bases \(V_{n}\) and \(W_{n+1}\) for the spaces \(\mathscr {V}_{n}\) and \(\mathscr {W}_{n+1}\) have been computed. Then we can identify a vector \(\widehat{{\varvec{v}}}\in \mathscr {V}_n\), \(\Vert {\widehat{{\varvec{v}}}}\Vert _2 = 1\), such that \(F{\widehat{{\varvec{v}}}}\) is best approximated by some vector in \(\mathscr {W}_{n+1}\). More precisely, we can find a coefficient vector \({\varvec{c}}_n\in \mathbb {C}^n\), \(\Vert {\varvec{c}}_n\Vert _2=1\), such that \(\Vert (I_N - W_{n+1}W_{n+1}^*)F V_n {\varvec{c}}_n \Vert _2 \rightarrow \min \). The vector \({\varvec{c}}_n\) is given as a right singular vector of \((I_N - W_{n+1}W_{n+1}^*)F V_n\) corresponding to a smallest singular value.

Assume that a “sufficiently good” denominator \(q_{n-1}\) of \(r_n = p_n/q_{n-1}\) has been found. Then the problem of finding the numerator \(p_{n}\) such that \(\Vert F{\varvec{v}} - r_n(A){\varvec{v}} \Vert _2\) is minimal becomes a linear one. Indeed, the vector \(r_n(A){\varvec{v}} := W_{n+1} W_{n+1}^* F {\varvec{v}}\) corresponds to the orthogonal projection of \(F{\varvec{v}}\) onto \(\mathscr {W}_{n+1}\) and its representation in the rational Krylov basis \(W_{n+1}\) is

$$\begin{aligned} r_n(A){\varvec{v}} = W_{n+1} {\varvec{c}}_{n+1}, \quad \text {where} \ \ \ {\varvec{c}}_{n+1} := W_{n+1}^* F {\varvec{v}}. \end{aligned}$$

The pseudocode for a single RKFIT iteration is given in Algorithm 4.1. A MATLAB implementation is contained in the Rational Krylov Toolbox [6] which is available online at http://rktoolbox.org.

figure a

4.3 Conversion to continued fraction form

Similarly to what we did in (4.2), we can arrange the columns of \(W_{n+1}\) so that \(W_{n+1} {\varvec{e}}_1 = {\varvec{v}}\) and a rational Krylov decomposition

$$\begin{aligned} A W_{n+1} \underline{K_{n}} = W_{n+1} \underline{H_{n}} \end{aligned}$$

is satisfied, where \((\underline{H_{n}},\underline{K_{n}})\) is an unreduced upper Hessenberg pair of size \((n+1)\times n\). Indeed, we have \(\mathscr {V}_n \subset \mathscr {W}_{n+1}\) and \(\mathscr {W}_{n+1}\) is a rational Krylov space with starting vector \({\varvec{v}}\), finite poles \(\xi _1,\ldots ,\xi _{n-1}\), and a formal additional “pole” at \(\infty \).

Our aim is to transform the decomposition (4.4) so that it can be identified with (3.4) when \({\varvec{u}}_0 = {\varvec{v}}\). This transformation should not alter the space \(\mathscr {W}_{n+1}\) but merely transform the basis \(W_{n+1}\) into the continued fraction basis \(U_{n+1}\) and the pair \((\underline{H_n},\underline{K_n})\) into the tridiagonal-and-diagonal form of (3.5).

First we transform (4.4) so that \(r_n(A){\varvec{v}}\) defined in (4.3) becomes the first vector in the rational Krylov basis, and \({\varvec{v}}\) the second. To this end, we define the transformation matrix \(X = [ \, {\varvec{c}}_{n+1}\, |\, {\varvec{e}}_1\, |\, {\varvec{x}}_3\, |\, \cdots \, \, {\varvec{x}}_{n+1} ] \in \mathbb {C}^{(n+1)\times (n+1)}\) with the columns \({\varvec{x}}_3,\ldots ,{\varvec{x}}_{n+1}\) chosen freely but so that X is invertible, and rewrite (4.4) by inserting \(X X^{-1}\):

$$\begin{aligned} A W_{n+1}^{(0)} \underline{K_n^{(0)}} = W_{n+1}^{(0)} \underline{H_n^{(0)}}, \end{aligned}$$

where \(W_{n+1}^{(0)} = W_{n+1} X\), \(\underline{K_n^{(0)}} = X^{-1} \underline{K_n}\) and \(\underline{H_n^{(0)}} = X^{-1} \underline{H_n}\). By construction, the transformed rational Krylov basis \(W_{n+1}^{(0)}\) is of the form \(W_{n+1}^{(0)} = \big [ \, r_n(A){\varvec{v}} \, |\, {\varvec{v}} \, | * \, | \, \cdots \, | \, *\, \big ]\in \mathbb {C}^{N\times (n+1)}\). The transformation to (4.5) has potentially destroyed the upper Hessenberg structure of the decomposition and \((\underline{H_n^{(0)}},\underline{K_n^{(0)}})\) generally is a dense \((n+1)\times n\) matrix pair. Here is a pictorial view of decomposition (4.5) for the case \(n=4\):

$$\begin{aligned} A W_{n+1}^{(0)} \begin{bmatrix} * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ \end{bmatrix} = W_{n+1}^{(0)} \begin{bmatrix} * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ \end{bmatrix}. \end{aligned}$$

We now transform \((\underline{H_n^{(0)}},\underline{K_n^{(0)}})\) into tridiagonal-and-diagonal form by successive right and left multiplication, giving rise to pairs \((\underline{H_n^{(j)}},\underline{K_n^{(j)}})\) (\(j=1,2,\ldots ,5\)) all corresponding to the same rational Krylov space \(\mathscr {W}_{n+1}\) and all without the two leading vectors in \(W_{n+1}^{(0)}\) being altered. More precisely, the allowed transformations are:

  • right-multiplication of the pair by any invertible matrix \(R\in \mathbb {C}^{n\times n}\),

  • left-multiplication of the pair by an invertible matrix \(L\in \mathbb {C}^{(n+1)\times (n+1)}\), the first two columns of which are \([\, {\varvec{e}}_1\, |\, {\varvec{e}}_2\, ]\). This ensures that inserting \(L^{-1}L\) into the decomposition will not alter the leading two vectors \([\, r_n(A){\varvec{v}}\, |\, {\varvec{v}} \, ]\) in the rational Krylov basis.

Here are the transformations we perform:

  1. 1.

    We right-multiply the pair \((\underline{H_n^{(0)}},\underline{K_n^{(0)}})\) by the inverse of the lower \(n\times n\) part of \(\underline{K_n^{(0)}}\), giving rise to \((\underline{H_n^{(1)}},\underline{K_n^{(1)}})\) (we now only show a pictorial view of the transformed pairs):

    $$\begin{aligned} A W_{n+1}^{(1)} \begin{bmatrix} {\small 0} &{} * &{} * &{} * \\ {\small 1} &{} &{} &{} \\ &{} {\small 1} &{} &{} \\ &{} &{} {\small 1} &{} \\ &{} &{} &{} {\small 1} \\ \end{bmatrix} = W_{n+1}^{(1)} \begin{bmatrix} * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ \end{bmatrix}. \end{aligned}$$

    The Krylov basis matrix \(W_{n+1}^{(1)} = W_{n+1}^{(0)} = [ \, r_n(A){\varvec{v}}\, | \, {\varvec{v}} \, |\, * \, | \, \cdots \, | \, *\, ]\) has not changed. The (1, 1) element of the transformed matrix \(\underline{K_n^{(1)}} = [ k_{ij}^{(1)} ]\) is automatically zero because the decomposition states that the linear combination \(k_{11}^{(1)} Ar_n(A){\varvec{v}} + k_{21}^{(1)} {\varvec{v}}\) is in the column span of \(W_{n+1}^{(1)}\), a space of type \((n,n-1)\) rational functions. This linear combination is a type \((n+1,n-1)\) rational function unless \(k_{11}=0\).

  2. 2.

    We left-multiply the pairs to zero the first row of \(\underline{K_n^{(1)}}\) completely. This can be done by adding multiples of the 3rd, 4th, ..., \((n+1)\)th row to the first. As a result we obtain

    $$\begin{aligned} A W_{n+1}^{(2)} \begin{bmatrix} {\small 0} &{} &{} &{} \\ {\small 1} &{} &{} &{} \\ &{} {\small 1} &{} &{} \\ &{} &{} {\small 1} &{} \\ &{} &{} &{} {\small 1} \\ \end{bmatrix} = W_{n+1}^{(2)} \begin{bmatrix} * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ \end{bmatrix}. \end{aligned}$$

    This left-multiplication does not affect the leading two columns of the Krylov basis, hence \(W_{n+1}^{(2)}\) is still of the form \(W_{n+1}^{(2)} = [ \, r_n(A){\varvec{v}}\, | \, {\varvec{v}} \, |\, * \, | \, \cdots \, | \, *\, ]\).

  3. 3.

    We right-multiply the pair to zero all elements in the first row of \(\underline{H_n^{(2)}}\) except the (1, 1) entry, which we can assume to be nonzero (see Remark 4.1). This can be done by adding multiples of the first column to the 2nd, 3rd, ..., nth column. As a result we have

    $$\begin{aligned} A W_{n+1}^{(3)} \begin{bmatrix} {\small 0} &{} &{} &{} \\ {\small 1} &{} * &{} * &{} * \\ &{} {\small 1} &{} &{} \\ &{} &{} {\small 1} &{} \\ &{} &{} &{} {\small 1} \\ \end{bmatrix} = W_{n+1}^{(3)} \begin{bmatrix} * &{} &{} &{} \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ \end{bmatrix}. \end{aligned}$$

    Again, this right-multiplication has not affected \(W_{n+1}^{(3)}=W_{n+1}^{(2)}\).

  4. 4.

    With a further left-multiplication, adding multiples of the 3rd, 4th,...,\((n+1)\)st row to the second row, we can zero all the entries in the second row of \(\underline{K_n^{(3)}}\), except the entry in the (2, 1) position:

    $$\begin{aligned} A W_{n+1}^{(4)} \begin{bmatrix} {\small 0} &{} &{} &{} \\ {\small 1} &{} &{} &{} \\ &{} {\small 1} &{} &{} \\ &{} &{} {\small 1} &{} \\ &{} &{} &{} {\small 1} \\ \end{bmatrix} = W_{n+1}^{(4)} \begin{bmatrix} * &{} &{} &{} \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ * &{} * &{} * &{} * \\ \end{bmatrix}. \end{aligned}$$

    Note that \(\underline{H_n^{(4)}}\) still has zero entries in its first row. Also, \(W_{n+1}^{(4)}\) is still of the form \(W_{n+1}^{(4)} = [ \, r_n(A){\varvec{v}}\, | \, {\varvec{v}} \, |\, * \, | \, \cdots \, | \, *\, ]\).

  5. 5.

    We apply the two-sided Lanczos algorithm with the lower \(n\times n\) part of \(\underline{H_n^{(4)}}\), using \({\varvec{e}}_1\) as the left and right starting vector. This produces biorthogonal matrices \(Z_L,Z_R\in \mathbb {C}^{n\times n}\), \(Z_L^H Z_R=I_n\). Left-multiplying the decomposition with \(\mathrm {blkdiag}(1,Z_L^H)\) and right-multiplication with \(Z_R\) results in the demanded structure:

    $$\begin{aligned} A W_{n+1}^{(5)} \begin{bmatrix} {\small 0} &{} &{} &{} \\ {\small 1} &{} &{} &{} \\ &{} {\small 1} &{} &{} \\ &{} &{} {\small 1} &{} \\ &{} &{} &{} {\small 1} \\ \end{bmatrix} = W_{n+1}^{(5)} \begin{bmatrix} * &{} &{} &{} \\ * &{} * &{} &{} \\ * &{} * &{} * &{} \\ &{} * &{} * &{} * \\ &{} &{} * &{} * \\ \end{bmatrix}. \end{aligned}$$
  6. 6.

    Finally, let the nonzero entries of \(\underline{H_n^{(5)}}\) be denoted by \(\eta _{i,j}\) (\(1\le j\le n\), \(j\le i\le j+2\)), then we aim to scale these entries so that they are matched with those of the matrix \(\underline{\widetilde{H}_n}\) in (3.5). This can be achieved by left multiplication of the pair with \(L=\mathrm {diag}(1,1,\ell _3,\ldots ,\ell _{n+1})\in \mathbb {C}^{(n+1)\times (n+1)}\) and right multiplication with \(R=\mathrm {diag}(\rho _1,\rho _2,\ldots ,\rho _n)\in \mathbb {C}^{n\times n}\). The diagonal entries of L and R are found by equating \(\underline{\widetilde{H}_n}\) in (3.5) and \(L \underline{H_n^{(5)}} R\), starting from the (1, 1) entry and going down columnwise. We obtain \(r_1 = 1/\eta _{1,1}\), \(h_1 = -1/(\eta _{2,1} \rho _1)\), \(\ell _3 = 1/(\eta _{3,1} h_1 \rho _1)\), and for \(j=2,3,\ldots \) \(r_j = 1/( \ell _j \eta _{j,j} h_{j-1})\), \(h_j = -1/(1/h_{j-1} + \ell _{j+1} \eta _{j+1,j} \rho _j)\), \(\ell _{j+2} = 1/(\eta _{j+2,j} h_j \rho _j)\). The diagonal entries of \(\underline{\widetilde{K}_n}\) in (3.5) satisfy \(\widehat{h}_{j-1} = \ell _{j+1} \rho _j\), \(j = 1,\ldots ,n\), and thus the pair has been transformed exactly into the form (3.5).

The above six-step procedure converts the RKFIT approximant \(r_n\) into continued fraction form and hence allows its interpretation as an FD scheme. This scheme is referred to as an RKFIT-FD grid. Note that all transformations only act on small matrices of size \((n+1)\times n\) and the computation of the tall skinny matrices \(W_{n+1}^{(j)}\) is not required if one only needs the continued fraction parameters. We have extended the Rational Krylov Toolbox by the contfrac method, which implements the conversion of an RKFUN, the fundamental data type to represent and work with rational functions \(r_n\), into continued fraction form following the above transformations. Numerically, these transformations may be ill conditioned and the use of multiple precision arithmetic is recommended. The toolbox supports MATLAB’s Variable Precision Arithmetic and the Advanpix Multiprecision Toolbox [1].

Remark 4.1

In Step 3 we have assumed that the (1, 1) element of \(\underline{H_n^{(2)}}\) is nonzero. This assumption is always satisfied: assuming to the contrary that the (1, 1) element of \(\underline{H_n^{(2)}}\) vanishes, the first column of (4.7) reads \(A{\varvec{v}} = W_{n+2}^{(2)} [0,*,\ldots ,*]^T\). This is a contradiction as the left-hand side of this equation is a superdiagonal rational function in A times \({\varvec{v}}\), whereas the trailing n columns of \(W_{n+1}^{(2)}\) can be taken to be a basis for \(\mathscr {V}_n\subset \mathscr {W}_{n+1}\), which only contains diagonal (and subdiagonal) rational functions in A times \({\varvec{v}}\) (provided that all poles \(\xi _1,\ldots ,\xi _{n-1}\) are finite).

Remark 4.2

In Step 5 we have assumed that the lower \(n\times n\) part of \(\underline{H_n^{(4)}}\) can be tridiagonalized by the two-sided Lanczos algorithm. While this conversion can potentially fail, we conjecture that if \(r_n\) admits a continued fraction form (3.2) then such an unlucky breakdown cannot occur. (The conditions for the rational function \((r_n(\lambda ) - \widehat{h}_0 \lambda )\) to posses this so-called Stieltjes continued fraction form [19] are reviewed in [15]; see Theorem 1.39 therein.) Even if our conjecture was false, the starting vector \({\varvec{v}}\) will typically be chosen at random in our application. So if an unlucky breakdown occurs, trying again with another vector \({\varvec{v}}\) would easily solve the problem. We have not encountered any unlucky breakdowns in our experiments.

5 Numerical tests: constant-coefficient case

The nonlinear rational least squares problem (4.1) is nonconvex and there is no guarantee that a minimizing solution exists, nor that such a solution would be unique. As a consequence of these theoretical difficulties and due to the nonlinear nature of RKFIT’s pole relocation procedure, a comprehensive convergence analysis seems currently intractable. (An exception is [9,  Corollary 3.2], which states that in exact arithmetic RKFIT converges within a single iteration if F itself is a rational matrix function of appropriate type.) However, for some special cases we can compare the RKFIT approximants to analytically constructed near-best approximants. Here we provide such comparisons to the compound Zolotarev approach in [12] and the approximants studied by Newman and Vjacheslavov [17,  Section 4].

Throughout this section we assume that A is Hermitian with eigenvalues \(\lambda _1\le \lambda _2\le \cdots \le \lambda _N\). In our discussion of available convergence bounds we will usually focus on the function \(f(\lambda )=\sqrt{\lambda }\), however, as has been argued in [12,  Section 5.1], it is possible to obtain similar bounds for the discrete impedance function \(f_h(\lambda ) = \sqrt{\lambda + (h\lambda /2)^2}\). Some of our numerical experiments will be for the latter function, illustrating that the convergence behavior is indeed similar to that for the former.

5.1 Two-interval approximation with coarse spectrum

Our first test concerns the approximation of \(F = f_h(A)\), \(f_h(\lambda ) = \sqrt{\lambda +(h\lambda /2)^2}\), where A is a nonsingular indefinite Hermitian matrix with relatively large gaps between neighboring eigenvalues. We recall the convergence result (1.2) from the introduction, which states that the geometric convergence factor is governed by the ratios of the spectral subintervals \([a_1,b_1]\) and \([a_2,b_2]\), \(a_1<b_1<0<a_2<b_2\).

Example 5.1

In Fig. 2 (top left) we show the relative errors \(\Vert F{\varvec{u}}_0 - r_n(A){\varvec{u}}_0\Vert _2/\) \(\Vert F{\varvec{u}}_0\Vert _2\) of the type \((n,n-1)\) rational functions obtained by RKFIT (dashed red curve) and the two-interval Zolotarev approach (dotted blue) for varying degrees \(n=1,2,\ldots ,25\). Here the matrix A is defined as \(A = L/h^2 - k_\infty ^2 I\in \mathbb {R}^{N\times N}\), where \(N=150\), \(h=1/N\), \(k_\infty =15\), and

$$\begin{aligned} L = \small \begin{bmatrix} 1 &{} -1 \\ -1 &{} 2 &{} -1 \\ &{} \ddots &{} \ddots &{} \ddots \\ &{} &{} -1 &{} 2 &{} -1 \\ &{} &{} &{} -1 &{} 1 \end{bmatrix}. \end{aligned}$$

The matrix L corresponds to a scaled FD discretization of the 1D Laplace operator with homogeneous Neumann boundary conditions. The spectral subintervals of A are \([a_1,b_1] \approx [-225, -67.2]\) and \([a_2,b_2] \approx [21.5, 8.98\times 10^4]\). The vector \({\varvec{u}}_0\in \mathbb {R}^N\) is chosen at random with normally distributed entries. To compute the RKFIT approximant \(r_n\) we have used another random training vector \({\varvec{v}}\) with normally distributed entries. The corresponding errors \(\Vert F{\varvec{v}} - r_n(A){\varvec{v}}\Vert _2/\Vert F{\varvec{v}}\Vert _2\) together with the number of required RKFIT iterations are also shown in the plot (solid red curve). For all degrees n at most 5 RKFIT iterations where required until stagnation occurred. Note that the two RKFIT convergence curves (for the vectors \({\varvec{u}}_0\) and \({\varvec{v}}\)) are very close together, indicating that the random choice for the training vector does not affect much the computed RKFIT approximant. Note further that the RKFIT convergence follows the geometric rate predicted by (1.2) (dotted black curve) very closely initially (up to a degree \(n\approx 10\)), but then the convergence becomes superlinear. This convergence acceleration is due to the spectral adaptation of the RKFIT approximant.

The spectral adaptation is illustrated in the graph on the top right of Fig. 2, which plots the error curve \(|f_h(\lambda ) - r_{10}(\lambda )|\) of the RKFIT approximant \(r_{10}\) (solid red curve) over the spectral interval of A, together with the attained values at the eigenvalues of A (red crosses). In particular, close to \(\lambda =0\), there are two eigenvalues at which the error curve attains a relatively small value in comparison to the other eigenvalues farther away (meaning that \(r_n\) interpolates \(f_h\) nearby). These eigenvalues have started to become “deflated” by RKFIT, effectively shrinking the spectral subintervals \([a_1,b_1]\) and \([a_2,b_2]\), and thereby leading to the observed superlinear convergence.

In the bottom of Fig. 2 we show the poles and residues of the RKFIT approximant \(r_{10}\) (left) and the associated continued fraction parameters (right), giving rise to the RKFIT-FD grid. All the involved quantities have been computed using the new contfrac method in the Rational Krylov Toolbox.

Fig. 2
figure 2

Top: Accuracy comparison of RKFIT and Zolotarev approximants for a shifted 1D Laplacian which has a rather coarse spectrum, hence resulting in superlinear RKFIT convergence. The DtN function is \(f_h(\lambda )=\sqrt{\lambda + (h\lambda /2)^2}\). The small numbers on the solid red convergence curve on the left indicate the number of required RKFIT iterations. Bottom: The poles and residues of the RKFIT approximant \(r_{10}\) (left) and the associated continued fraction parameters (right)

5.2 Two-interval approximation with dense spectrum

The superlinear convergence effects observed in the previous example should disappear when the spectrum of A is dense enough so that, for the order n under consideration, no eigenvalues of A are deflated by interpolation nodes of \(r_n\). The next example demonstrates this.

Example 5.2

In Fig. 3 we show the relative errors \(\Vert F{\varvec{u}}_0 - r_n(A){\varvec{u}}_0\Vert _2/\Vert F{\varvec{u}}_0\Vert _2\) of the type \((n,n-1)\) rational functions obtained by RKFIT and the Zolotarev approach for varying degrees \(n=1,2,\ldots ,25\). Now the matrix A corresponds to a shifted 2D Laplacian \(A = (L\otimes L)/h^2 - k_\infty ^2 I\in \mathbb {R}^{N\times N}\) with \(N=150^2\), \(h=1/150\), \(k_\infty =15\), and with L defined in (5.1). The special structure of L (and A) allows for the use of the 2D discrete cosine transform for computing \(F=f_h(A)\). The spectral subintervals of A are \([a_1,b_1] \approx [-225, -27.7]\) and \([a_2,b_2] \approx [21.5, 1.80\times 10^5]\). The vector \({\varvec{u}}_0\in \mathbb {R}^{N}\) is chosen at random with normally distributed entries. We also show the relative error of the RKFIT approximant \(r_n(A){\varvec{v}}\) with another randomly chosen training vector \({\varvec{v}}\), and the number of required RKFIT iterations. As in the previous example there is no big difference in accuracy when evaluating the RKFIT approximant for \({\varvec{u}}_0\) or \({\varvec{v}}\), however, the number of required RKFIT iterations is slightly higher in this example. As the eigenvalues of the matrix A are relatively dense in its spectral interval, we now observe that no spectral adaptation takes place and both the RKFIT and the Zolotarev approximants converge at the rate predicted by (1.2).

In the bottom of Fig. 3 we show the grid vectors \({\varvec{u}}_j\) satisfying the FD relation (3.3) for \(n=10\), with the RKFIT-FD grid parameters \(h_j\) and \(\widehat{h}_{j-1}\) (\(j=0,1,\ldots ,10)\) extracted from \(r_{10}\). The entries of \({\varvec{u}}_j\) are complex-valued, hence we show the \(\log _{10}\) of the amplitude and phase separately. Note how the amplitude decays very quickly as the random signal travels further to the right in the grid, illustrating the good absorption property of this grid.

Fig. 3
figure 3

Top: Comparison of RKFIT and Zolotarev approximants for a shifted 2D Laplacian. Bottom: The \(\log _{10}\) of the amplitude and phase of the grid vectors \({\varvec{u}}_j\) \((j=0,1,\ldots ,n=10)\). Qualitatively, the poles and residues and the complex grid steps for the associated RKFIT approximant \(r_{10}\) look similar to those in Fig. 2 and are therefore omitted

5.3 Approximation on an indefinite interval

In order to remove the spectral gap \([b_1,a_2]\) from which the previous two examples benefited, we now consider the approximation on an indefinite interval.

Example 5.3

We approximate \(f(\lambda ) = \sqrt{\lambda }\) on the indefinite interval \([a_1,b_2] = [-225,\) \(1.80\times 10^5]\). Note that \([a_1,b_2]\) is the same as in the previous Example 5.2, but without the spectral gap about zero. This problem is of interest as, in the variable-coefficient case, one cannot easily exploit a spectral gap between the eigenvalues of A which are closest to zero. This is because a varying coefficient c(x) can be thought of as a variable shift of the eigenvalues of A; hence an eigenvalue-free interval \([b_1,a_2]\) may not always exist.

To mimic continuous approximation on an interval, we use for A a surrogate diagonal matrix of size \(N=200\) having 100 logspaced eigenvalues in \([a_1,-10^{-16}]\) and \([10^{-16},b_2]\), respectively. The training vector \({\varvec{v}}\) is chosen as \([1,1,\ldots ,1]^T\). We run RKFIT for degrees \(n=1,2,\ldots ,25\). The relative error of the RKFIT approximants \(\Vert F{\varvec{v}} - r_n(A){\varvec{v}}\Vert _2/\Vert F{\varvec{v}}\Vert _2\) seems to reduce like \(\exp (-\pi \sqrt{n})\); see Fig. 4 (left).

We also compare RKFIT to a two-interval Remez-type approximant obtained by using the interpolation nodes of numerically computed best approximants to \(\sqrt{\lambda }\) on [0, 1], scaling them appropriately, and unifying them for the intervals \([a_1,0]\) and \([0,b_2]\). The number of interpolation nodes on both intervals is balanced so that the resulting error curve is closest to being equioscillatory on the whole of \([a_1,b_2]\). Again the error of the so-obtained Remez-type approximant seems to reduce like \(\exp (-\pi \sqrt{n})\).

Remark 5.1

The uniform rational approximation of \(\sqrt{\lambda }\) on a semi-definite interval \([0,b_2]\) has been studied by Newman and Vjacheslavov. It is known that the error reduces like \(\exp (-\pi \sqrt{2n})\) with the degree n; see [17,  Section 4]. Based on the observations in Fig. 4 we conjecture that the error of the best rational approximant to \(\sqrt{\lambda }\) on an indefinite interval \([a_1,b_2]\) reduces like \(\exp (-\pi \sqrt{n})\).

Fig. 4
figure 4

RKFIT approximation of \(f(\lambda ) = \sqrt{\lambda }\) on an indefinite interval \([a_1,b_2]\), \(a_1<0<b_2\), compared to a two-interval Remez-type approximant. Qualitatively, the poles/residues and the complex grid steps associated with \(r_{10}\) look similar to those in Fig. 2 and are therefore omitted

6 Numerical tests: variable-coefficient case

We now consider a variable-coefficient function c motivated by a geophysical seismic exploration setup as shown in Fig. 5. Here a pressure wave signal of a single frequency is emitted by an acoustic transmitter in the Earth’s subsurface, travels through the underground, and is then logged by receivers on the surface. From these measurements geophysicists try to infer variations in the wave speed to draw conclusions about the subsurface composition. The computational domain of interest is a three-dimensional portion of the Earth and we might have knowledge about the sediment layers below this domain, i.e., for \(x\ge 0\) in Fig. 5. While the acoustic waves in \(x\ge 0\) may not be of interest on their own, the layers might cause wave reflections back into the computational domain and hence need be part of the model.

Fig. 5
figure 5

Typical setup of a seismic exploration of the Earth’s subsurface. It is of practical interest to compress the layered medium in \(x\ge 0\) into a single PML with a small number of grid points

Fig. 6
figure 6

Top: The four panels show the modulus of the discrete variable-coefficient DtN function \(f_h\) for varying thickness T of the two finite layers. Bottom: The two plots show the RKFIT convergence for approximating \(f_h(A){\varvec{v}}\) when A is a shifted 2D Laplacian (left) and a diagonal matrix with dense eigenvalues in the same spectral interval (right), respectively

Example 6.1

At the \(x=0\) interface of the computational domain, shown in Fig. 5, we assume to have a 2D Laplacian \(A = (L\otimes L)/h^2 - k_\infty ^2 I\) with L defined in (5.1), and \(N=150^2\), \(h=150\), and \(k_\infty = 15\). Now the function \(f_h\) of interest is (2.3), with the coefficients \(c_j\) obtained by discretizing the piecewise-constant coefficient function c which equals \(-400\) on [0, T), \(+125\) on [T, 2T) and 0 on \([2T,\infty )\). The thickness of the two finite layers T is varied in \(\{0.25,0.5,1,2\}\). For each thickness T, the four panels in the top of Fig. 6 show the modulus of \(f_h\) over the spectral subintervals \([a_1,b_1]\) and \([a_2,b_2]\) of A, glued together with the gray linear region \([b_1,a_2]\). It becomes apparent that with increasing T the function \(f_h\) exhibits more poles on or nearby the spectral interval of A, indicated by the upward spikes.

The convergence of the RKFIT approximants for increasing degree n is shown in Fig. 6 on the bottom left. For each thickness T there are two curves very nearby: a solid curve showing the relative 2-norm approximation error for \(F{\varvec{v}}\) (where \({\varvec{v}}\) is a random training vector) and a dashed curve for \(F{\varvec{u}}_0\) (where \({\varvec{u}}_0\) is another random testing vector). We observe that RKFIT converges very robustly for this piecewise constant-coefficient problem. Similar behavior has been observed in many numerical tests with other offset functions c. We refer to the example collection of the Rational Krylov Toolbox which contains further examples. The codes for producing our examples are available online and can easily be modified to other coefficient functions.

Example 6.2

Here we consider a diagonal matrix A with the same indefinite spectral interval as the matrix in the previous example but with dense eigenvalues, namely 100 logspaced eigenvalues in \([a_1,-10^{-16}]\) and \([10^{-16},b_2]\), respectively. The convergence is shown on the bottom right of Fig. 6. Again the RKFIT behavior is very robust even for high approximation degrees n, but compared to the above Example 6.1 the convergence is delayed, indicating that spectral adaptation has been prevented here.

7 Discussion and conclusions

An obvious alternative to our grid compression approach in the two examples of Sect. 6 would be to use an efficient discretization method on c’s support, and then to append it to the constant-coefficient PML of [12]. In principle such an approach requires at least the integer part of \( \text {N}={\pi }^{-1} \int _{0}^H {\sqrt{k_\infty ^2-c(x)}} \,\mathrm {d}x \) discretization points according to the Nyquist sampling rate, where H is the total thickness of c’s support. In fact, the classical spectral element method (SEM) with polynomial local basis requires at least \(\frac{\pi }{2}\text {N}\) grid points [2]. (The downside of SEM compared to our FD approach is its high linear solver cost per unknown caused by the dense structure of the resulting linear systems.) The following table shows the minimal number of grid points required for discretizing the two finite layers in the examples of Sect. 6, depending on the layer thickness T, as well as the number of RKFIT-FD grid points to achieve a relative accuracy of \(10^{-5}\) for the same problem:






Nyquist minimum \(\text {N}\)





SEM minium \(\frac{\pi }{2}\text {N}\)





RKFIT-FD (Example 6.1)





RKFIT-FD (Example 6.2)





Although we also observe with RKFIT-FD a tendency that the DtN functions become more difficult to approximate when the layer thickness increases (an increase of the coefficient jumps between the layers will have a similar effect), the number of required grid points can be significantly smaller than the Nyquist limit \(\text {N}\). A possible explanation for this phenomenon is RKFIT’s ability to adapt to the spectrum of A, not being slowed down in convergence by singularities of the DtN function well separated from the eigenvalues of A. In the “Appendix” we analyze this phenomenon.