Skip to main content

Theory and Modern Applications

Exact schemes for second-order linear differential equations in self-adjoint cases


When working with mathematical models, to keep the model errors as small as possible, a special system of linear equations is constructed whose solution vector yields accurate discretized values for the exact solution of the second-order linear inhomogeneous ordinary differential equation (ODE). This case involves a 1D spatial variable x with an arbitrary coefficient function \(\kappa (x)\) and an arbitrary source function \(f(x)\) at each grid point under Dirichlet or/and Neumann boundary conditions. This novel exact scheme is developed considering the recurrence relations between the variables. Consequently, this scheme is similar to those obtained using the finite difference, finite element, or finite volume methods; however, the proposed scheme provides the exact solution without any error. In particular, the adequate test functions that provide accurate values for the solution of the ODE at arbitrarily located grid points are determined, thereby eliminating the errors originating from discretization and numerical approximation.

1 Introduction

Consider the following linear second-order inhomogeneous ordinary differential equation (ODE) in self-adjoint form:

$$ -{\frac{d}{dx}} \biggl(\kappa (x) {\frac{d}{dx}}u(x) \biggr) =f(x)\quad (0< x< \ell ), $$

where \(\kappa (x) \geq \kappa _{0} > 0 \) is a positive function ensuring the existence of the integrals applied for the solution procedure. Equation (1.1) is a fundamental formula in the mathematics of physical laws. The practical impact of the solution of Eq. (1.1) is profound since many important physical phenomena used in various industrial applications are described by this equation. Problems in this form arise in various fields, including thermal energy transport, diffusion, electrostatics, and electrodynamics. In electrical applications, κ is the conductivity distribution, u is the electric potential, and f is the source term; all these parameters depend on the 1D spatial variable x. It is assumed that the classic solution \(u(x)\) exists on \([0,\ell ]\) with the appropriate boundary conditions.

Finding and applying an analytical solution to Eq. (1.1) ensures that the error in the mathematical algorithm used to solve the physical problem is solely numerical. Therefore, our mathematical problem in the case of Eq. (1.1) is finding and applying the inverse of the differential operator to construct an analytical ODE solver. On the basis of our research work, this paper proposes a scheme that provides the values for the exact solutionFootnote 1 of Eq. (1.1) in arbitrarily chosen grid points. Although some researchers have attempted to develop exact schemes, practically applicable solutions have been reported only for homogeneous second-order ODEs [1]. Furthermore, some researchers [2] used the nonstandard finite difference method to develop a scheme by using the Green function corresponding to the operator. Based on the fundamental solutions corresponding to differential operators, several schemes applicable to first-order ODEs have been reported [3]. In addition, some higher-order schemes for first- and second-order differential equations were presented in [4]. Furthermore, the authors of [4] reported an exact scheme originating from Samarskii applicable to a special case, namely an equidistant distribution of space. Delkhosh et al. proposed analytical methods for solving a second-order ODE, the effectiveness of which was demonstrated in their published work [5, 6]. The method they described uses the beneficial properties of the Bessel equation to solve homogenous equations with a second-order self-adjoint differential operator [5, 6]. Based on the state-of-the-art literature, it is generally concluded that analytical methods based on the current state of science provide solutions for some specific version of Eq. (1.1) (\(f(x) = 0\) or \(\kappa (x) = 1\)).

Well-known numerical methods, such as the finite difference method (FDM) [7], finite volume method [8], and boundary element method [9], can be used to resolve equations in form (1.1) by approximating the analytical solution of the ODE. Among the classic numerical methods for second-order differential equations, at present, the finite element method (FEM) is the most widely used [10]. This method has also been used to develop approaches involving a higher order of convergence, particularly with the application of higher-order elements [10].

Thus, research on exact schemes is an important aspect in the domain of mathematical physics, and increasing the accuracy of such schemes represents a continuous challenge for researchers. It has been reported [11] that there is no unified theoretical foundation for the construction of exact schemes. Furthermore, increasing the accuracy also increases the complexity and computational burden of these schemes, resulting in difficulties during their application. However, the proposed scheme can overcome these limitations as it provides the exact solution at an arbitrary location independent of the spatial discretization.

The subsequent sections present the details pertaining to the mathematical construction of the proposed method. Furthermore, we demonstrate the advantages of the method through several examples.

2 Local Green functions of ODE for arbitrary partitioning

Consider an arbitrary discretization of the interval \([0,\ell ]\) into \((n+1)\) subintervals using arbitrarily distributed node points:

$$ x_{0}=0 < x_{1}< \cdots < x_{i-1} < x_{i}< x_{i+1}< \cdots < x_{n-1} < x_{n}< x_{n+1} = \ell, $$

where n may be \(1,2,3, \ldots \) . We represent the subintervals as \(I_{i-1}=[x_{i-1}, x_{i}]\) for the indexes \(i=1,2,\ldots,n,n+1\); thus,

$$ [0,\ell ]=I_{0} \cup I_{1} \cup \cdots \cup I_{n-1} \cup I_{n}. $$

We define (2n) nonnegative integral functions of \(\frac{1}{\kappa (x)}\) on the different subintervals represented as follows:

figure a

for each \(i=1,2,\ldots,n\), assuming that the integrals are existing and finite. In the subsequent sections, these functions are used as test functions in a similar sense to the case of the FEM [10].

The following properties are fulfilled for the test functions based on the fundamental theorems of calculus:

$$\begin{aligned} \begin{aligned} &{\frac{d}{dx}}\psi _{i-1}(x) = \frac{1}{\kappa (x)}, \\ &{\frac{d}{dx}} \biggl(\kappa (x){\frac{d}{dx}}\psi _{{i-1}}(x) \biggr)=0\quad (x\in I_{i-1}), \\ &\psi _{i-1}(x_{i-1})=0, \end{aligned} \end{aligned}$$
$$\begin{aligned} \begin{aligned} & {\frac{d}{dx}}\varphi _{i}(x) = -\frac{1}{\kappa (x)}, \\ & {\frac{d}{dx}} \biggl(\kappa (x){\frac{d}{dx}}\varphi _{{i}}(x) \biggr)=0\quad (x\in I_{i}), \\ & \varphi _{i}(x_{i+1})=0, \end{aligned} \end{aligned}$$

