1 Introduction

The Ulam stability problem originated from an important talk at the University of Wisconsin organized by Ulam [34]. Such stability problem is first concerned with the stability of group homomorphisms. The essential problem of this type of stability is summarized as follows: “under what conditions can a solution of a perturbed equation close to a solution of the original equation?” Hyers [8] seems to be the first person to study this kind of stability. Specifically, he gave a first affirmative partial answer to the question proposed by Ulam for Banach spaces. Afterward, this work was generalized by Rassias [27] for linear mappings by considering an unbounded Cauchy difference. It is worth mentioning that Rassias’ work has a great impact on the development of the Ulam stability of functional equations. In the following decades, almost all of the studies associated with the Ulam stability were focused on different types of functional equations and abstract spaces. For more details, the reader can refer to several monographs [6, 9, 16, 29] and the references therein.

Obloza [23] first initiated the study of the Ulam stability of differential equations. A few years later, Alsina and Ger [2] established the Hyers–Ulam stability of the differential equation \(y'(x)=y(x)\). That is to say, for a given \(\varepsilon >0\), if f is a differentiable function from an open interval I into \({\mathbb {R}}\) with \(|f'(x)-f(x)|\le \varepsilon \) for all \(x\in {I}\), then there exists a differentiable function \(g:I\rightarrow {\mathbb {R}}\) such that \(g'(x)=g(x)\) which satisfies \(|f(x)-g(x)|\le 3\varepsilon \) for all \(x\in {I}\). Later, Miura and Takahasi et al. [18, 20, 32] further studied the Ulam stability of the differential equation \(y'(x)=\lambda y(x)\) in various abstract spaces. By using the same method as in [2], Jung [10] proved the Hyers–Ulam stability of the differential equation \(\varphi (x)y'(x)=y(x)\). Furthermore, the Hyers–Ulam stability of the first-order linear differential equation \(y'(x)+p(x)y(x)+q(x)=0\) was extensively studied by Miura et al. [19], Takahasi et al. [33] and Jung [11, 12]. Meantime, Jung [13] also proved the Hyers–Ulam stability of a system of first-order linear differential equations with constant coefficients by the matrix method. Li and Shen [17] established the Hyers–Ulam stability of second order linear differential equations with constant coefficients by the reduced order method. However, this result requires the condition that the associated characteristic equation contains two different positive roots. Using the similar technique, the Ulam stability of linear differential equations with constant coefficients was considered by Cîmpean and Popa [5], Popa and Raşa [25]. Analogously, the Hyers–Ulam stability of third-order linear differential equations with constant coefficients was studied by Abdollahpour and Najati [1]. More generally, Brzdek and Jung [3] investigated the Hyers–Ulam stability for an operator linear equation of second order. Further, Xu et al. [36] proved the Hyers–Ulam stability of linear operator equations of higher order by using the fixed point method. Recently, Brzdek et al. [4] studied the Hyers–Ulam stability of linear operators and hence they also obtained the stability results of linear differential equation of n-th order with constant coefficients. Popa and Raşa [26] investigated the Hyers–Ulam stability of linear differential equations with nonconstant coefficients by the decomposition of the differential operator of n-th order. At the same time, Miura et al. [21] proved the Hyers–Ulam stability of the Chebyshev differential equation \((1-x^2)y''(x)-xy'(x)+n^2y(x)=0\) by using the analytical method. Inspired by this work, Shen et al. [31] further considered the Ulam stability of a class of linear differential equations \(p(x)y''(x)+q(x)y'(x)+\lambda y(x)=0,\,\,\lambda >0\) when the coefficient functions satisfy certain conditions. This work can be regarded as a generalization of Miura et al. [21]. In recent years, some classical methods for solving differential equations were also applied to study the Ulam stability problem of differential equations, such as the integrating factor method [30, 35], the power series method [14] and the Laplace transform method [28] and so on. It should be pointed out that the fixed point technique had been used to study the Ulam stability of the general differential equation \(y'=F(x,y)\) [15]. Huang and Li [7] showed the Hyers–Ulam stability of linear functional equations by using various methods, including direct method, iteration method, fixed point method and open mapping theorem. Meanwhile, Mortici et al. [22] solved the inhomogeneous Euler equation of second order and proved its Hyers–Ulam stability on a bounded domain by using the integration method. Soon after, Popa and Pugna [24] obtained the Ulam stability of the inhomogeneous Euler’s differential equation of n-th order. This result extends and improves the work of Mortici et al. [22].

Based on the preceding statements, we can find that there is little literature, except for Ref. [26], to uniformly study the Ulam stability of linear differential equations with constant and nonconstant coefficients. The aim of this paper is to provide a unified method, i.e., the variation of parameters, to establish the Ulam stability of linear differential equations.

Let \({\mathbb {R}}\) denote the set of all real numbers. Unless otherwise stated, the symbol I denotes a subinterval in \({\mathbb {R}}\). Let \(C(I,{\mathbb {R}})\) and \(C^{n}(I,{\mathbb {R}})\) denote the set of all real-valued continuous functions and the set of all differentiable functions which have continuous derivatives up to n.

2 The General Solution and Ulam Stability of First-Order Linear Differential Equations

In this section, we shall establish the Ulam stability of first order linear differential equations by the method of variation of parameters.

The nonhomogeneous linear differential equation of first-order is given as follows:

$$\begin{aligned} y'(x)+p(x)y(x)=f(x), \end{aligned}$$
(1)

where \(x\in I\), \(p,f\in C(I,{\mathbb {R}})\). The associated homogeneous linear differential equation of (1) is

$$\begin{aligned} y'(x)+p(x)y(x)=0. \end{aligned}$$
(2)

Suppose that \(y_{1}(x)\) is a basic solution of (2). It is well known that \(Y(x)=\widetilde{c}y_{1}(x)\) is the general solution of (2), where \(\widetilde{c}\) is an arbitrary constant. Using the method of variation of parameters, we can obtain a particular solution of (1) by replacing the constant \(\widetilde{c}\) in Y(x) by an undetermined function u(x). Setting \(y_{p}(x)=u(x)y_{1}(x)\). Now, we assume that \(y_{p}(x)\) is a solution of (1). Substituting \(y_{p}\) into (1), we then obtain

$$\begin{aligned} u(x)\left( \frac{\mathrm{d}y_{1}}{\mathrm{d}x}+p(x)y_{1}(x)\right) +y_{1}(x)\frac{\mathrm{d}u}{\mathrm{d}x}=f(x). \end{aligned}$$
(3)

Notice that \(y_{1}(x)\) is a solution of (2), it follows from (3) that

$$\begin{aligned} y_{1}(x)\frac{\mathrm{d}u}{\mathrm{d}x}=f(x). \end{aligned}$$
(4)

By separating the variable and integrating both sides of (4) from \(x_{0}\) to x with respect to t, we get

$$\begin{aligned} u(x)=c_{1}+\int _{x_{0}}^{x}\frac{f(t)}{y_{1}(t)}\mathrm{d}t, \end{aligned}$$

where \(c_{1}\in {\mathbb {R}}\) is an arbitrary constant. Therefore, we have

$$\begin{aligned} y_{p}(x)=u(x)y_{1}(x)=\left( c_{1}+\int _{x_{0}}^{x}\frac{f(t)}{y_{1}(t)}\mathrm{d}t\right) y_{1}(x). \end{aligned}$$

Accordingly, we can present the following result.

Theorem 2.1

Let \(p,f\in C(I,{\mathbb {R}})\) and let \(y_{1}(x)\) be a basic solution of (2). Then, the general solution y(x) of (1) is given by

$$\begin{aligned} \begin{aligned} y(x)&=Y(x)+y_{p}(x)\\&=\widetilde{c}y_{1}(x)+\left( c_{1}+\int _{x_{0}}^{x} \frac{f(t)}{y_{1}(t)}\mathrm{d}t\right) y_{1}(x)\\&=cy_{1}(x)+y_{1}(x)\int _{x_{0}}^{x}\frac{f(t)}{y_{1}(t)}\mathrm{d}t, \end{aligned} \end{aligned}$$

where \(c=\widetilde{c}+c_{1}\) is still an arbitrary constant.

Based on Theorem 2.1, we now prove the Ulam stability of nonhomogeneous linear differential Eq. (1).

Theorem 2.2

Let \(p,f\in C(I,{\mathbb {R}})\) and let \(y_{1}(x)\) be a basic solution of (2). Assume that \(\varphi :I\rightarrow [0,+\infty )\) is a continuous function. If \(y_{\varphi }\in C^{1}(I,{\mathbb {R}})\) satisfies the differential inequality

$$\begin{aligned} \left| y_{\varphi }'(x)+p(x)y_{\varphi }(x)-f(x)\right| \le \varphi (x) \end{aligned}$$
(5)

for all \(x\in I\), then there exists \(y\in C^{1}(I,{\mathbb {R}})\) such that y(x) satisfies (1) and

$$\begin{aligned} \left| y_{\varphi }(x)-y(x)|\le |y_{1}(x)\right| \left| \int _{x_{0}}^{x} \frac{\varphi (t)}{|y_{1}(t)|}\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\).

Proof

For convenience, we write

$$\begin{aligned} y_{\varphi }'(x)+p(x)y_{\varphi }(x):=f_{\varphi }(x). \end{aligned}$$
(6)

Then, it follows from (5) that

$$\begin{aligned} |f_{\varphi }(x)-f(x)|\le \varphi (x) \end{aligned}$$
(7)

for all \(x\in {I}\). According to Theorem 2.1 and (6), there exists a constant c such that

$$\begin{aligned} y_{\varphi }(x)=cy_{1}(x)+y_{1}(x)\int _{x_{0}}^{x} \frac{f_{\varphi }(t)}{y_{1}(t)}\mathrm{d}t, \end{aligned}$$
(8)

where \(x_{0}\in {I}\) is an arbitrary fixed point.

Define

$$\begin{aligned} y(x)=cy_{1}(x)+y_{1}(x)\int _{x_{0}}^{x}\frac{f(t)}{y_{1}(t)}\mathrm{d}t \end{aligned}$$
(9)

for all \(x\in {I}\). By Theorem 2.1, it is easy to verify that y(x) is a solution of (1). From (7), (8) and (9), we can obtain

$$\begin{aligned} \begin{aligned} |y_{\varphi }(x)-y(x)|&=\left| y_{1}(x)\int _{x_{0}}^{x} \frac{f_{\varphi }(t)}{y_{1}(t)}\mathrm{d}t-y_{1}(x)\int _{x_{0}}^{x} \frac{f(t)}{y_{1}(t)}\mathrm{d}t\right| \\&=|y_{1}(x)|\left| \int _{x_{0}}^{x}\frac{f_{\varphi }(t)-f(t)}{y_{1}(t)}\mathrm{d}t\right| \\&\le |y_{1}(x)|\left| \int _{x_{0}}^{x}\frac{\varphi (t)}{|y_{1}(t)|}\mathrm{d}t\right| \end{aligned} \end{aligned}$$
(10)

for all \(x\in {I}\). The proof of the theorem is now completed. \(\square \)

Remark 1

In fact, we all know that \(y_{1}(x)=\mathrm{e}^{-\int _{x_{0}}^xp(t)\mathrm{d}t}\)\((x_{0}\in {I})\) is a basic solution of the homogeneous linear differential Eq. (2). Then, the general solution of (2) is given by \(Y(x)=c\mathrm{e}^{-\int _{x_{0}}^xp(t)\mathrm{d}t}\). Therefore, the inequality (10) can be rewritten as

$$\begin{aligned} |y_{\varphi }(x)-y(x)|\le \mathrm{e}^{-\int _{x_{0}}^xp(t)\mathrm{d}t}\left| \int _{x_{0}}^{x}\varphi (t) \mathrm{e}^{\int _{x_{0}}^{t}p(\tau )\mathrm{d}\tau }\mathrm{d}t\right| . \end{aligned}$$

As a particular case of Theorem 2.2, we can obtain the Hyers–Ulam stability of the first-order nonhomogeneous linear differential Eq. (1) when the interval \(I=[a,b]\) is finite.

Corollary 2.3

Let \(p,f\in C([a,b],{\mathbb {R}})\). For a given \(\varepsilon >0\), if a continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| y_{\varphi }'(x)+p(x)y_{\varphi }(x)-f(x)\right| \le \varepsilon \end{aligned}$$

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (1) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\mathrm{e}^{\int _{a}^{b}|p(x)|\mathrm{d}x}(b-a). \end{aligned}$$

3 The General Solution and Ulam Stability of Second-Order Linear Differential Equations

In this section, we shall consider the general solution and Ulam stability of second-order linear differential equations by the method of variation of parameters.

The second-order nonhomogeneous linear differential equation is given as follows:

$$\begin{aligned} y''(x)+p(x)y'(x)+q(x)y(x)=f(x), \end{aligned}$$
(11)

where \(x\in {I}\), \(p,q,f\in C(I,{\mathbb {R}})\). The corresponding homogeneous linear differential equation of (11) is given by

$$\begin{aligned} y''(x)+p(x)y'(x)+q(x)y(x)=0. \end{aligned}$$
(12)

Let \(y_{1}\) and \(y_{2}\) be fundamental system of solutions of (12). The general solution of (12) is \(Y(x)=\widetilde{c}_{1}y_{1}(x)+\widetilde{c}_{2}y_{2}(x)\). Replacing \(\widetilde{c}_{1}\) and \(\widetilde{c}_{2}\) in Y(x) by two undetermined functions \(u_{1}(x)\) and \(u_{2}(x)\), respectively. Setting \(y_{p}(x)=u_{1}(x)y_{1}(x)+u_{2}(x)y_{2}(x)\). Now, we assume that \(y_{p}(x)\) is a solution of (11). Then, we have

$$\begin{aligned} \begin{aligned}&y_{p}'=u_{1}y_{1}'+u_{1}'y_{1}+u_{2}y_{2}'+u_{2}'y_{2},\\&y_{p}''=u_{1}y_{1}''+2u_{1}'y_{1}'+u_{1}''y_{1}+u_{2}y_{2}'' +2u_{2}'y_{2}'+u_{2}''y_{2}. \end{aligned} \end{aligned}$$
(13)

Substituting (13) into (11), and combining the same items, we can obtain

$$\begin{aligned} \begin{aligned} y_{p}''+p(x)y_{p}'+q(x)y_{p}&=\left( y_{1}''+p(x)y_{1}'+q(x)y_{1}\right) u_{1}+\left( y_{2}''+p(x)y_{2}'\right. \\&\left. \quad +\,\, q(x)y_{2}\right) u_{2}+y_{1}u_{1}''+y_{1}'u_{1}'+y_{2}u_{2}''+y_{2}'u_{2}'\\&\quad +p(x)\left( y_{1}u_{1}'+y_{2}u_{2}'\right) +y_{1}'u_{1}'+y_{2}'u_{2}'\\&=\left( y_{1}u_{1}'\right) '+\left( y_{2}u_{2}'\right) '+p(x)\left( y_{1}u_{1}' +y_{2}u_{2}'\right) +y_{1}'u_{1}'+y_{2}'u_{2}'\\&=\left( y_{1}u_{1}'+y_{2}u_{2}'\right) '+p(x)\left( y_{1}u_{1}'+y_{2}u_{2}'\right) +y_{1}'u_{1}'+y_{2}'u_{2}'\\&=f(x), \end{aligned} \end{aligned}$$
(14)

where for the second equal sign we have used the fact \(y_{1}\) and \(y_{2}\) are two solutions of (12). Note that \(y_{p}\) is merely a particular solution. Without loss of generality, we can assume that

$$\begin{aligned} y_{1}u_{1}'+y_{2}u_{2}'=0, \end{aligned}$$
(15)

and then we can obtain from (14) that

$$\begin{aligned} y_{1}'u_{1}'+y_{2}'u_{2}'=f(x). \end{aligned}$$
(16)

Since \(y_{1}\) and \(y_{2}\) are fundamental system of solutions of (12), it follows that the Wronskian

$$\begin{aligned} W(y_{1},y_{2})(x)=\left| \begin{matrix} y_{1}(x) &{}\quad y_{2}(x)\\ y_{1}'(x) &{}\quad y_{2}'(x) \end{matrix}\right| \ne 0 \end{aligned}$$

for all \(x\in {I}\). By using Cramer’s rule, we can get from (15) and (16) that

$$\begin{aligned} u_{1}'(x)=\frac{W_{1,2}(x)}{W(y_{1},y_{2})(x)},\quad u_{2}'(x)=\frac{W_{2,2}(x)}{W(y_{1},y_{2})(x)}, \end{aligned}$$
(17)

where

$$\begin{aligned} W_{1,2}(x)=\left| \begin{matrix} 0 &{}\quad y_{2}(x)\\ f(x) &{}\quad y_{2}'(x) \end{matrix}\right| ,\quad W_{2,2}(x)=\left| \begin{matrix} y_{1}(x) &{}\quad 0\\ y_{1}'(x) &{}\quad f(x) \end{matrix}\right| . \end{aligned}$$

By integrating both sides of (17) from \(x_{0}\) to x with respect to t, it follows that