for all \(i=1,2,\ldots,n\). Based on the equalities in (2.4) and (2.5), these test functions can be considered local Green functions as they are local solutions to the homogeneous part of ODE (1.1), i.e., when \(f(x)\equiv 0\).

Example 2.1

To illustrate the concepts of local Green functions, we choose an exponential function \(\kappa (x)=e^{x}\) on the interval \([0,3]\) and divide it into \(4=n+1\) pieces with the following node points:

$$x_{0}=0,\qquad x_{1}=1/2,\qquad x_{2}=1,\qquad x_{3}=5/2,\qquad x_{4}=3. $$

Then the local Green functions can be defined as follows:

$$\begin{aligned} &\textstyle\begin{cases} \psi _{{0}}(x) = \int _{0}^{x} \frac{1}{e^{t}} \,dt = 1-e^{-x} \quad (x \in [0,\frac{1}{2} ]), \\ \psi _{1}(x) = \int _{\frac{1}{2}}^{x} \frac{1}{e^{t}} \,dt =e^{-\frac{1}{2}}-e^{-x} \quad (x\in [\frac{1}{2},1]), \\ \psi _{2}(x) = \int _{1}^{x} \frac{1}{e^{t}} \,dt =e^{-1}-e^{-x} \quad (x\in [1,\frac{5}{2}]), \end{cases}\displaystyle \end{aligned}$$
$$\begin{aligned} &\textstyle\begin{cases} \varphi _{1}(x) = \int _{x}^{1} \frac{1}{e^{t}} \,dt =e^{-x}-e^{-1} \quad(x\in [\frac{1}{2},1]), \\ \varphi _{2}(x) = \int _{x}^{\frac{5}{2}} \frac{1}{e^{t}} \,dt =e^{-x}-e^{-\frac{5}{2}} \quad (x\in [1, \frac{5}{2}]), \\ \varphi _{3}(x) = \int _{x}^{3} \frac{1}{e^{t}} \,dt =e^{-x}-e^{-3} \quad (x\in [\frac{5}{2},3] ). \end{cases}\displaystyle \end{aligned}$$

In Fig. 1, the graphs of functions \(\psi _{0}\), \(\psi _{1}\), and \(\psi _{2}\) are represented as solid lines, while those of functions \(\varphi _{1}\), \(\varphi _{2}\), and \(\varphi _{3}\) are represented as dotted lines on the domains of their definitions.

Figure 1
figure 1

Local Green functions Graphs of the local Green functions \(\psi _{0}\), \(\psi _{1}\), and \(\psi _{2}\) (with solid lines) and \(\varphi _{1}\), \(\varphi _{2}\), and \(\varphi _{3}\) (with dotted lines) when \(\kappa (x)=e^{x}\) and \(n=3\)

From the derivatives listed in (2.4) and (2.5), it is clear that test functions \(\psi _{i}\) increase monotonously and that test functions \(\varphi _{i}\) decrease on the interval of their domain \(I_{i} \) for all \(i=1,2,\ldots, n-1 \). On the first interval \(I_{0}\), only the test function \(\psi _{0}\) is considered, while on the last interval \(I_{n}\), we define only the test function \(\varphi _{n}\) similar to the FEM [10]. Initially, it appears as though the local Green functions are not all independent because

$$\begin{aligned} \psi _{i}(x)= \int _{x_{i}}^{x} \frac{1}{\kappa (t)} \,dt = - \int _{x}^{x_{i}} \frac{1}{\kappa (t)} \,dt=-\varphi _{i-1}(x) \quad(i=2,3,\ldots n-1). \end{aligned}$$

Furthermore, as indicated by (2.8) and demonstrated in the following subsections, the test functions are handled in a similar manner as in the FEM [10].

Remark 1

If \(\kappa (x) \equiv 1\) is selected as the constant function and the uniform mesh \(x_{i}=i h (i=0,1,\dots,n+1)\) is used on the interval \([0,1 ]\) with a step size of \({h=\frac{1}{n+1}}\), the test functions form linear functions resembling a saw-tooth pattern, as shown in Fig. 2, and the shape functions can be calculated as follows:

$$ \psi _{{i-1}}(x)=x-(i-1) h,\qquad \varphi _{i}(x) =i h-x\quad (i=1,2, \ldots,n). $$
Figure 2
figure 2

Local Green functions (\(\kappa = 1\)) Graphs of the local Green functions \(\psi _{i}\) (solid line) and \(\varphi _{i}\) (dotted line) in the case of \(\kappa (x) \equiv 1\) with a uniform mesh on \([0,1 ]\) and \(n=4\)

3 Fundamental recursive relation: flux elimination process