$$\begin{aligned} u_{1}(x)= & {} {\widehat{c}}_{1}+\int _{x_{0}}^{x}\frac{W_{1,2}(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t,\\ u_{2}(x)= & {} {\widehat{c}}_{2}+\int _{x_{0}}^{x}\frac{W_{2,2}(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t, \end{aligned}$$

where \({\widehat{c}}_{1}\) and \({\widehat{c}}_{2}\) are two arbitrary constants. Then, we have

$$\begin{aligned} \begin{aligned} y_{p}(x)&=u_{1}(x)y_{1}(x)+u_{2}(x)y_{2}(x)={\widehat{c}}_{1}y_{1}(x)+{\widehat{c}}_{2}y_{2}(x)\\&\quad +y_{1}(x) \int _{x_{0}}^{x}\frac{W_{1,2}(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t+y_{2}(x)\int _{x_{0}}^{x}\frac{W_{2,2}(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t. \end{aligned} \end{aligned}$$

Furthermore, we can obtain the general solution of (11).

Theorem 3.1

Let \(p,q,f\in C(I,{\mathbb {R}})\) and let \(y_{1}(x)\) and \(y_{2}(x)\) be fundamental system of solutions of (12). Then, the general solution y(x) of (11) can be given by

$$\begin{aligned} \begin{aligned} y(x)&=Y(x)+y_{p}(x)=c_{1}y_{1}(x)+c_{2}y_{2}(x)+y_{1}(x)\int _{x_{0}}^{x}\frac{W_{1,2}(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t\\&\quad +y_{2}(x)\int _{x_{0}}^{x}\frac{W_{2,2}(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t, \end{aligned} \end{aligned}$$

where \(c_{1}\) and \(c_{2}\) are two arbitrary constants, \(x_{0}\in {I}\) is an arbitrary fixed point.

According to Theorem 3.1, we can obtain the Ulam stability of the second-order nonhomogeneous linear differential Eq. (11).

Theorem 3.2

Let \(p,q,f\in C(I,{\mathbb {R}})\) and let \(y_{1}(x)\) and \(y_{2}(x)\) be fundamental system of solutions of (12). Assume that \(\varphi :I\rightarrow [0,+\infty )\) is a continuous function. If \(y_{\varphi }\in C^{2}(I,{\mathbb {R}})\) satisfies the differential inequality

$$\begin{aligned} \left| y_{\varphi }''(x)+p(x)y_{\varphi }'(x)+q(x) y_{\varphi }(x)-f(x)\right| \le \varphi (x) \end{aligned}$$
(18)

for all \(x\in I\), then there exists \(y\in C^{2}(I,{\mathbb {R}})\) such that y(x) satisfies (11) and

$$\begin{aligned} \left| y_{\varphi }(x)-y(x)\right| \le \left| \int _{x_{0}}^{x}\left| \frac{W(y_{1},y_{2}) (t,x)}{W(y_{1},y_{2})(t)}\right| \varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\), where

$$\begin{aligned} W(y_{1},y_{2})(t,x)=\left| \begin{matrix} y_{1}(t) &{}\quad y_{2}(t)\\ y_{1}(x) &{}\quad y_{2}(x) \end{matrix}\right| . \end{aligned}$$

Proof

Here, we set

$$\begin{aligned} y_{\varphi }''(x)+p(x)y_{\varphi }'(x)+q(x)y_{\varphi }(x):=f_{\varphi }(x). \end{aligned}$$
(19)

From (18), it follows that the inequality (11) holds. By Theorem 3.1 and (19), there exist two constants \(c_{1}\) and \(c_{2}\) such that

$$\begin{aligned} y_{\varphi }(x)=c_{1}y_{1}(x)+c_{2}y_{2}(x)+y_{1}(x)\int _{x_{0}}^{x} \frac{-y_{2}(t)f_{\varphi }(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t+y_{2}(x) \int _{x_{0}}^{x}\frac{y_{1}(t)f_{\varphi }(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t, \end{aligned}$$
(20)

where \(x_{0}\in {I}\) is an arbitrary fixed point.

Define

$$\begin{aligned} y(x)=c_{1}y_{1}(x)+c_{2}y_{2}(x)+y_{1}(x)\int _{x_{0}}^{x} \frac{-y_{2}(t)f(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t+y_{2}(x)\int _{x_{0}}^{x} \frac{y_{1}(t)f(t)}{W(y_{1},y_{2})(t)}\mathrm{d}t \end{aligned}$$
(21)

for all \(x\in {I}\). By Theorem 3.1, we know that y(x) is a solution of (12). In view of (11), (20) and (21), we can infer that

$$\begin{aligned} \begin{aligned}&\left| y_{\varphi }(x)-y(x)\right| \\&\quad =\left| y_{1}(x)\int _{x_{0}}^{x}\frac{-y_{2}(t)\left( f_{\varphi }(t)-f(t)\right) }{W(y_{1},y_{2})(t)}\mathrm{d}t+y_{2}(x)\int _{x_{0}}^{x}\frac{y_{1}(t)\left( f_{\varphi } (t)-f(t)\right) }{W(y_{1},y_{2})(t)}\mathrm{d}t\right| \\&\quad =\left| \int _{x_{0}}^{x}\frac{-y_{1}(x)y_{2}(t)\left( f_{\varphi }(t)-f(t)\right) }{W(y_{1},y_{2})(t)}\mathrm{d}t+\int _{x_{0}}^{x}\frac{y_{2}(x)y_{1}(t)\left( f_{\varphi } (t)-f(t)\right) }{W(y_{1},y_{2})(t)}\mathrm{d}t\right| \\&\quad \le \left| \int _{x_{0}}^{x}\right| \frac{W(y_{1},y_{2})(t,x)}{W(y_{1},y_{2}) (t)}\left| \varphi (t)\mathrm{d}t\right| , \end{aligned} \end{aligned}$$

for all \(x\in {I}\). This completes the proof. \(\square \)

Remark 2

Let \(I=[a,b]\) be a finite closed interval and let \(\varepsilon \) be an arbitrary positive number. If we take \(\varphi (t)\equiv \varepsilon \), then we can obtain the Hyers–Ulam stability of (11).

Corollary 3.3

Let \(p,q,f\in C([a,b],{\mathbb {R}})\). For a given \(\varepsilon >0\), if a twice continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| y_{\varphi }''(x)+p(x)y_{\varphi }'(x)+q(x)y_{\varphi }(x)-f(x) \right| \le \varepsilon \end{aligned}$$

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (11) such that

$$\begin{aligned} \left| y_{\varepsilon }(x)-y(x)\right| \le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\max _{x\in [a,b]}\int _{a}^{x}\left| \frac{W(y_{1},y_{2})(t,x)}{W(y_{1},y_{2})(t)}\right| \mathrm{d}t. \end{aligned}$$

As a particular case, we can establish the Ulam stability of second order nonhomogeneous linear differential equations with constant coefficients. Specifically, the differential equation is given as follows:

$$\begin{aligned} y''(x)+\gamma y'(x)+\delta y(x)=f(x), \end{aligned}$$
(22)

where \(\gamma ,\delta \) are real constants, \(f\in C(I,{\mathbb {R}})\). The associated characteristic equation is

$$\begin{aligned} \lambda ^2+\gamma \lambda +\delta =0. \end{aligned}$$
(23)

Corollary 3.4

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (23) has two distinct real roots \(\lambda _{1}\) and \(\lambda _{2}\). If \(y_{\varphi }\in C^{2}(I,{\mathbb {R}})\) satisfies the differential inequality

$$\begin{aligned} \left| y_{\varphi }''(x)+\gamma y_{\varphi }'(x)+\delta y_{\varphi }(x)-f(x)\right| \le \varphi (x) \end{aligned}$$
(24)

for all \(x\in I\), then there exists a solution \(y\in C^{2}(I,{\mathbb {R}})\) of (22) such that

$$\begin{aligned} \left| y_{\varphi }(x)-y(x)\right| \le \frac{1}{|\lambda _{1}-\lambda _{2}|}\left| \int _{x_{0}}^{x}\right| \mathrm{e}^{\lambda _{2}(x-t)}-\mathrm{e}^{\lambda _{1}(x-t)} \left| \varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\).

Proof

Notice that \(y_{1}(x)=\mathrm{e}^{\lambda _{1}x}\) and \(y_{2}(x)=\mathrm{e}^{\lambda _{2}x}\) are fundamental system of solutions of the associated homogeneous linear differential equation of (22). The desired result can be obtained from Theorem 3.2. \(\square \)

Corollary 3.5

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (23) has two real roots \(\lambda _{1}\) and \(\lambda _{2}\) with \(\lambda _{1}=\lambda _{2}\). If \(y_{\varphi }\in C^{2}(I,{\mathbb {R}})\) satisfies the differential inequality (24) for all \(x\in I\), then there exists a solution \(y\in C^{2}(I,{\mathbb {R}})\) of (22) such that

$$\begin{aligned} \left| y_{\varphi }(x)-y(x)\right| \le \left| \int _{x_{0}}^{x}\left| (x-t)\mathrm{e}^{\lambda _{1} (x-t)}\right| \varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\).

Proof

It is well known that \(y_{1}(x)=\mathrm{e}^{\lambda _{1}x}\) and \(y_{2}(x)=x\mathrm{e}^{\lambda _{1}x}\) are fundamental system of solutions of the associated homogeneous linear differential equation of (22). Similarly, the desired result can be proved by Theorem  3.2. \(\square \)

Corollary 3.6

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (23) has a pair of complex conjugate roots \(\lambda _{1}\) and \(\lambda _{2}\) with \(\lambda _{1}=\alpha +i\beta \), \(\lambda _{2}=\alpha -i\beta \), where \(\alpha \in {\mathbb {R}}\), \(\beta >0\). If \(y_{\varphi }\in C^{2}(I,{\mathbb {R}})\) satisfies the differential inequality (24) for all \(x\in I\), then there exists a solution \(y\in C^{2}(I,{\mathbb {R}})\) of (22) such that

$$\begin{aligned} |y_{\varphi }(x)-y(x)|\le \beta \left| \int _{x_{0}}^{x}\left| \mathrm{e}^{\alpha (x-t)} \sin [\beta (x-t)]\right| \varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\).

Proof

In view of the theory of ordinary differential equations, we know that \(y_{1}(x)=\mathrm{e}^{\alpha x}\cos \beta x\) and \(y_{2}(x)=\mathrm{e}^{\alpha x}\sin \beta x\) are fundamental system of solutions of the associated homogeneous linear differential equation of (22). By Theorem 3.2, the desired result can be derived. \(\square \)

In addition, as an application of Theorem 3.2, we can show the Hyers–Ulam stability of the Cauchy–Euler differential equation of second order. The general form of the nonhomogeneous Cauchy–Euler differential equation of second order is given by

$$\begin{aligned} x^2y''(x)+\mu xy'(x)+\nu y(x)=f(x), \end{aligned}$$
(25)

where \(\mu ,\nu \in {\mathbb {R}}\), \(f\in C([a,b],{\mathbb {R}})\), \(0<a<b\). The auxiliary equation is

$$\begin{aligned} \lambda ^2-(\mu -1)\lambda +\nu =0. \end{aligned}$$
(26)

The following stability results can be obtained depending on the different cases of the auxiliary Eq. (26).

Corollary 3.7

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu \in {\mathbb {R}}\) with \((\mu -1)^2-4\nu >0\), i.e., the auxiliary Eq. (25) has two distinct real roots \(\lambda _{1}\) and \(\lambda _{2}\). For a given \(\varepsilon >0\), if a twice continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| x^2y_{\varphi }''(x)+\mu xy_{\varphi }'(x)+\nu y_{\varphi }(x)-f(x)\right| \le \varepsilon \end{aligned}$$
(27)

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (25) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\frac{1}{|\lambda _{1}-\lambda _{2}|}\max _{x\in [a,b]}\int _{a}^{x} \frac{1}{t}\left| \left( \frac{x}{t}\right) ^{\lambda _{1}} -\left( \frac{x}{t}\right) ^{\lambda _{2}}\right| \mathrm{d}t. \end{aligned}$$

Proof

Notice that the inequality (27) is equivalent to

$$\begin{aligned} \left| y_{\varphi }''(x)+\frac{\mu }{x}y_{\varphi }'(x)+\frac{\nu }{x^2} y_{\varphi }(x)-\frac{f(x)}{x^2}\right| \le \frac{\varepsilon }{x^2}, \end{aligned}$$
(28)

since \(x\in [a,b]\) and \(0<a<b\). By Theorem 3.2, there exists \(y\in C^{2}([a,b],{\mathbb {R}})\) such that

$$\begin{aligned} y''(x)+\frac{\mu }{x}y'(x)+\frac{\nu }{x^2} y(x)=\frac{f(x)}{x^2} \end{aligned}$$
(29)

for all \(x\in [a,b]\). Clearly, the Eqs. (25) and (29) are equivalent. So y is also solution of (25).

Moreover, since \(\lambda _{1}\ne \lambda _{2}\), we know that \(y_{1}(x)=x^{\lambda _{1}}\) and \(y_{2}(x)=x^{\lambda _{2}}\) are fundamental system of solutions of the associated homogeneous linear differential equation of (25). Then, it follows from Theorem  3.2 and (28) that the desired inequality holds. \(\square \)

Corollary 3.8

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu \in {\mathbb {R}}\) with \((\mu -1)^2-4\nu =0\), i.e., the auxiliary Eq. (25) has two equal real roots \(\lambda _{1}=\lambda _{2}\). For a given \(\varepsilon >0\), if a twice continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality (27) for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (25) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\max _{x\in [a,b]}\int _{a}^{x}\frac{1}{t}\left| \left( \frac{x}{t}\right) ^{\lambda _{1}}\ln \left( \frac{x}{t}\right) \right| \mathrm{d}t. \end{aligned}$$

Proof

In this case, \(y_{1}(x)=x^{\lambda _{1}}\) and \(y_{2}(x)=x^{\lambda _{1}}\ln {x}\) are fundamental system of solutions of the associated homogeneous linear differential equation of (25). The proof is similar to Corollary 3.7 and so is omitted. \(\square \)

Corollary 3.9

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu \in {\mathbb {R}}\) with \((\mu -1)^2-4\nu <0\), i.e., the auxiliary Eq. (25) has a pair of complex conjugate roots \(\lambda _{1}=\alpha +i\beta \) and \(\lambda _{2}=\alpha -i\beta \), where \(\alpha \in {\mathbb {R}}\), \(\beta >0\). For a given \(\varepsilon >0\), if a twice continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality (27) for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (25) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\frac{1}{\beta }\max _{x\in [a,b]}\int _{a}^{x}\frac{1}{t}\left| \left( \frac{x}{t}\right) ^{\alpha }\sin \left[ \beta \left( \frac{x}{t}\right) \right] \right| \mathrm{d}t. \end{aligned}$$

Proof

In this case, \(y_{1}(x)=x^{\alpha }\cos (\beta \ln {x})\) and \(y_{2}(x)=x^{\alpha }\sin (\beta \ln {x})\) are fundamental system of solutions of the associated homogeneous linear differential equation of (25). The proof is similar to Corollary 3.7 and so is omitted. \(\square \)

Remark 3

In [22], the authors proved the Hyers–Ulam stability of the Eq. (25) when the auxiliary Eq. (26) has two distinct real roots and two equal real roots, respectively. But this case is not considered if the auxiliary Eq. (26) has a pair of complex conjugate roots. So Corollary 3.9 can be regarded as a supplement to [22].

4 The General Solution and Ulam Stability of Third-Order Linear Differential Equations

Using the similar argument as in Sect. 3, this section will deal with the general solution and Ulam stability of three-order linear differential equations.

The general form of the three-order nonhomogeneous linear differential equation is given by

$$\begin{aligned} y'''(x)+p(x)y''(x)+q(x)y'(x)+r(x)y(x)=f(x), \end{aligned}$$
(30)

where \(p,q,r,f\in C(I,{\mathbb {R}})\). The associated homogenous linear differential equation of (30) is

$$\begin{aligned} y'''(x)+p(x)y''(x)+q(x)y'(x)+r(x)y(x)=0. \end{aligned}$$
(31)

Let \(y_{1}(x)\), \(y_{2}(x)\) and \(y_{3}(x)\) be fundamental system of solutions of (31). Then, the general solution of (31) is \(Y(x)=\widetilde{c}_{1}y_{1}(x)+\widetilde{c}_{2}y_{2}(x)+\widetilde{c}_{3}y_{3}(x)\). By using the method of variation of parameters, we set \(y_{p}(x)=u_{1}(x)y_{1}(x)+u_{2}(x)y_{2}(x)+u_{3}(x)y_{3}(x)\), where \(u_{1}(x)\), \(u_{2}(x)\) and \(u_{3}(x)\) are three undetermined functions. In order to solve these functions, we assume that \(y_{p}(x)\) is a solution of (30). Then, we get

$$\begin{aligned} y_{p}'= & {} u_{1}y_{1}'+u_{1}'y_{1}+u_{2}y_{2}'+u_{2}'y_{2}+u_{3}y_{3}' +u_{3}'y_{3}, \end{aligned}$$
(32)
$$\begin{aligned} y_{p}''= & {} u_{1}y_{1}''+2u_{1}'y_{1}'+u_{1}''y_{1}+u_{2}y_{2}'' +2u_{2}'y_{2}'+u_{2}''y_{2}+u_{3}y_{3}''+2u_{3}'y_{3}'+u_{3}''y_{3}, \end{aligned}$$
(33)
$$\begin{aligned} y_{p}'''= & {} u_{1}y_{1}'''+3u_{1}'y_{1}''+3u_{1}''y_{1}'+u_{1}'''y_{1} +u_{2}y_{2}'''+3u_{2}'y_{2}''+3u_{2}''y_{2}'+u_{2}'''y_{2}\nonumber \\&+\,u_{3}y_{3}'''+3u_{3}'y_{3}''+3u_{3}''y_{3}'+u_{3}'''y_{3}. \end{aligned}$$
(34)

Substituting these equalities (3234) into (30), we can infer that

$$\begin{aligned} \begin{aligned}&y_{p}'''+p(x)y_{p}''+q(x)y_{p}'+r(x)y_{p}\\&\quad =\left( y_{1}'''+p(x)y_{1}''+q(x)y_{1}'+r(x)y_{1}\right) u_{1}+\left( y_{2}''' +p(x)y_{2}''+q(x)y_{2}'+r(x)y_{2}\right) u_{2}\\&\qquad +\left( y_{3}'''+p(x)y_{3}''+q(x)y_{3}'+r(x)y_{3}\right) u_{3}+p(x) \left( u_{1}''y_{1}+u_{2}''y_{2}+u_{3}''y_{3}\right. \\&\left. \qquad +\, 2u_{1}'y_{1}'+2u_{2}'y_{2}'+2u_{3}'y_{3}'\right) +q(x)\left( u_{1}'y_{1} +u_{2}'y_{2}+u_{3}'y_{3}\right) \\&\qquad +u_{1}'''y_{1}+3u_{1}''y_{1}'+3u_{1}'y_{1}''+u_{2}'''y_{2} +3u_{2}''y_{2}'+3u_{2}'y_{2}''\\&\qquad +u_{3}'''y_{1}+3u_{3}''y_{3}'+3u_{3}'y_{3}''\\&\quad =p(x)\left( u_{1}''y_{1}+u_{2}''y_{2}+u_{3}''y_{3}+2u_{1}'y_{1}'+2u_{2}'y_{2}' +2u_{3}'y_{3}'\right) +q(x)\left( u_{1}'y_{1}+u_{2}'y_{2}+u_{3}'y_{3}\right) \\&\qquad +u_{1}'''y_{1}+3u_{1}''y_{1}'+3u_{1}'y_{1}''+u_{2}'''y_{2} +3u_{2}''y_{2}'+3u_{2}'y_{2}''+u_{3}'''y_{3}+3u_{3}''y_{3}'+3u_{3}'y_{3}''\\&\quad =\left( u_{1}'y_{1}+u_{2}'y_{2}+u_{3}'y_{3}\right) ''+\left( u_{1}'y_{1}'+u_{2}'y_{2}' +u_{3}'y_{3}'\right) '+p(x)\left( u_{1}'y_{1}+u_{2}'y_{2}+u_{3}'y_{3}\right) '\\&\qquad +p(x)\left( u_{1}'y_{1}+u_{2}'y_{2}+u_{3}'y_{3}\right) +q(x)\left( u_{1}'y_{1} +u_{2}'y_{2}+u_{3}'y_{3}\right) +\left( u_{1}'y_{1}''+u_{2}'y_{2}''+u_{3}'y_{3}''\right) \\&\quad =f(x), \end{aligned} \end{aligned}$$
(35)

where for the second equal sign we have used the fact \(y_{1}\), \(y_{2}\) and \(y_{3}\) are three solutions of (31). By the foregoing hypothesis, \(y_{p}\) is only a particular solution of (30). For the sake of convenience, without loss of generality, we can assume that

$$\begin{aligned} {\left\{ \begin{array}{ll} u_{1}'y_{1}+u_{2}'y_{2}+u_{3}'y_{3}=0,\\ u_{1}'y_{1}'+u_{2}'y_{2}'+u_{3}'y_{3}=0. \end{array}\right. } \end{aligned}$$
(36)

Then, it follows from (35) that

$$\begin{aligned} u_{1}'y_{1}''+u_{2}'y_{2}''+u_{3}'y_{3}''=f(x). \end{aligned}$$
(37)

Since \(y_{1}\), \(y_{2}\) and \(y_{3}\) are fundamental system of solutions of (31), the Wronskian

$$\begin{aligned} W(y_{1},y_{2},y_{3})(x)=\left| \begin{matrix} y_{1}(x) &{}\quad y_{2}(x) &{}\quad y_{3}(x)\\ y_{1}'(x) &{}\quad y_{2}'(x) &{}\quad y_{3}'(x)\\ y_{1}''(x) &{}\quad y_{2}''(x) &{}\quad y_{3}''(x) \end{matrix}\right| \ne 0 \end{aligned}$$

for all \(x\in {I}\). Using Cramer’s rule, it follows from (36) and (37) that

$$\begin{aligned} \begin{aligned}&u_{1}'(x)=\frac{W_{1,3}(x)}{W(y_{1},y_{2},y_{3})(x)},\\&u_{2}'(x)=\frac{W_{2,3}(x)}{W(y_{1},y_{2},y_{3})(x)},\\&u_{3}'(x)=\frac{W_{3,3}(x)}{W(y_{1},y_{2},y_{3})(x)}, \end{aligned} \end{aligned}$$
(38)

where

$$\begin{aligned} \begin{aligned}&W_{1,3}(x)=\left| \begin{matrix} 0 &{}\quad y_{2}(x) &{}\quad y_{3}(x)\\ 0 &{}\quad y_{2}'(x) &{}\quad y_{3}'(x)\\ f(x) &{}\quad y_{2}''(x) &{}\quad y_{3}''(x) \end{matrix}\right| ,\\&W_{2,3}(x)=\left| \begin{matrix} y_{1}(x) &{}\quad 0 &{}\quad y_{3}(x)\\ y_{1}'(x) &{}\quad 0 &{}\quad y_{3}'(x)\\ y_{1}''(x) &{}\quad f(x) &{}\quad y_{3}''(x) \end{matrix}\right| ,\\&W_{3,3}(x)=\left| \begin{matrix} y_{1}(x) &{}\quad y_{2}(x) &{}\quad 0\\ y_{1}'(x) &{}\quad y_{2}'(x) &{}\quad 0\\ y_{1}''(x) &{}\quad y_{2}''(x) &{}\quad f(x) \end{matrix}\right| . \end{aligned} \end{aligned}$$

By integrating both sides of (38) from \(x_{0}\) to x with respect to t, then we can obtain

$$\begin{aligned} \begin{aligned}&u_{1}(x)={\widehat{c}}_{1}+\int _{x_{0}}^{x}\frac{W_{1,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t,\\&u_{2}(x)={\widehat{c}}_{2}+\int _{x_{0}}^{x}\frac{W_{2,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t,\\&u_{3}(x)={\widehat{c}}_{3}+\int _{x_{0}}^{x}\frac{W_{3,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t, \end{aligned} \end{aligned}$$

where \({\widehat{c}}_{1}\), \({\widehat{c}}_{2}\) and \({\widehat{c}}_{3}\) are three arbitrary constants. Thus, we get

$$\begin{aligned} \begin{aligned} y_{p}(x)&=u_{1}(x)y_{1}(x)+u_{2}(x)y_{2}(x)+u_{3}(x)y_{3}(x)\\&={\widehat{c}}_{1}y_{1}(x)+{\widehat{c}}_{2}y_{2}(x)+{\widehat{c}}_{3}y_{3} (x)+y_{1}(x)\int _{x_{0}}^{x}\frac{W_{1,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t\\&\quad +y_{2}(x)\int _{x_{0}}^{x}\frac{W_{2,3}(t)}{W(y_{1},y_{2}, y_{3})(t)}\mathrm{d}t++y_{3}(x)\int _{x_{0}}^{x}\frac{W_{3,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t. \end{aligned} \end{aligned}$$

Based on the above argument, we can obtain the following result.

Theorem 4.1

Let \(p,q,r,f\in C(I,{\mathbb {R}})\) and let \(y_{1}(x)\), \(y_{2}(x)\) and \(y_{3}(x)\) be fundamental system of solutions of (31). Then, the general solution y(x) of (30) can be given by

$$\begin{aligned} \begin{aligned} y(x)&=Y(x)+y_{p}(x)\\&=c_{1}y_{1}(x)+c_{2}y_{2}(x)+c_{3}y_{3}(x)+y_{1}(x)\int _{x_{0}}^{x} \frac{W_{1,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t\\&\quad +y_{2}(x)\int _{x_{0}}^{x}\frac{W_{2,3}(t)}{W(y_{1},y_{2},y_{3}) (t)}\mathrm{d}t+y_{3}(x)\int _{x_{0}}^{x}\frac{W_{3,3}(t)}{W(y_{1},y_{2},y_{3})(t)}\mathrm{d}t, \end{aligned} \end{aligned}$$

where \(c_{1}\), \(c_{2}\) and \(c_{3}\) are three arbitrary constants, \(x_{0}\in {I}\) is an arbitrary fixed point.

By Theorem 4.1, we shall discuss the Ulam stability of the three-order nonhomogeneous linear differential Eq. (30).

Theorem 4.2

Let \(p,q,r,f\in C(I,{\mathbb {R}})\) and let \(y_{1}(x)\), \(y_{2}(x)\) and \(y_{3}(x)\) be fundamental system of solutions of (31). Assume that \(\varphi :I\rightarrow [0,+\infty )\) is a continuous function. If \(y_{\varphi }\in C^{3}(I,{\mathbb {R}})\) satisfies the differential inequality

$$\begin{aligned} \left| y_{\varphi }'''(x)+p(x)y_{\varphi }''(x)+q(x)y_{\varphi }'(x) +r(x)y_{\varphi }(x)-f(x)\right| \le \varphi (x) \end{aligned}$$

for all \(x\in I\), then there exists \(y\in C^{3}(I,{\mathbb {R}})\) such that y(x) satisfies (30) and

$$\begin{aligned} |y_{\varphi }(x)-y(x)|\le \left| \int _{x_{0}}^{x}\left| \frac{W(y_{1},y_{2},y_{3}) (t,t,x)}{W(y_{1},y_{2},y_{3})(t)}\right| \varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\), where

$$\begin{aligned} W(y_{1},y_{2},y_{3})(t,t,x)=\left| \begin{matrix} y_{1}(t) &{}\quad y_{2}(t) &{}\quad y_{3}(t)\\ y_{1}'(t) &{}\quad y_{2}'(t) &{}\quad y_{3}'(t)\\ y_{1}(x) &{}\quad y_{2}(x) &{}\quad y_{3}(x) \end{matrix}\right| . \end{aligned}$$

Proof

Using the same argument as in the proof of Theorem 3.2, we can easily carry out the proof of this theorem. \(\square \)

In particular, we can obtain the Hyers–Ulam stability of (30) when \(I=[a,b]\) be a finite closed interval.

Corollary 4.3

Let \(p,q,r,f\in C([a,b],{\mathbb {R}})\). For a given \(\varepsilon >0\), if a three times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| y_{\varphi }'''(x)+p(x)y_{\varphi }''(x)+q(x)y_{\varphi }'(x)+r(x)y_{\varphi } (x)-f(x)\right| \le \varepsilon \end{aligned}$$

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (30) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\max _{x\in [a,b]}\int _{a}^{x}\left| \frac{W(y_{1},y_{2},y_{3})(t,t,x)}{W(y_{1},y_{2},y_{3})(t)}\right| \mathrm{d}t. \end{aligned}$$

According to Theorem 4.2, we can obtain the Ulam stability of third-order nonhomogeneous linear differential equations with constant coefficients. The general form of the differential equation is given by

$$\begin{aligned} y'''(x)+\gamma y''(x)+\delta y'(x)+\eta y(x)=f(x), \end{aligned}$$
(39)

where \(\gamma ,\delta ,\eta \) are real constants, \(f\in C(I,{\mathbb {R}})\). The corresponding characteristic equation is

$$\begin{aligned} \lambda ^{3}+\gamma \lambda ^{2}+\delta \lambda +\eta =0. \end{aligned}$$
(40)

By distinguishing various roots of the characteristic equation, the following results can be obtained.

Corollary 4.4

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (40) has three distinct real roots \(\lambda _{1}\), \(\lambda _{2}\) and \(\lambda _{3}\). If \(y_{\varphi }\in C^{3}(I,{\mathbb {R}})\) satisfies the differential inequality

$$\begin{aligned} \left| y_{\varphi }'''(x)+\gamma y_{\varphi }''(x)+\delta y_{\varphi }'(x)+\eta y_{\varphi }'(x)-f(x)\right| \le \varphi (x) \end{aligned}$$
(41)

for all \(x\in I\), then there exists a solution \(y\in C^{3}(I,{\mathbb {R}})\) of (39) such that

$$\begin{aligned} \begin{aligned} |y_{\varphi }(x)-y(x)|&\le \frac{1}{|(\lambda _{1}-\lambda _{2})(\lambda _{1}-\lambda _{3}) (\lambda _{2}-\lambda _{3})|}\Bigg |\int _{x_{0}}^{x}\Bigg |\lambda _{1} \left( \mathrm{e}^{\lambda _{3}(x-t)}-\mathrm{e}^{\lambda _{2}(x-t)}\right) \\&\quad +\lambda _{2}\left( \mathrm{e}^{\lambda _{1} (x-t)}-\mathrm{e}^{\lambda _{3}(x-t)}\right) +\lambda _{3}\left( \mathrm{e}^{\lambda _{2}(x-t)}-\mathrm{e}^{\lambda _{1}(x-t)}\right) \Bigg |\varphi (t)\mathrm{d}t\Bigg | \end{aligned} \end{aligned}$$

for all \(x\in {I}\).

Proof

The proof is quite similar to the proof of Corollary 3.3 and so is omitted. \(\square \)

Corollary 4.5

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (40) has three real roots \(\lambda _{1}\), \(\lambda _{2}\) and \(\lambda _{3}\) with \(\lambda _{1}=\lambda _{2}\ne \lambda _{3}\). If \(y_{\varphi }\in C^{3}(I,{\mathbb {R}})\) satisfies the differential inequality (41) for all \(x\in I\), then there exists a solution \(y\in C^{3}(I,{\mathbb {R}})\) of (39) such that

$$\begin{aligned} |y_{\varphi }(x)-y(x)|\le \frac{1}{(\lambda _{1}-\lambda _{3})^2} \left| \int _{x_{0}}^{x}\left| \left[ \left( \lambda _{1}-\lambda _{3}\right) (x-t)-1\right] \left( \mathrm{e}^{\lambda _{1}(x-t)}+\mathrm{e}^{\lambda _{3}(x-t)}\right) \right| \varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\).

Corollary 4.6

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (40) has three real roots \(\lambda _{1}\), \(\lambda _{2}\) and \(\lambda _{3}\) with \(\lambda _{1}=\lambda _{2}=\lambda _{3}\). If \(y_{\varphi }\in C^{3}(I,{\mathbb {R}})\) satisfies the differential inequality (41) for all \(x\in I\), then there exists a solution \(y\in C^{3}(I,{\mathbb {R}})\) of (39) such that

$$\begin{aligned} |y_{\varphi }(x)-y(x)|\le \frac{1}{2}\left| \int _{x_{0}}^{x}(x-t) ^2\mathrm{e}^{\lambda _{1}(x-t)}\varphi (t)\mathrm{d}t\right| \end{aligned}$$

for all \(x\in {I}\).

Corollary 4.7

Let \(\varphi :I\rightarrow [0,+\infty )\) be a continuous function. Assume that the characteristic Eq. (40) has a real root \(\lambda _{1}\) and a pair of complex conjugate roots \(\lambda _{2}=\alpha +i\beta \), \(\lambda _{3}=\alpha -i\beta \), where \(\alpha \in {\mathbb {R}}\), \(\beta >0\). If \(y_{\varphi }\in C^{3}(I,{\mathbb {R}})\) satisfies the differential inequality (41) for all \(x\in I\), then there exists a solution \(y\in C^{3}(I,{\mathbb {R}})\) of (39) such that

$$\begin{aligned} \begin{aligned} |y_{\varphi }(x)-y(x)|&\le \frac{1}{\beta [\beta ^2+(\alpha -\lambda _{1})^2]}\left| \int _{x_{0}}^{x}\right| \beta {\mathrm{e}^{\lambda _{1}(x-t)}}-\mathrm{e}^{\alpha (x-t)} \left( \beta \cos [\beta (x-t)]\right. \\&\left. \quad +\,(\alpha -\lambda )\sin [\beta (x-t)]\right) \left| \varphi (t)\mathrm{d}t\right| \end{aligned} \end{aligned}$$

for all \(x\in {I}\).

Moreover, we can infer from Theorem 4.2 that the Cauchy–Euler differential equation of third order is Hyers–Ulam stable. The general form of the nonhomogeneous Cauchy–Euler differential equation of third order is given by

$$\begin{aligned} x^3y'''(x)+\mu x^2y''(x)+\nu xy'(x)+\omega y(x)=f(x), \end{aligned}$$
(42)

where \(\mu ,\nu ,\omega \in {\mathbb {R}}\), \(f\in C([a,b],{\mathbb {R}})\), \(0<a<b\). The auxiliary equation is

$$\begin{aligned} \lambda ^3+(\mu -3)\lambda ^2+(\nu -\mu +2)\lambda +\omega =0. \end{aligned}$$
(43)

The following stability results can be obtained depending on the different cases of the auxiliary Eq. (43).

Corollary 4.8

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu ,\omega \in {\mathbb {R}}\). Assume that the auxiliary Eq. (43) has three distinct real roots \(\lambda _{1}\),\(\lambda _{2}\) and \(\lambda _{3}\). For a given \(\varepsilon >0\), if a three times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| x^3y_{\varphi }'''(x)+\mu x^2y_{\varphi }''(x)+\nu xy_{\varphi }'(x)+\omega y_{\varphi }(x)-f(x)\right| \le \varepsilon \end{aligned}$$
(44)

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (42) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} \begin{aligned} K&=\frac{1}{|(\lambda _{1}-\lambda _{2})(\lambda _{2}-\lambda _{3}) (\lambda _{3}-\lambda _{1})|}\max _{x\in [a,b]}\int _{a}^{x}\frac{1}{t}\left| (\lambda _{1}-\lambda _{2})\left( \frac{x}{t}\right) ^{\lambda _{3}}\right. \\&\left. \quad +\,\,(\lambda _{2}-\lambda _{3})\left( \frac{x}{t}\right) ^{\lambda _{1}}+ (\lambda _{3}-\lambda _{1})\left( \frac{x}{t}\right) ^{\lambda _{2}}\right| \mathrm{d}t. \end{aligned} \end{aligned}$$

Proof

Using the same argument as in Corollary 3.7, the desired result can be derived by Theorem 4.2. \(\square \)

Corollary 4.9

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu ,\omega \in {\mathbb {R}}\). Assume that the auxiliary Eq. (43) has a single root \(\lambda _{1}\) and a double root \(\lambda _{2}\). For a given \(\varepsilon >0\), if a three times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality (44) for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (42) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\frac{1}{(\lambda _{1}-\lambda _{2})^2}\max _{x\in [a,b]}\int _{a}^{x} \frac{1}{t}\left| \left( \frac{x}{t}\right) ^{\lambda _{1}}-\left( \frac{x}{t}\right) ^{\lambda _{2}}+\left( \lambda _{2}-\lambda _{1}\right) \left( \frac{x}{t}\right) ^{\lambda _{2}}\ln \frac{x}{t}\right| \mathrm{d}t. \end{aligned}$$

Corollary 4.10

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu ,\omega \in {\mathbb {R}}\). Assume that the auxiliary Eq. (43) has a triple root \(\lambda _{1}\). For a given \(\varepsilon >0\), if a three times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality (44) for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (42) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\frac{1}{2}\max _{x\in [a,b]}\int _{a}^{x}\frac{1}{t}\left( \frac{x}{t} \right) ^{\lambda _{1}}\ln ^2\frac{x}{t}\mathrm{d}t. \end{aligned}$$

Corollary 4.11

Let \(f\in C([a,b],{\mathbb {R}})\) and let \(\mu ,\nu ,\omega \in {\mathbb {R}}\). Assume that the auxiliary Eq. (43) has a real root \(\lambda _{1}\) and a pair of complex conjugate roots \(\lambda _{2}=\alpha +i\beta \), \(\lambda _{3}=\alpha -i\beta \), where \(\alpha \in {\mathbb {R}}\), \(\beta >0\). For a given \(\varepsilon >0\), if a three times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality (44) for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (42) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} \begin{aligned} K&=\frac{1}{\beta [(\alpha -\lambda _{1})^2+\beta ^2]}\max _{x\in [a,b]} \int _{a}^{x}\frac{1}{t}\left| \beta \left( \frac{x}{t}\right) ^{\lambda _{1}} -\left( \frac{x}{t}\right) ^{\alpha }\left[ \beta \cos \left( \beta \ln \frac{x}{t} \right) \right. \right. \\&\left. \left. \quad +\,(\lambda _{1}-\alpha )\sin \left( \beta \ln \frac{x}{t}\right) \right] \right| \mathrm{d}t. \end{aligned} \end{aligned}$$

5 The General Solution and Ulam Stability of n-th Order Linear Differential Equations

More generally, in this section, we will consider the Ulam stability of n-th order linear differential equations.

The general form of the n-th order nonhomogeneous linear differential equation is given by

$$\begin{aligned} y^{(n)}(x)+p_{n-1}(x)y^{(n-1)}(x)+\cdots +p_{1}(x)y'(x)+p_{0}(x)y(x)=f(x), \end{aligned}$$
(45)

where \(p_{k},f\in C(I,{\mathbb {R}})\), \(k=0,1,\ldots ,n-1\), \(n\ge 2\). The corresponding homogeneous linear differential equation of (45) is

$$\begin{aligned} y^{(n)}(x)+p_{n-1}(x)y^{(n-1)}(x)+\cdots +p_{1}(x)y'(x)+p_{0}(x)y(x)=0. \end{aligned}$$
(46)

Let \(y_{1}(x),y_{2}(x),\ldots ,y_{n}(x)\) be fundamental system of solutions of (46). It is well known that the general solution of (45) is

$$\begin{aligned} Y(x)=\widetilde{c}_{1}y_{1}(x)+\widetilde{c}_{2}y_{2}(x)+\cdots + \widetilde{c}_{n}y_{n}(x), \end{aligned}$$

where \(\widetilde{c}_{1},\widetilde{c}_{2},\ldots ,\widetilde{c}_{n}\) are arbitrary constants. Using the method of variation of parameters, we can replace \(\widetilde{c}_{1},\widetilde{c}_{2},\ldots ,\widetilde{c}_{n}\) by the undetermined functions \(u_{1}(x),u_{2}(x),\)\(\ldots ,u_{n}(x)\), respectively. Then, we set

$$\begin{aligned} y_{p}(x)=u_{1}(x)y_{1}(x)+u_{2}(x)y_{2}(x)+\cdots +u_{n}(x)y_{n}(x). \end{aligned}$$

To determine these functions, we assume that \(y_{p}\) is a solution of (45). Thus, we have

$$\begin{aligned} y_{p}'=\sum _{k=1}^{n}\left( u_{k}'y_{k}+u_{k}y_{k}'\right) . \end{aligned}$$

In order to conveniently compute the second derivative of \(y_{p}\), we can assume

$$\begin{aligned} \sum _{k=1}^{n}u_{k}'y_{k}=u_{1}'y_{1}+u_{2}'y_{2}+\cdots +u_{n}'y_{n}=0. \end{aligned}$$

Furthermore, we can obtain

$$\begin{aligned} y_{p}''=\sum _{k=1}^{n}\left( u_{k}'y_{k}'+u_{k}y_{k}''\right) . \end{aligned}$$

Similarly, if we assume

$$\begin{aligned} \sum _{k=1}^{n}u_{k}'y_{k}'=u_{1}'y_{1}'+u_{2}'y_{2}'+\cdots +u_{n}'y_{n}'=0. \end{aligned}$$

Then, we have

$$\begin{aligned} y_{p}'''=\sum _{k=1}^{n}\left( u_{k}'y_{k}''+u_{k}y_{k}'''\right) . \end{aligned}$$

Continuing in this manner, in general, we arrive at the following hypothesis and the corresponding derivative.

$$\begin{aligned} \begin{aligned} \sum _{k=1}^{n}u_{k}'y_{k}^{(n-2)}&=u_{1}'y_{1}^{(n-2)} +u_{2}'y_{2}^{(n-2)}+\cdots +u_{n}'y_{n}^{(n-2)}=0,\\ y_{p}^{(n)}&=\sum _{k=1}^{n}\left( u_{k}'y_{k}^{(n-1)}+u_{k}y_{k}^{(n)}\right) . \end{aligned} \end{aligned}$$
(47)

Under these assumptions, by substituting \(y_{p}\) and its derivatives up to n into (45), we can infer that

$$\begin{aligned} \sum _{k=1}^{n}u_{k}'y_{k}^{(n-1)}=u_{1}'y_{1}^{(n-1)}+u_{2}'y_{2}^ {(n-1)}+\cdots +u_{n}'y_{n}^{(n-1)}=f(x). \end{aligned}$$

Combining (47) with the previous assumptions gives the following system of linear equations

$$\begin{aligned} {\left\{ \begin{array}{ll} u_{1}'y_{1}+u_{2}'y_{2}+\cdots +u_{n}'y_{n}=0\\ u_{1}'y_{1}'+u_{2}'y_{2}'+\cdots +u_{n}'y_{n}'=0\\ \cdots \cdots \\ u_{1}'y_{1}^{(n-1)}+u_{2}'y_{2}^{(n-1)}+\cdots +u_{n}'y_{n}^{(n-1)}=f(x) \end{array}\right. }. \end{aligned}$$

Notice that \(y_{1},y_{2},\ldots ,y_{n}\) are fundamental system of solutions of (46). Then, the Wronskian

$$\begin{aligned} W(y_{1},y_{2},\ldots ,y_{n})(x)=\left| \begin{matrix} y_{1}(x) &{}\quad y_{2}(x) &{}\quad \cdots &{}\quad y_{n}(x)\\ y_{1}'(x) &{}\quad y_{2}'(x) &{}\quad \cdots &{}\quad y_{n}'(x)\\ \vdots &{}\quad \vdots &{}\quad &{}\quad \vdots \\ y_{1}^{(n-1)}(x) &{}\quad y_{2}^{(n-1)}(x) &{}\quad \cdots &{}\quad y_{n}^{(n-1)}(x) \end{matrix}\right| \ne 0 \end{aligned}$$

for all \(x\in {I}\). Using Cramer’s rule, it follows that

$$\begin{aligned} u_{k}'(x)=\frac{W_{k,n}(x)}{W(y_{1},y_{2},\ldots ,y_{n})(x)}, k=1,2,\ldots ,n, \end{aligned}$$

where \(W_{k,n}(x)\) is the determinant of n order obtained by replacing the k-th column of the Wronskian by the n dimensional column vector \((0,0,\ldots ,0,f(x))^\mathrm{T}\).

By integrating both sides of (45) from \(x_{0}\) to x with respect to t, then we can infer that

$$\begin{aligned} u_{k}(x)={\widehat{c}}_{k}+\int _{x_{0}}^{x}\frac{W_{k,n}(t)}{W(y_{1},y_{2},\ldots ,y_{n})(t)}\mathrm{d}t, \end{aligned}$$

where \({\widehat{c}}_{k},\,\,k=1,2,\ldots ,n\) are arbitrary constants. Therefore, we can obtain

$$\begin{aligned} \begin{aligned} y_{p}(x)&=\sum _{k=1}^{n}u_{k}(x)y_{k}(x)\\&=\sum _{k=1}^{n}{\widehat{c}}_{k}y_{k}(x)+\sum _{k=1}^{n}\int _{x_{0}} ^{x}\frac{y_{k}(x)W_{k,n}(t)}{W(y_{1},y_{2},\ldots ,y_{n})(t)}\mathrm{d}t. \end{aligned} \end{aligned}$$

Based on the preceding argument, the general solution of the n-th order nonhomogeneous linear differential Eq. (45) can be obtained.

Theorem 5.1

Let \(p_{k},f\in C(I,{\mathbb {R}})\), \(k=1,2,\ldots ,n-1\), and let \(y_{1}(x),y_{2}(x),\ldots ,y_{n}(x)\) be fundamental system of solutions of (46). Then, the general solution y(x) of (45) can be given by

$$\begin{aligned} \begin{aligned} y(x)&=Y(x)+y_{p}(x)\\&=\sum _{k=1}^{n}c_{k}y_{k}(x)+\sum _{k=1}^{n}\int _{x_{0}}^{x} \frac{y_{k}(x)W_{k,n}(t)}{W(y_{1},y_{2},\ldots ,y_{n})(t)}\mathrm{d}t, \end{aligned} \end{aligned}$$

where \(c_{k},\,\,k=1,2,\ldots ,n\) are arbitrary constants, \(x_{0}\in {I}\) is an arbitrary fixed point.

According to Theorem 5.1, the Ulam stability of the n-th order linear differential Eq. (45) can be derived.

Theorem 5.2

Let \(p_{k},f\in C(I,{\mathbb {R}})\), \(k=1,2,\ldots ,n-1\), and let \(y_{1}(x),y_{2}(x),\ldots ,y_{n}(x)\) be fundamental system of solutions of (46). Assume that \(\varphi :I\rightarrow [0,+\infty )\) is a continuous function. If \(y_{\varphi }\in C^{n}(I,{\mathbb {R}})\) satisfies the differential inequality

$$\begin{aligned} \left| y_{\varphi }^{(n)}(x)+\sum _{k=1}^{n}p_{n-k}(x)y_{\varphi }^{(n-k)} (x)-f(x)\right| \le \varphi (x) \end{aligned}$$

for all \(x\in I\), then there exists \(y\in C^{n}(I,{\mathbb {R}})\) such that y(x) satisfies (45) and

$$\begin{aligned} |y_{\varphi }(x)-y(x)|\le \left| \int _{x_{0}}^{x}\left| \frac{W(y_{1},y_{2}, \cdots ,y_{n})\left( \overbrace{t,\ldots ,t}^{n-1},x\right) }{W\left( y_{1},y_{2},\ldots ,y_{n}\right) (t)}\right| \varphi (t)\mathrm{d}t\right| \end{aligned}$$
(48)

for all \(x\in {I}\), where

$$\begin{aligned} W(y_{1},y_{2},\ldots ,y_{n})(\underbrace{t,\ldots ,t}_{n-1},x)=\left| \begin{matrix} y_{1}(t) &{}\quad y_{2}(t) &{}\quad \cdots &{}\quad y_{n}(t)\\ y_{1}'(t) &{}\quad y_{2}'(t) &{}\quad \cdots &{}\quad y_{n}'(t)\\ \vdots &{}\quad \vdots &{}\quad &{}\quad \vdots \\ y_{1}^{(n-2)}(t) &{}\quad y_{2}^{(n-2)}(t) &{}\quad \cdots &{}\quad y_{n}^{(n-2)}(t)\\ y_{1}(x) &{}\quad y_{2}(x) &{}\quad \cdots &{}\quad y_{n}(x) \end{matrix}\right| . \end{aligned}$$

Proof

Using the same argument as in Theorem 3.2, we set

$$\begin{aligned} y_{\varphi }^{(n)}(x)+\sum _{k=1}^{n}p_{n-k}(x)y_{\varphi }^{(n-k)}(x) :=f_{\varphi }(x). \end{aligned}$$

By Theorem 5.1, there exist \(c_{1},c_{2},\ldots ,c_{n}\) such that

$$\begin{aligned} y_{\varphi }(x)=\sum _{k=1}^{n}c_{k}y_{k}(x)+\sum _{k=1}^{n}\int _{x_{0}} ^{x}\frac{y_{k}(x)\widetilde{W}_{k,n}(t)}{W(y_{1},y_{2},\ldots ,y_{n})(t)}\mathrm{d}t, \end{aligned}$$
(49)

where \(\widetilde{W}_{k,n}(x)\) is the determinant of n-th order obtained by replacing the k-th column of the Wronskian by the n dimensional column vector \((0,0,\ldots ,0,f_{\varphi }(x))^\mathrm{T}\).

Define

$$\begin{aligned} y(x)=\sum _{k=1}^{n}c_{k}y_{k}(x)+\sum _{k=1}^{n}\int _{x_{0}}^{x} \frac{y_{k}(x)W_{k,n}(t)}{W(y_{1},y_{2},\ldots ,y_{n})(t)}\mathrm{d}t. \end{aligned}$$
(50)

By the property of the determinant, we get

$$\begin{aligned}&\sum _{k=1}^{n}\left( y_{k}(x)\widetilde{W}_{k,n}(t)-y_{k}(x)W_{k,n}(t)\right) \\&\quad =\sum _{k=1}^{n}y_{k}(x)(-1)^{k+n}f_{\varphi }(x)M_{k,n}(t)-y_{k}(x)(-1) ^{k+n}f(x)M_{k,n}(t)\\&\quad =(f_{\varphi }(x)-f(x))\sum _{k=1}^{n}(-1)^{k+n}y_{k}(x)M_{k,n}(t)\\&\quad =(f_{\varphi }(x)-f(x))W(y_{1},y_{2},\ldots ,y_{n})(\underbrace{t,\ldots ,t}_ {n-1},x), \end{aligned}$$

where \(M_{k,n}(t)\) is the cofactor of the element \(f_{\varphi }(x)\) in the determinant \(\widetilde{W}_{k,n}(t)\). Obviously, it is the same as the cofactor of the element f(x) in the determinant \(W_{k,n}(t)\).

Therefore, the desired inequality (48) can be derived from (49), (50) and the above equality. The proof of the theorem is now completed. \(\square \)

Similar to Corollary 4.3, the Hyers–Ulam stability of the n-th order nonhomogeneous linear differential Eq. (45) can be derived from Theorem 5.2.

Corollary 5.3

Let \(p_{k},f\in C(I,{\mathbb {R}})\), \(k=1,2,\ldots ,n-1\). For a given \(\varepsilon >0\), if an n times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| y_{\varphi }^{(n)}(x)+\sum _{k=1}^{n}p_{n-k}(x)y_{\varphi }^{(n-k)} (x)-f(x)\right| \le \varepsilon \end{aligned}$$

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (45) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\max _{x\in [a,b]}\int _{a}^{x}\left| \frac{W\left( y_{1},y_{2},\ldots ,y_{n}\right) \left( \overbrace{t,\ldots ,t}^{n-1},x\right) }{W\left( y_{1},y_{2},\ldots ,y_{n}\right) (t)}\right| \mathrm{d}t. \end{aligned}$$

Remark 4

In the theory of Ulam stability, the optimal Hyers–Ulam constant K is the minimum positive real number such that the error inequality \(|y_{\varepsilon }(x)-y(x)|\le K\varepsilon \) holds for all \(x\in I\). It can be easily seen from the proofs of the main theorems that each Hyers–Ulam constant K is optimal in Corollaries 3.3, 4.3 and 5.3.

Finally, by Theorem 5.2, we can obtain the Hyers–Ulam stability of the Cauchy–Euler differential equation of n-th order. For simplicity, the general form of the nonhomogeneous Cauchy–Euler differential equation of n-th order is given as follows:

$$\begin{aligned} x^n y^{(n)}(x)+\sum _{k=1}^{n}\mu _{n-k}x^{n-k}y^{(n-k)}(x)=f(x), \end{aligned}$$
(51)

where \(\mu _{k}\in {\mathbb {R}},\,\,(k=1,2,\ldots ,n)\), \(f\in C([a,b],{\mathbb {R}})\) with \(0<a<b\).

Corollary 5.4

Let \(y_{1}(x),y_{2}(x),\ldots ,y_{n}(x)\) be fundamental system of solutions of the associated homogeneous equation of (51). For a given \(\varepsilon >0\), if an n times continuously differentiable function \(y_{\varepsilon }:[a,b]\rightarrow {\mathbb {R}}\) satisfies the following inequality

$$\begin{aligned} \left| x^n y_{\varphi }^{(n)}(x)+\sum _{k=1}^{n}\mu _{n-k}x^{n-k}y_{\varphi }^{(n-k)}(x)-f(x)\right| \le \varepsilon \end{aligned}$$

for all \(x\in [a,b]\), then there exists a solution \(y:[a,b]\rightarrow {\mathbb {R}}\) of (51) such that

$$\begin{aligned} |y_{\varepsilon }(x)-y(x)|\le K\varepsilon \end{aligned}$$

for all \(x\in [a,b]\), where

$$\begin{aligned} K=\max _{x\in [a,b]}\int _{a}^{x}\frac{1}{t^{n}}\left| \frac{W\left( y_{1},y_{2}, \cdots ,y_{n}\right) \left( \overbrace{t,\ldots ,t}^{n-1},x\right) }{W\left( y_{1},y_{2},\ldots ,y_{n}\right) (t)}\right| \mathrm{d}t. \end{aligned}$$

Proof

By Theorem 5.2, the proof is a direct extension of Corollary 3.7 and so is omitted. \(\square \)

6 Conclusions

By using the method of variation of parameters, in this paper, we have established the Ulam stability of linear differential equations of first order, second order, third order and n-th order, respectively. This paper presented a unified method to study the Ulam stability problem of linear differential equations of first order and higher order with constant and nonconstant coefficients. Accordingly, the Hyers–Ulam stability of linear differential equations can be directly derived from the main results. Moreover, the stability constant obtained in this paper is optimal. In particular, the Hyers–Ulam stability of the Cauchy–Euler differential equations of second order, third order and n-th order can also be obtained by the relevant conclusions.