In this section, we demonstrate that the test functions defined in (2.3a)–(2.3b) are adequate to create a recursive relation among consecutive values of the solution \(u(x)\). This approach enables the elimination of the derivative \(u'(x)\) from the equations. The objective is now to formulate a linear equation containing three consecutive accurate values \(u(x_{i-1})\), \(u(x_{i})\), and \(u(x_{i+1})\) for the solution of ODE (1.1).

The coefficients of the linear recursive relation are defined using the following integral formula:

$$ a_{i} = \frac{1}{ \int _{x_{i}}^{x_{i+1}} \frac{1}{\kappa (t)} \,dt}\quad (i=0,1,\ldots,n). $$

Using the definition of the test functions in (2.3a)–(2.3b), equivalent formulas for the following coefficients can be defined:

$$ \begin{aligned}& \frac{1}{a_{0}}=\psi _{0}(x_{1}), \\ &\frac{1}{a_{i}}=\psi _{i}(x_{i+1})=\varphi _{i}(x_{i}) \quad(i=1,\ldots,n-1), \\ &\frac{1}{a_{n}}=\varphi _{n}(x_{n}). \end{aligned} $$

The recursive relation can be developed essentially in two steps. An arbitrary pair of consecutive subintervals \(I_{i-1}=[x_{i-1},x_{i}]\) and \(I_{i}=[x_{i},x_{i+1}]\) is selected with a common point \(x_{i}\), where i can be \(1,\ldots,n\).

In the first step, we multiply ODE (1.1) by the test function \(\psi _{{i-1}} ( x )\) and then integrate with respect to x over the interval \(I_{i-1}\):

$$ - \int _{x_{i-1}}^{x_{i}} \bigl(\kappa (x)u'(x) \bigr)'\psi _{i-1}(x)\,dx = \int _{x_{i-1}}^{x_{i}}f(x) \psi _{i-1}(x)\,dx=:G_{i-1}, $$

where the prime symbol (′) denotes the derivative with respect to x and \(i=1,2,\ldots,n\). Applying integration by parts to the left-hand side of (3.3), the derivative of \(\psi _{i-1}(x)\) and the anti-derivative of the remainder can be obtained as follows:

$$ - \bigl[\kappa (x)u'(x)\psi _{i-1}(x) \bigr]_{x=x_{i-1}}^{x=x_{i}}+ \int _{x_{i-1}}^{x_{i}}\kappa (x)u'(x) \underbrace{\psi _{i-1}'(x)}_{1/ \kappa (x)} =G_{i-1}. $$

The first term becomes zero by substituting the lower limit according to the third identity reported in (2.4); however, by substituting the upper limit, we can obtain the coefficient \(\frac{1}{a_{i-1}}=\psi _{{i-1}} ( x_{i} )\) from (3.2). The integrand of the second term can be simplified using the factor \(\kappa ( x )\), and based on the fundamental theorems of calculus, the following expression is obtained:

$$\begin{aligned} -\kappa (x_{i})u'(x_{i})\frac{1}{a_{i-1}}+ \bigl(u(x_{i})-u(x_{i-1}) \bigr)=G_{i-1}. \end{aligned}$$

By multiplying this equation with the coefficient \(a_{i-1}\), we obtain the following relation:

$$ -\kappa (x_{i})u'(x_{i})+{a_{i-1}} \bigl(u(x_{i})-u(x_{i-1}) \bigr)= a_{i-1} G_{i-1}, $$

which is satisfied for all \(i=1,2,\ldots,n\).

It is desirable to eliminate the first term from (3.5), the so-called flux, because the derivative \(u'(x)\) is unknown. This elimination is a necessary second step to obtain the recursive formula.

Therefore, we multiply ODE (1.1) by the test function \(\varphi _{i}(x)\) and integrate over the interval \(I_{i}\):

$$ - \int _{x_{i}}^{x_{i+1}} \bigl(\kappa (x)u'(x) \bigr)'\varphi _{i}(x)\,dx= \int _{x_{i}}^{x_{i+1}}f(x) \varphi _{i}(x)\,dx=:H_{i}, $$

where \(i=1,2,\ldots,n\).

Applying integration by parts to the left-hand side of (3.6), the derivative of factor \(\varphi _{{i}} ( x )\) and the anti-derivative of the remainder can be obtained as follows:

$$ - \bigl[\kappa (x)u'(x)\varphi _{i}(x) \bigr]_{x=x_{i}}^{x=x_{i+1}}+ \int _{x_{i}}^{x_{i+1}}\kappa (x)u'(x) \underbrace{\varphi _{i}'(x)}_{-1/ \kappa (x)}\,dx = H_{i}. $$

The first term becomes zero by substituting the upper limit according to the third identity reported in (2.5); furthermore, by substituting the lower limit, we obtain the coefficient \(\frac{1}{a_{i}}=\varphi _{i}(x_{i})\), as discussed in (3.2). The integrand of the second term can be simplified using the factor \(\kappa (x)\), and from the fundamental theorems of calculus, we can obtain the following:

$$ \kappa (x_{i})u'(x_{i})\frac{1}{a_{i}}- \bigl(u(x_{i+1})-u(x_{i}) \bigr)=H_{i}. $$

Multiplying this equation by the coefficient \(a_{i}\), the following relation is obtained:

$$ \kappa (x_{i})u'(x_{i})-{a_{i}} \bigl(u(x_{i+1})-u(x_{i}) \bigr)={a_{i}} H_{i}, $$

which is satisfied for all \(i=1,2,\ldots,n\).

Now, we can eliminate the flux from Eqs. (3.5) and (3.9). By adding these two equations, the basic recursive relation can be obtained:

$$ -{a_{i-1}} u(x_{i-1})+(a_{i-1}+a_{i}) u(x_{i}) - {a_{i}} u(x_{i+1}) = {a_{i-1}} G_{i-1}+{a_{i}} H_{i} $$

for all indexes \(i=1,2,\ldots,n\).

4 Exact scheme for Dirichlet boundary conditions

We use the basic recurrence relation of Eq. (3.10) to obtain the exact values of solution (1.1) at all \((n+2)\) node points:

$$ u(x_{0}),u(x_{1}),\ldots,u(x_{n-1}),u(x_{n}),u(x_{n+1}). $$

However, only n equations are available in (3.10). Therefore, two values must be prescribed arbitrarily to obtain a unique solution. One possible approach to provide two independent values is to apply Dirichlet boundary conditions, in which the values of the solution at the endpoints are obtained as follows:

$$ {\mathfrak{B}_{D}}= \bigl\{ u(0)=\alpha,u (\ell )= \beta \bigr\} . $$

In this case, we substitute \(u(x_{0})=\alpha \) into the first equation and \(u(x_{n+1})=\beta \) into the last equation in (3.10) to obtain the key result as follows.

Theorem 1

Consider a system of \(n\ge 3\)linear equations:

$$ \textstyle\begin{cases} (a_{0}+a_{1}) u_{1}-a_{1} u_{2} = a_{0} \alpha +a_{0} G_{0} +a_{1} H_{1}, \\ -a_{i-1} u_{i-1}+(a_{i-1}+a_{i}) u_{i} -a_{i} u_{i+1}= a_{i-1} G_{i-1} +a_{i} H_{i}, \\ -a_{n-1} u_{n-1}+(a_{n-1}+a_{n}) u_{n} = a_{n} \beta + a_{n-1} G_{n-1} +a_{n} H_{n} \end{cases} $$

with the indexes \(i=2,3,\ldots,(n-1)\). The coordinates of the solution vector \(U=(u_{1},u_{2},\ldots, u_{n})^{T}\)lead to the same values as the solution \(u(x)\)of the second-order ODE (1.1) with Dirichlet boundary conditions (4.2) at the interior grid points (2.1) without any error, i.e.,

$$ u(x_{i})=u_{i} \quad( i=1,2,\ldots,n), $$

where the coefficients \(a_{i}\)can be obtained using integrals

$$ a_{i}= \frac{1}{\int _{x_{i}}^{x_{i+1}} \frac{1}{\kappa ( t ) } \,dt}\quad (i=0,1,\ldots,n) $$

and the coefficients \(G_{i-1}\)and \(H_{i}\)can be obtained using double integrals

$$ \textstyle\begin{cases} G_{i-1}=\int _{x_{i-1}}^{x_{i}}f(t) (\int _{x_{i-1}}^{t} \frac{1}{\kappa (s)} \,ds ) \,dt, \\ H_{i}=\int _{x_{i}}^{x_{i+1}}f(t) (\int _{t}^{x_{i+1}} \frac{1}{\kappa (s)} \,ds ) \,dt \end{cases}\displaystyle \quad (i=1,2 \ldots n). $$

The matrix-vector format \(L U = F_{D}\) of system (4.3) can be defined, in which the discrete Laplacian matrix (L) is as follows:

figure d

This matrix is symmetric and positive definite and has a tridiagonal shape with dimensions of \(n\times n\). The vector on the right-hand side can be defined for the Dirichlet boundary conditions as follows:

$$ F_{D}=\begin{pmatrix} a_{{0}}\alpha +a_{{0}}G_{{0}}+a_{{1}}H_{{1}} \\ a_{{1}}G_{{1}}+a_{{2}}H_{{2}} \\ {\vdots } \\ a_{{n-2}}G_{{n-2}}+a_{{n-1}}H_{{n-1}} \\ \beta a_{{n}}+a_{{n-1}}G_{{n-1}}+a_{{n}}H_{{n}} \end{pmatrix}. $$

Example 4.1

This example demonstrates the process of the proposed method through detailed calculations for the following differential equation with homogeneous Dirichlet boundary conditions:

$$ - \bigl({e^{x}} u'(x) \bigr)' = 5-2 x, \qquad{ \bigl\{ u(0)=0,u(3)=0 \bigr\} }. $$

It can be tested by derivation that the function \(u(x)=x(3-x){e^{-x}}\) is the solution of (4.8). We choose the same partitioning

$$[0,3 ]=[0,1/2] \cup [1/2,1] \cup [1,5/2] \cup [5/2,3] $$

and the same parameter function \(\kappa (x)={e^{x}}\) as in Example 2.1. We can obtain the values of the Laplacian matrix L (4.6) by performing the integrations described in (3.1), which yields the following result:

$$ \textstyle\begin{cases} a_{0}= \frac{1}{\int _{0}^{1/2} \frac{1}{e^{t}} \,dt}= \frac{1}{1-{e^{-1/2}}},\qquad a_{1}= \frac{1}{\int _{1/2}^{1} \frac{1}{e^{t}} \,dt}= \frac{1}{e^{-1/2}-e^{-1}}, \\ a_{2}= \frac{1}{\int _{1}^{5/2} \frac{1}{e^{t}}\,dt}= \frac{1}{e^{-1}-e^{-5/2}}, \qquad a_{3}= \frac{1}{\int _{5/2}^{3} \frac{1}{e^{t}}\,dt}= \frac{1}{e^{-5/2}-e^{-3}}. \end{cases} $$

We can assemble the entries of the Laplacian matrix based on the tridiagonal form (4.6) by using accurate values of the exponential function \(e^{x}\) in (4.9) without approximating with rounded values:

L= ( a 0 + a 1 a 1 0 a 1 a 1 + a 2 a 2 0 a 2 a 2 + a 3 ) .

By calculating the integrals \(G_{i}\) and \(H_{i}\) in (4.5) and using the local Green functions from Example 2.1, the following expressions are obtained:

$$\begin{aligned} &\textstyle\begin{cases} G_{0} = \int _{0}^{1/2}(5-2 x) (1-e^{-x} )\,dx =-3/4+2 {e^{-1/2}}, \\ G_{1} = \int _{1/2}^{1}(5-2 x) (e^{-1/2}-e^{-x} )\,dx =-1/4 {e^{-1/2}}+{e^{-1}}, \\ G_{2}= \int _{1}^{5/2}(5-2 x) (e^{-1}-e^{-x} )\,dx =5/4 {e^{-1}}-2 {e^{-5/2}} ,\end{cases}\displaystyle \end{aligned}$$
$$\begin{aligned} & \textstyle\begin{cases}H_{1}= \int _{1/2}^{1} (5-2 x ) ( -{e^{-1}} + {e^{-x}} ) \,dx =-11/4 {e^{-1}}+2 {e^{-1/2}}, \\ H_{2}= \int _{1}^{5/2} (5-2 x ) (-{e^{-5/2}} + {e^{-x}} ) \,dx=-1/4 {e^{-5/2}}+{e^{-1}}, \\ H_{3}= \int _{5/2}^{3} (5-2 x ) ( {-e^{-3}} + {e^{-x}} ) \,dx= {13/4} {e^{-3}}-2 {e^{-5/2}}. \end{cases}\displaystyle \end{aligned}$$

Now, we can collect the entries of the right-hand side vector based on the formula

$$\begin{aligned} (F_{D})_{i}=a_{i-1} G_{i-1}+a_{i} H_{i}\quad ( i=1,2,3) \end{aligned}$$

and because the boundary conditions are homogeneous, i.e., \(\alpha =\beta =0\). After simplification, we obtain

$$ F_{D}=\begin{pmatrix} {\frac{-3/4+2 {e^{-}1/2}}{1-e ^{-1/2}}}+{\frac{-11/4 {e^{-1}}+2 {e^{-1/2}}}{{e ^{-1/2}}-{e^{-1}}}} \\ { \frac{-1/4 {e^{ -1/2}}+{e^{-1}}}{{e^{-1/2}}-{e^{-1}}}}+{ \frac{-1/4 {e^{-5/2}}+{e^{-1}}}{{e^{-1}}-{e^{-5/2}}}} \\ { \frac{5/4 {e^{-1}}-2 {e^{-5/2}}}{ {e^{-1}}-{e^{-5/2}}}}+{ \frac{{13/4} {e^{- 3}}-2 {e^{-5/2}}}{{e^{-5/2}}-{e^{-3}}}} \end{pmatrix}. $$

By solving the \(3\times 3\) system of linear equations \(L U=F_{D}\) for the unknown vector \({U=(U_{1},U_{2},U_{3})^{T}}\), the values of the exact solution \(u ( x ) =x ( 3-x ) {e^{-x}}\) at the node points are the same as the coordinates of the solution vector U:

$$ \textstyle\begin{cases} U_{1} =5/4 {e^{-1/2}} =u(1/2), \\ U_{2} =2 {e^{-1}} =u(1), \\ U_{3} =5/4 {e^{-5/2}} =u(5/2). \end{cases} $$

The solution \(u(x)\) is represented in Fig. 3 by a solid line, and the discrete values at the grid points are connected to each other by dotted straight lines.

Figure 3
figure 3

Solution of the example of the Dirichlet problem Graph of the solution \(u(x) \) for problem (Example 4.1) (solid line) and the discretized solution to the system of linear equations \(L U=F_{D}\) (dotted line)

Example 4.2

The recursion (3.10) is valid for \(n=1\) when the interval \([0,\ell ]\) is divided into two parts. In this case, the node points are denoted as \(x_{0}=0,x_{1}=x,x_{2}=\ell \). The objective is to obtain the exact solution \(u(x)\) of ODE (1.1) given the Dirichlet boundary conditions \(u(0)=\alpha \) and \(u(\ell )=\beta \). The only equation in (3.10) is formulated as follows:

$$ \textstyle\begin{cases} - \frac{1}{\int _{0}^{x} \frac{1}{\kappa (t)} \,dt} \alpha + ( \frac{1}{\int _{0}^{x} \frac{1}{\kappa (t)} \,dt} + \frac{1}{\int _{x}^{\ell } \frac{1}{\kappa (t)} \,dt} ) u(x) - \frac{1}{\int _{x}^{\ell } \frac{1}{\kappa (t)} \,dt} \beta \\ \quad =\frac{1}{\int _{0}^{x} \frac{1}{\kappa (t)} \,dt} \int _{0}^{x} f(t) ( \int _{0}^{t} \frac{1}{\kappa (s)} \,ds ) \,dt + \frac{1}{\int _{x}^{\ell } \frac{1}{\kappa (t)} \,dt} \int _{x}^{\ell } f(t) ( \int _{t}^{\ell } \frac{1}{\kappa (s)} \,ds ) \,dt. \end{cases} $$

Isolating \(u(x)\) from this equation yields the solution for the Dirichlet boundary conditions in the form

$$ u(x)=\frac{1}{\int _{0}^{\ell } \frac{1}{\kappa ( t ) } \,dt} \biggl( \alpha \int _{x}^{\ell } \frac{1}{\kappa ( t ) } \,dt +\beta \int _{0}^{x} \frac{1}{\kappa ( t ) } \,dt \biggr) + \int _{0}^{\ell } G ( x,t ) f ( t ) \,dt, $$

where the kernel function \(G(x,t)\) is the (global) Green function

$$ G(x,t) = \frac{1}{ \int _{0}^{\ell } \frac{1}{\kappa (t)} \,dt} \textstyle\begin{cases} \int _{0}^{x} \frac{1}{\kappa (s)} \,ds \int _{t}^{\ell } \frac{1}{\kappa (s)} \,ds & 0\leq x \leq t \leq \ell, \\ \int _{0}^{t} \frac{1}{\kappa (s)} \,ds \int _{x}^{\ell } \frac{1}{\kappa (s)} \,ds & 0\leq t \leq x \leq \ell. \end{cases} $$

We should note that this derivation from local Green functions towards the global Green function is reversible; i.e., we could have started with a solution of the form (4.16) with the Green function (4.17) applied to the partitions \(I_{i-1}\) and \(I_{i}\), and we would still have arrived at the basic recursion relations (3.10).

5 Exact scheme for Dirichlet and Neumann boundary conditions

Consider ODE (1.1) with a Dirichlet boundary condition at \(x=0\) and a Neumann boundary condition at \(x=\ell \):

$$ {\mathfrak{B}_{DN}}= \bigl\{ u(0)=\alpha,\kappa (\ell ) u'(\ell ) = \beta \bigr\} . $$

Because the flux value β is given at \(x=\ell \), we specify a function mapping from the flux β to the solution value \(u(\ell )\). This function is termed the Neumann-to-Dirichlet map at the boundary \(x=\ell \).

Considering the same manipulations leading to identity (3.5) (albeit on the whole interval \([0,\ell ]\)), in this case, we have

$$ -\kappa (\ell )u'(\ell )+ \frac{1}{\int _{0}^{\ell } \frac{1}{\kappa (t)} \,dt} \bigl(u(\ell )-\alpha \bigr)= \frac{1}{\int _{0}^{\ell } \frac{1}{\kappa (t)} \,dt} \int _{0}^{\ell }f(t) \biggl({ \int _{0}^{t} \frac{1}{\kappa (s)} \,ds} \biggr) \,dt. $$

Substituting the Neumann boundary condition and isolating \(u(\ell )\) from this equation results in the following:

$$ u(\ell ) = \alpha + \beta \int _{0}^{\ell } \frac{1}{\kappa (t)} \,dt + \int _{0}^{\ell }f(t) \biggl({ \int _{0}^{t} \frac{1}{\kappa (s)} \,ds} \biggr) \,dt. $$

Therefore, the Neumann boundary condition (5.1) at \(x=\ell \) is transformed into a Dirichlet boundary condition. Applying the scheme from the Dirichlet boundary conditions and using the Dirichlet boundary condition (5.2) instead of \(u(\ell )=\beta \) leads to the following theorem.

Theorem 2

The solution vector \(U=(u_{1},u_{2},\ldots,u_{n})^{T}\)of the system of linear equations, that is,

$$ \textstyle\begin{cases} (a_{0}+a_{1}) u_{1} -a_{1} u_{2} = a_{0} \alpha +a_{0} G_{0} +a_{1} H_{1}, \\ -a_{i-1} u_{i-1}+(a_{i-1}+a_{i}) u_{i} -a_{i} u_{i+1} =a_{i-1} G_{i-1} +a_{i} H_{i}, \\ -a_{n-1} u_{n-1}+(a_{n-1}+a_{n}) u_{n} = a_{n} u(\ell ) +a_{n-1} G_{n-1} + a_{n}H_{n}, \end{cases} $$

with the indexes \(i=2,3,\ldots,n-1\), yields accurate values of the solution \(u(x)\)for the second-order ODE (1.1) with Dirichlet–Neumann boundary conditions (5.1) at the inner grid points (2.1) without any error, i.e.,

$$ u(x_{i})=u_{i} \quad( i=1,2,\ldots,n), $$

where the coefficients \(a_{i}\)are defined by integrals

$$ a_{i}= \frac{1}{\int _{x_{i}}^{x_{i+1}} \frac{1}{\kappa (t)} \,dt} \quad(i=0,1,\ldots,n) $$

\(G_{i-1}\)and \(H_{i}\)are defined by double integrals

$$ \textstyle\begin{cases} G_{i-1}=\int _{x_{i-1}}^{x_{i}} f(t) ( \int _{x_{i-1}}^{t} \frac{1}{\kappa ( s ) } \,ds ) \,dt, \\ H_{i}= \int _{x_{i}}^{x_{i+1}} f(t) (\int _{t}^{x_{i+1}} \frac{1}{\kappa ( s ) } \,ds ) \,dt \end{cases}\displaystyle \quad (i=1,2 \ldots n), $$

and \(u(\ell )\)is defined in (5.2).

The Laplacian matrix (4.6) for the Dirichlet–Neumann boundary conditions (5.1) is the same as in the case of the Dirichlet boundary conditions. Only the last element of the vector on the right-hand side must be changed as follows:

$$ F_{DN}=\begin{pmatrix} a_{0}\alpha +a_{0}G_{0}+a_{1}H_{1} \\ a_{1}G_{1}+a_{2}H_{2} \\ {\vdots } \\ a_{n-2}G_{n-2}+a_{n-1}H_{n-1} \\ a_{n}u(\ell ) +a_{n-1} G_{n-1} + a_{n} H_{n} \end{pmatrix}. $$

Example 5.1

Consider ODE (4.8) in Example 4.1 with the same interval \([0,3]\), the same \(\kappa (x)=e^{x}\), the same \(f(x)=5-2 x\), and the same partitioning. The objective is to attain the same solution \(u ( x ) =x ( 3-x ) {e^{-x}}\); therefore, we prescribe the boundary conditions \(u(0)=0\) and \(\kappa (3) u'(3)=-3 \). Calculating the value \(u(3)\) directly based on identity (5.2) yields

$$\begin{aligned} u(\ell ) &= \alpha + \beta \int _{0}^{\ell } \frac{1}{\kappa (t)} \,dt + \int _{0}^{\ell }f(t) \biggl({ \int _{0}^{t} \frac{1}{\kappa (s)} \,ds} \biggr) \,dt \\ & =(-3) \int _{0}^{3} \frac{1}{e^{t}} \,dt+ \int _{0}^{3} (5-2 t) { \int _{0}^{t} \frac{1}{e^{s}} \,ds} = 0. \end{aligned}$$

Therefore, the right-hand side vector \(F_{DN}\) in 5.6 is the same as the vector \(F_{D}\) in Example 4.1. Consequently, the solution values of the system of linear equations are the same as well.

6 Case study for piecewise constant \(\kappa (x)\)

In this section, we demonstrate the effectiveness and robustness of the proposed exact scheme in the case of an ODE with a discontinuous conductivity function, which appears frequently in practical problems. Consider a physical problem based on (1.1) with homogeneous Dirichlet boundary conditions, in which the source term is \(f(x) = x\) and the conductivity function

$$ \kappa (x) = \textstyle\begin{cases} 1 & \text{if } 0 \leq x \leq 1, \\ 2 & \text{if } 1 < x \leq 3, \end{cases} $$

is not continuous at \(x=1\), as shown in Fig. 4.

Figure 4
figure 4

A piecewise constant \(\kappa (x)\) Plot of the piecewise constant \(\kappa (x)\) function

Because the proposed method eliminates the numerical difficulties arising from the discontinuity, no smoothing (i.e., a sigmoid approximation of the Heaviside function) is required to obtain the exact solution. In particular, the discontinuity of \(\kappa (x)\) does not create issues for the implementation of the proposed method. Although the \(\kappa (x)\) function is discontinuous, its integrals exist, and thus the necessary calculations can be performed. The integral of the conductivity function on the whole domain is

$$ R_{0} = \int _{0}^{3} \frac{1}{\kappa (x)} \,dx = \int _{0}^{1} 1 \,dx + \int _{1}^{3} \frac{1}{2} \,dx = 2. $$

Thus, the shape functions are expressed as follows:

$$\begin{aligned} &\psi (x) = \int _{0}^{x} \frac{1}{\kappa (t)} \,dt = \textstyle\begin{cases} x & \text{if } 0\leq x \leq 1, \\ \frac{1}{2}x + \frac{1}{2} & \text{if } 1\leq x\leq 3, \end{cases}\displaystyle \end{aligned}$$
$$\begin{aligned} & \varphi (x) = \int _{x}^{1} \frac{1}{\kappa (t)} \,dt = \textstyle\begin{cases} 2-x & \text{if } 0\leq x \leq 1, \\ \frac{3}{2} - \frac{1}{2}x & \text{if } 1 \leq x \leq 3, \end{cases}\displaystyle \end{aligned}$$

as shown in Fig. 5.

Figure 5
figure 5

Local Green functions for \(\kappa (x)\) in Eq. (6.1) Graphs of the local Green functions \(\psi _{i}\) (solid line) and \(\varphi _{i}\) (dotted line) in the case of the piecewise constant \(\kappa (x)\)

The different parts of the Green function are defined as follows:

$$ G(x,t) = \frac{1}{R_{0}} \textstyle\begin{cases} \psi (x) \varphi (t) & \text{if } x \leq t, \\ \varphi (x) \psi (t) & \text{if } t \leq x. \end{cases} $$

Thus, based on the shape functions (6.3), (6.4) and (6.5), we can construct the Green functions corresponding to conductivity function (6.1) as follows:

$$ G(x,t) = \frac{1}{R_{0}} \textstyle\begin{cases} x (2-t) & \text{if } x \leq t \leq 1, \\ x (\frac{3}{2}-\frac{1}{2}t ) & \text{if } x \leq 1 \leq t, \\ (\frac{1}{2}x+\frac{1}{2} ) (\frac{3}{2}- \frac{1}{2}t ) & \text{if } 1 \leq x \leq t, \\ (2-x) t & \text{if } t \leq x \leq 1, \\ (\frac{3}{2}-\frac{1}{2}x ) t & \text{if } t \leq 1 \leq x \\ (\frac{3}{2}-\frac{1}{2}x ) (\frac{1}{2}t+ \frac{1}{2} ) & \text{if } 1 \leq t \leq x. \end{cases} $$

Figure 6 shows the surface plot of the Green function \(G(x,t)\).

Figure 6
figure 6

Green function for \(\kappa (x)\) in Eq. (6.1) Graph of the Green function \(G(x,t)\) for the piecewise constant \(\kappa (x)\)

The solution of the problem \(u(x)\) can be derived by using (4.16); however, in general, the solution is defined using

$$ u(x) = \int _{0}^{3} G(x,t) f(t) \,dt. $$

By substituting (6.6) into (6.7), the following expression can be derived:

  • if \(0 \leq x \leq 1\),

    $$\begin{aligned} u(x)={}& \frac{1}{R_{0}} \biggl( \int _{0}^{x} \underbrace{G(x,t)}_{\text{$t \leq x \leq 1$}}f(t)\,dt + \int _{x}^{1} \underbrace{G(x,t)}_{\text{$x \leq t \leq 1$}}f(t)\,dt + \int _{1}^{3}\underbrace{G(x,t)}_{\text{$x \leq 1 \leq t$}}f(t) \,dt \biggr)\\ ={}& \biggl(\frac{1}{2} \int _{0}^{x}(2-x) t^{2} \,dt + \int _{x}^{1} x (2-t) t \,dt + \int _{1}^{3} x \biggl( \frac{3}{2}- \frac{1}{2}t \biggr) t \,dt \biggr) \\ ={}&{ -}\frac{1}{6}x^{3} + \frac{7}{6}x, \end{aligned}$$
  • if \(1 \leq x \leq 3\),

    $$\begin{aligned} u(x)={}& \frac{1}{R_{0}} \biggl( \int _{0}^{1} \underbrace{G(x,t)}_{\text{$t \leq 1 \leq x$}}f(t)\,dt + \int _{1}^{x} \underbrace{G(x,t)}_{\text{$1 \leq t \leq x$}}f(t)\,dt + \int _{x}^{3}\underbrace{G(x,t)}_{\text{$1 \leq x \leq t$}}f(t) \,dt \biggr) \\ = {}&\frac{1}{2} \biggl( \int _{0}^{1} \biggl(\frac{3}{2}- \frac{1}{2}x \biggr) t^{2} \,dt + \int _{1}^{x} \biggl(\frac{3}{2}- \frac{1}{2}x \biggr) \biggl(\frac{1}{2}t+\frac{1}{2} \biggr) t \,dt \\ &{}+ \int _{x}^{3} \biggl( \frac{1}{2}x+ \frac{1}{2} \biggr) \biggl(\frac{3}{2}-\frac{1}{2}t \biggr) t \,dt \biggr) \\ ={}&{ -}\frac{1}{12}x^{3} + \frac{7}{12}x + \frac{1}{2}. \end{aligned}$$

The solution can thus be obtained in the following form:

$$ u(x) = \textstyle\begin{cases} -\frac{1}{6}x^{3} + \frac{7}{6}x & \text{if } 0 \leq x \leq 1, \\ -\frac{1}{12}x^{3} + \frac{7}{12}x + \frac{1}{2} & \text{if } 1 \leq x \leq 3, \end{cases} $$

which is continuous in the whole domain but not differentiable at \(x = 1\), as shown in Fig. 7. Next, we verify whether \(u(x)\) is actually the solution of the original problem. To this end, first, we calculate the derivative of \(u(x)\) with respect to x:

$$ u'(x) = \textstyle\begin{cases} -\frac{1}{2}x^{2} + \frac{7}{6} & \text{if } 0 \leq x < 1, \\ -\frac{1}{4}x^{2} + \frac{7}{12} & \text{if } 1 < x \leq 3. \end{cases} $$

The \(u'(x)\) function is not defined at \(x=1\); however, if we solve the function \(J(x) = \kappa (x) u'(x)\), we obtain

J(x)= { 1 2 x 2 + 7 6 if  0 x < 1 1 2 x 2 + 7 6 if  1 < x 3 }

in which the common value can be inserted at \(x=1\) as follows:

J(x)= { 1 2 x 2 + 7 6 if  x [ 0 , 3 ] { 1 } 2 3 if  x = 1 } = 1 2 x 2 + 7 6 .

The discontinuity can be removed, as shown in Fig. 7.

Figure 7
figure 7

Verifying the solution of the example with piecewise constant \(\kappa (x)\) Process of removing the discontinuity of \(J(x)=\kappa (x)u'(x)\)

The derivative of the now differentiable \(J(x)\) proves that \(u(x)\) is actually the solution of the original problem

$$ -J'(x) = x = f(x). $$

7 Conclusion

This paper presents a practically useful and easily applicable robust scheme for calculating the exact solutions of a second-order self-adjoint ODE on any grid point corresponding to an arbitrary discretization. Through detailed derivations, we proved our theorems and assertions, and the effectiveness of the method was demonstrated through several relevant examples involving continuous and discontinuous \(\kappa (x)\). By rearranging the scheme, an implicit form of the solution of the differential equation can be obtained, which can be used to derive the analytical solution if it can be evaluated symbolically; in addition, by numerically evaluating the integrals, the proposed approach can provide the exact numerical values of the solution at any given point. Because the proposed scheme is easy to implement in various mathematical software environments (Mathematica, Maple, MATLAB, etc.), for problems possessing the given ODE structure, the exact solution can be determined, thereby avoiding the use of and problems associated with various numerical approximation methods. For all these reasons, the proposed method can be used not only to effectively solve mathematical problems with the differential operators in Eq. (1.1) but also to solve physical processes that can be described by the ODE in Eq. (1.1). In this case, if the integrals resulting from the applied scheme can be evaluated symbolically, the physical problem can be solved analytically, but if the integrals are numerically evaluated, we can obtain the exact solution to the physical problem at arbitrarily located grid points. At the moment, the proposed scheme works for the specific ODE structure discussed; a future direction can be the extension of this method to a broader range of differential operators.


  1. By the exact solution, we refer to the value of the analytical solution at any given location.


  1. Axelsson, O., Karátson, J.: Harmonic averages, exact difference schemes and local Green’s functions in variable coefficient PDE problems. Open Math. 11(8), 1441–1457 (2013).

    Article  MathSciNet  MATH  Google Scholar 

  2. Hernandez-Martinez, E., Puebla, H., Valdes-Parada, F., Alvarez-Ramirez, J.: Nonstandard finite difference schemes based on Green’s function formulations for reaction–diffusion–convection systems. Chem. Eng. Sci. 94, 245–255 (2013).

    Article  Google Scholar 

  3. Vabishchevich, P.N.: Fundamental mode exact schemes for unsteady problems. Numer. Methods Partial Differ. Equ. 34(6), 2301–2315 (2018).

    Article  MathSciNet  MATH  Google Scholar 

  4. Samarskii, A.A.: The Theory of Difference Schemes. Differential Equations & Nonlinearity, vol. 1, 1st edn. CRC Press, Boca Raton (2001).

    Book  MATH  Google Scholar 

  5. Delkhosh, M.: The conversion a Bessel’s equation to a self-adjoint equation and applications. World Appl. Sci. J. 15(12), 1687–1691 (2011)

    Google Scholar 

  6. Delkhosh, M., Delkhosh, M.: Analytic solutions of some self-adjoint equations by using variable change method and its applications. J. Appl. Math. 2012, Article ID 180806 (2012).

    Article  MathSciNet  MATH  Google Scholar 

  7. LeVeque, R.J.: Finite Difference Methods for Ordinary and Partial Differential Equations. Other Titles in Applied Mathematics, vol. 1. SIAM, Philadelphia (2007).

    Book  MATH  Google Scholar 

  8. Adison, H.: Principles and Practice of Finite Volume Method. Differential & Riemannian Geometry, vol. 1. Clanrye International, New York (2015).

    Google Scholar 

  9. Sauter, S.A., Schwab, C.: Boundary Element Methods. Springer Series in Computational Mathematics, vol. 39. Springer, Berlin (2010).

    MATH  Google Scholar 

  10. Pepper, D.W., Heinrich, J.C.: The Finite Element Method, Computational and Physical Processes in Mechanics and Thermal Sciences, vol. 2, 2nd edn. CRC Press, Boca Raton (2017).

    Book  Google Scholar 

  11. Mickens, R.E.: Nonstandard finite difference schemes for differential equations. J. Differ. Equ. Appl. 8(9), 823–847 (2002).

    Article  MathSciNet  MATH  Google Scholar 

Download references


Not applicable.

Availability of data and materials

Data sharing was not applicable to this article as no datasets were generated or analysed during the current study.


The research project was conducted at the University of Pecs, Hungary, within the frameworks of the Biomedical Engineering Project of the Thematic Excellence Programme 2019 (TUDFO/51757-1/2019-ITM) and the project “Sustainable Raw Material Management Thematic Network RING 2017” EFOP-3.6.2-16-2017-00010.

Author information

Authors and Affiliations



All of the authors have approved the submitted version (and any substantially modified version that involves the authors’ contribution to the study) and have agreed both to be personally accountable for the author’s own contributions and to ensure that questions related to the accuracy or integrity of any part of the work, even those in which the author was not personally involved, are appropriately investigated and resolved and that the resolution is documented in the literature. The authors contributed to the manuscript as follows: ZV: drafted the work, performed analysis, ZS: created new software used in the work, MK: designed the work, PO: designed and substantively revised the work.

Corresponding author

Correspondence to Zoltan Vizvari.

Ethics declarations

Competing interests

The authors declare that they have no competing interests.

Rights and permissions

Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Vizvari, Z., Sari, Z., Klincsik, M. et al. Exact schemes for second-order linear differential equations in self-adjoint cases. Adv Differ Equ 2020, 497 (2020).

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: