1 Introduction

It’s been about 80 years since professor Ulam posed the stability problem before the Mathematics Club of the University of Wisconsin [1]. When concerning a proposition, Ulam asked whether its assertion still holds, or approximately holds, if we change the hypothesis “a little”. This is a very interesting and meaningful question in various science fields and stimulated lots of people to study it. We now call it Hyers–Ulam stability problem.

At first, the stability was concerned with group homomorphisms. Only one year later, D.H. Hyers [2] worked out the question related to the additive mappings between Banach spaces by an application of the “contraction mapping theorem”. He proved that corresponding to any \(\varepsilon >0\), there is a \(\delta >0\) such that if \(\|f(x+y)-f(x)-f(y)\|<\delta \), then there is an additive mapping \(l(x)\) with \(\|f(x)-l(x) \| \leq \varepsilon \). It was the first important breakthrough which led to various studies on Ulam’s problem in different forms and by different methods. In 1978, Rassias [3] generalized the results of Hyers. He used a dominant function to control the estimate instead of a positive constant, and this case this is usually called Hyers–Ulam–Rassias stability problem, or generalized Hyers–Ulam stability problem.

Over the past decades, numerous papers on Hyers–Ulam stability have been published, especially in ordinary differential equations (ODEs) [48]. There are fruitful results in ODEs, including linear and nonlinear equations.

On the other hand, fractional calculus has achieved great success owing to its applications in biology, dynamics, engineering, signal processing, and many other fields [913]. The history of fractional calculus is approximately as old as classical calculus. The concept was mentioned in L’Hospital’s letter written to Leibniz in 1695. Since then, many mathematicians began to study it, and many definitions of fractional derivatives have been posed [1418], including those published in recent years [1921].

There are also more and more papers studying the Hyers–Ulam stability relevant to fractional differential equations (FDEs) recently. The theories of existence, uniqueness, and Hyers–Ulam stability(EUH) in many types of FDEs have been established. For example, in 2017, Arshad Ali et al. [22] investigated the EUH of a kind of implicit impulsive FDEs with certain boundary conditions. In 2018, Kamal Shah et al. [23] established the existence theory to a kind of boundary value problem of FDEs and analyzed the Hyers–Ulam stability for numerical solutions. In [24], Hasib Khan et al. analyzed the existence of a positive solution and the Hyers–Ulam stability of the nonlinear singular FDEs with p-Laplacian. In [25], Wang et al. studied the EUH of some fractional evolution equations. In [26], Hasib Khan et al. established the stability of the fractional order nonlinear Klein–Gordon equations. There are also many other relevant results, see [2733].

Among all definitions of fractional derivatives, two types of them have a prominent position: Riemann–Liouville and Caputo. In the study of FDEs, many theorems in connection with Hyers–Ulam stability have been proved in Caputo sense. Wang JinRong et al. [3437] obtained many good results, after studying the Hyers–Ulam stability of different FDEs with Caputo derivatives, such as the following equations:

$$\begin{aligned}& {}^{C} D^{\alpha } x(t)=f\bigl(t, x(t)\bigr), \quad t \in [a, b), b=+\infty , \\& {}^{C} D^{\alpha } x(t)=f\bigl(t, x(t)\bigr), \quad t \in [a, b), b< +\infty , \\& {}^{C} D^{\alpha } x(t)=-A x(t)+f\bigl(t, x(t)\bigr), \quad \alpha \in (0,1), t \in I:[0,b] \subset \mathbb{R}, \\& {}^{C} D^{\beta } \bigl({}^{C} D^{\alpha }+\lambda \bigr) x(t)=f\bigl(t, x(t)\bigr), \quad t \in J:=[0,1], \end{aligned}$$

where \({}^{C} D^{\alpha }\), \({}^{C} D^{\beta }\) denote the Caputo derivatives (see Definition 2.1).

In 2016, Shen and Chen [38] solved the stability problem of the following linear fractional differential equations with constant coefficients by using Laplace transform method:

$$ \bigl(D^{\alpha }y\bigr) (t)-\lambda y(t)=f(t), $$

where \(D^{\alpha }\) denotes the Riemann–Liouville derivative (see Definition 2.1).

In this paper, we will establish the Hyers–Ulam stability of the following linear fractional differential equations with variable coefficients under certain restrictions on \(p(t)\):

$$ \textstyle\begin{cases} (D^{\alpha } x )(t)+p(t) x(t)=h(t), \quad t \in J, \\ ( (D^{n-j} I^{n-\alpha } x )(0)=x_{j}, \quad j=1, \ldots , n \end{cases} $$
(1)

and

$$ \textstyle\begin{cases} ({}^{C} D^{\alpha }x)(t)+p(t) x(t)=h(t), \quad t \in J, \\ x^{(k)}(0)=x_{k}, \quad k=0,1,\dots ,n-1,\end{cases} $$
(2)

where \(D^{\alpha }\), \({}^{C} D^{\alpha }\), \(I^{\alpha }\) denote the fractional Riemann–Liouville and Caputo derivatives, as well as Riemann–Liouville fractional integral, respectively, where \(n-1<\alpha <n\), \(n\in \mathbb{N}\), \(J=[0,b]\) is a finite interval, \(p(t)\), \(h(t)\) are given continuous functions, \(x(t)\) is an unknown function on J and \(x_{j}\), \(j=1, \ldots ,n\), are the given initial values. This is a kind of Cauchy problem [14, 15]. According to the theorems of linear FDEs [1416], there are unique continuous solutions for both equations (1) and (2).

2 Definitions, notations, and auxiliary propositions

In this section, we will introduce some definitions, notations, and auxiliary propositions. Most of the results in this section can be found in [14, 15, 17, 18, 39, 40] and you can refer to these sources for more details. Throughout this paper, t, u always denote the variables and \(n-1<\alpha <n\) (\(n\in \mathbb{N}\)) is a positive, noninteger real number (unless otherwise specified).

Motivated by [38, 41], we want to invoke the following Gronwall’s inequality to solve the Hyers–Ulam stability of equations (1) and (2).

Lemma 2.1

(Gronwall’s inequality, [39])

Let\(\xi (t)\)be a nonnegative, summable function on\([0,T]\)which satisfies the following integral inequality:

$$ \xi (t) \leq C_{1} \int _{0}^{t} \xi (s) \,d s+C_{2} , $$

for a.e. \(t\in [0,T]\)and constants\(C_{1}, C_{2}\geq 0\). Then

$$ \xi (t) \leq C_{2} \bigl(1+C_{1} te^{C_{1} t}\bigr) , $$

for a.e. \(0 \leq t \leq T\).

Next, let’s recall the definitions of Riemann–Liouville fractional integral, fractional derivatives of Riemann–Liouville type and that of Caputo type.

Definition 2.1

([14, 15])

Assume that \(\alpha >0\), \(\varGamma (\alpha )\) is Gamma function, and \(f(t)\) is a function defined on an interval \(J=[a,b]\). Then the following formula is called the α-order Riemann–Liouville fractional integral (or α-order integral) of \(f(t)\):

$$ \bigl(I_{a+}^{\alpha } f \bigr) (t):=\frac{1}{\varGamma (\alpha )} \int _{a}^{t} \frac{f(u) \,d u}{(t-u)^{1-\alpha }} \quad (a< t\leq b ). $$

Suppose \(n-1<\alpha <n\), then the Riemann–Liouville derivative and Caputo derivative of order α of \(f(t)\) are

$$ \bigl(D_{a+}^{\alpha } f \bigr) (t) =\frac{1}{\varGamma (n-\alpha )} \biggl( \frac{d}{d t} \biggr)^{n} \int _{a}^{t} \frac{f(u) \,d u}{(t-u)^{\alpha -n+1}} \quad (a< t\leq b ) $$

and

$$ \bigl({}^{C} D_{a+}^{\alpha } f \bigr) (t)= \frac{1}{\varGamma (n-\alpha )} \int _{a}^{t} \frac{f^{(n)}(u) \,d u}{(t-u)^{\alpha -n+1}} \quad (a< t \leq b ) , $$

respectively.

The above two formulas are also called left-handed Riemann–Liouville and Caputo derivatives, respectively. The right-handed definitions are similar, and we shall only study the left-handed derivatives for convenience.

In this paper, we use the following notations when \(a=0\):

$$ I^{\alpha }=I_{0+}^{\alpha }, \qquad D^{\alpha }=D_{0+}^{\alpha }, \qquad {}^{C} D^{ \alpha }= {}^{C} D_{0+}^{\alpha }. $$

Next we will list some useful propositions [14, 15] for fractional derivatives and fractional integral. We use the notation

$$ \mathrm{AC}^{n}[a,b]:= \biggl\{ f:[a, b] \rightarrow \mathbb{R} \text{ and } \bigl(D^{n-1} f \bigr) (t) \in \mathrm{AC}[a, b] \ \biggl(D= \frac{d}{d t} \biggr) \biggr\} , $$

where \(\mathrm{AC}[a,b]\) is the collection of all absolutely continuous functions on \([a,b]\) and \(C^{n}[a,b]\) is the collection of all n times continuously differentiable functions on \([a,b]\).

Proposition 2.1

([14, 15])

If\(\alpha =k \in \mathbb{N}\), then

$$ D_{a+}^{k}= {}^{C} D_{a+}^{k}= \biggl(\frac{d}{dt} \biggr)^{k}. $$

That’s to say, if α is an integer, then both Riemann–Liouville and Caputo derivatives are equivalent to the classical integer order derivatives.

Proposition 2.2

([14, 15])

Let\(\alpha , \beta >0\), then

$$ \bigl(I_{a+}^{\alpha }(t-a)^{\beta -1} \bigr) (x) = \frac{\varGamma (\beta )}{\varGamma (\beta +\alpha )}(x-a)^{\beta +\alpha -1} \quad (\alpha >0) $$
(3)

and

$$ \bigl(D_{a+}^{\alpha }(t-a)^{\beta -1} \bigr) (x) = \frac{\varGamma (\beta )}{\varGamma (\beta -\alpha )}(x-a)^{\beta -\alpha -1} \quad (\beta >\alpha \geq 0) . $$
(4)

Proposition 2.3

([14, 15])

Suppose\(n=[\alpha ]+1 \) (\([\alpha ]\)is the maximum integer not greater thanα), then the following two relations hold (for Riemann–Liouville and Caputo type, respectively):

$$\begin{aligned}& \bigl(D_{a+}^{\alpha }(u-a)^{\alpha -j} \bigr) (t)=0, \quad j=1, \dots , n, \end{aligned}$$
(5)
$$\begin{aligned}& \bigl({}^{C} D_{a+}^{\alpha }(u-a)^{k} \bigr) (t)=0,\quad k=0,1,\dots ,n-1. \end{aligned}$$
(6)

Proposition 2.4

([14, 15])

Assume that\(n=[\alpha ]+1\), \(f(t)\in L^{1}(a,b)\), and\(f_{n-\alpha }(t):= (I_{a+}^{n-\alpha }f)(t)\in \mathrm{AC}^{n}[a,b]\). Then

$$ \bigl(I_{a+}^{\alpha } D_{a+}^{\alpha } f \bigr) (t)=f(t)-\sum_{j=1}^{n} \frac{f_{n-\alpha }^{(n-j)}(a)}{\varGamma (\alpha -j+1)}(t-a)^{\alpha -j} , $$
(7)

for a.e. \(x \in [a,b] \).

Proposition 2.5

([14, 15])

Assume that\(n=[\alpha ]+1\), \(f\in \mathrm{AC}^{n}[a,b]\)or\(f\in C^{n}[a,b]\), then

$$ \bigl(I_{a+}^{\alpha } {}^{C} D_{a+}^{\alpha } f \bigr) (t)=f(t)- \sum _{k=0}^{n-1} \frac{f^{(k)}(a)}{k !}(t-a)^{k}. $$
(8)

3 Main results

3.1 Hyers–Ulam stability of Riemann–Liouville FDEs

In this section, we will establish the Hyers–Ulam stability of the Riemann–Liouville FDEs (1) under some conditions. Before we give this general result, let’s investigate the following simple case first:

$$ \textstyle\begin{cases} (D^{\alpha } x )(t)+p(t) x(t)=h(t), \quad t \in J, \\ (I^{1-\alpha } x )(0)=x_{0} , \end{cases} $$
(9)

where \(0<\alpha <1\) and \(p(t)\), \(h(t)\), J are as aforesaid. Then the following theorem holds:

Theorem 3.1

Suppose that the solution of equation (9) is\(x(t)\in L^{1}(0,b)\)and that\((I^{1-\alpha }x)(t) \in \mathrm{AC}[0,b]\). Let\(y(t) \in \mathrm{AC}[0,b]\), \((I^{1-\alpha }y)(t) \in \mathrm{AC}[0,b]\), \((I^{1-\alpha } y )(0)=x_{0}\)and

$$ \bigl\vert \bigl(D^{\alpha } y \bigr) (t)+p(t) y(t)-h(t) \bigr\vert \leq \varepsilon , \quad t\in J, $$
(10)

where\(\varepsilon >0\). Assume also that there exists a constant\(M> 0\)such that

$$ \bigl\vert (t-u)^{\alpha -1} p(u) \bigr\vert \leq M, \quad \forall 0 \leq u \leq t, $$
(11)

for every\(0< t< b\). Then there exists a constant\(K>0\)such that

$$ \bigl\vert y(t)-x(t) \bigr\vert \leq K \varepsilon ,\quad \forall t\in J . $$
(12)

Proof

Consider the case of \(x_{0}=0\) first. Since

$$ -\varepsilon \leq \bigl(D^{\alpha } y\bigr) (t)+p(t) y(t)-h(t)\leq \varepsilon , $$
(13)

calculating the α-order integrals of the above inequality, we obtain

$$ -\varepsilon \frac{t^{\alpha }}{\varGamma (1+\alpha )} \leq y(t)+\bigl(I^{ \alpha }(p y)\bigr) (t)- \bigl(I^{\alpha }h\bigr) (t)\leq \varepsilon \frac{t^{\alpha }}{\varGamma (1+\alpha )}, $$
(14)

where we use formula (7) in Proposition 2.4.

Doing the same for the equation

$$ \bigl(D^{\alpha } x \bigr) (t)+p(t) x(t)=h(t), $$
(15)

we get

$$ x(t)+\bigl(I^{\alpha }(p x)\bigr) (t)-\bigl(I^{\alpha }h\bigr) (t)=0 . $$
(16)

Therefore

$$ \begin{aligned}[b] \bigl\vert y(t)-x(t) \bigr\vert &= \bigl\vert y(t)+(I^{\alpha }(p y) (t)-\bigl(I^{ \alpha }h\bigr) (t)- \bigl(I^{\alpha }\bigl(p(y-x)\bigr)\bigr) (t) \bigr\vert \\ &\leq \varepsilon \frac{t^{\alpha }}{\varGamma (1+\alpha )}+ \bigl\vert \bigl(I^{ \alpha } \bigl(p(y-x)\bigr)\bigr) (t) \bigr\vert \\ &= \varepsilon \frac{t^{\alpha }}{\varGamma (1+\alpha )}+ \frac{1}{\varGamma (\alpha )} \int _{0}^{t} \bigl\vert (t-u)^{\alpha -1} p(u) \bigl[y(u)-x(u)\bigr] \bigr\vert \,d u \\ &\leq \varepsilon \frac{b^{\alpha }}{\varGamma (1+\alpha )}+ \frac{M}{\varGamma (\alpha )} \int _{0}^{t} \bigl\vert y(u)-x(u) \bigr\vert \,d u. \end{aligned} $$
(17)

According to Gronwall’s inequality, we have the following estimate:

$$ \bigl\vert y(t)-x(t) \bigr\vert \leq \varepsilon C_{2} \bigl(1+C_{1} te^{C_{1} t}\bigr), $$
(18)

where \(C_{2}=\frac{b^{\alpha }}{\varGamma (1+\alpha )}\), \(C_{1}= \frac{M}{\varGamma (\alpha )}\). Set \(K=C_{2} (1+C_{1} be^{C_{1} b})\), then the proof is complete in the case of \(x_{0}=0\).

Now we abandon the condition \(x_{0}=0\). Setting \(\tilde{x}(t)=x(t)-\frac{x_{0} t^{\alpha -1}}{\varGamma (\alpha )} \) and \(\tilde{y}(t)=y(t)-\frac{x_{0} t^{\alpha -1}}{\varGamma (\alpha )} \) and invoking relation (5), we can convert the equation to:

$$ \textstyle\begin{cases} (D^{\alpha } \tilde{x})(t)+p(t) \tilde{x}(t)=h(t)- \frac{x_{0} t^{\alpha -1}p(t)}{\varGamma (\alpha )}, \quad t \in J, \\ (I^{1-\alpha }\tilde{x})(0)=0.\end{cases} $$
(19)

Notice that inequality (10) is equivalent to

$$ \biggl\vert \bigl(D^{\alpha } \tilde{y}\bigr) (t)+p(t) \tilde{y}(t)-h(t) + \frac{x_{0} t^{\alpha -1}p(t)}{\varGamma (\alpha )} \biggr\vert \leq \varepsilon , \quad t \in J . $$
(20)

Thus the assertion is also true since \(\tilde{x}(t)\), \(\tilde{y}(t)\) still satisfy the hypothesis of Proposition 2.4, and the proof is complete. □

Now we can deal with a more general case: \(n-1<\alpha <n\), \(n\in \mathbb{N}\). Compared with the previous situation, the only difficulty is converting equation (1) into the case of zero-initial-value. Here we should be very careful, since the Riemann–Liouville fractional derivative of a constant is not equal to 0 (unless the constant is 0). In fact,

$$ \bigl(D^{\alpha } 1 \bigr) (t)=\frac{t^{-\alpha }}{\varGamma (1-\alpha )} \quad (0< \alpha < 1) . $$
(21)

However, by using Propositions 2.2 and 2.3, we obtain that

$$ \bigl(D^{n-i} I^{n-\alpha } \bigl(u^{\alpha -j} \bigr)\bigr) (t)= \textstyle\begin{cases} \frac{\varGamma (\alpha -j+1)}{\varGamma (i-j+1)}t^{i-j} , & j=1,\dots ,i-1, \\ \varGamma (\alpha -i+1) , & j=i, \\ 0, & j=i+1,\dots ,n, \end{cases} $$
(22)

for \(i=1,\dots , n\). Therefore, we have:

Theorem 3.2

Consider equation (1) as above. Let the solution of equation (1) be\(x(t)\)and\(x(t)\in L^{1}(0,b)\), \((I^{n-\alpha }x)(t)\in \mathrm{AC}^{n}[0,b]\). Suppose\(y(t)\in L^{1}(0,b)\), \((I^{n-\alpha }y)(t)\in \mathrm{AC}^{n}[0,b]\), \((D^{n-j} I^{n-\alpha } y )(0)=x_{j}\), \(j=1, \ldots , n\), and let inequality (10) hold for\(\varepsilon >0\). Suppose also that there exists a constant\(M> 0\)such that

$$ \bigl\vert (t-u)^{\alpha -1} p(u) \bigr\vert \leq M, \quad \forall 0 \leq u \leq t, $$
(23)

for every\(0< t< b\). Then there exists a constant\(K>0\)such that

$$ \bigl\vert y(t)-x(t) \bigr\vert \leq K \varepsilon ,\quad \forall t\in J . $$
(24)

Proof

If \(x_{j}=0\), \(j=1,\dots ,n\), then the proof is totally the same as the proof of Theorem 3.1.

In the general case, set

$$ \tilde{x}(t)=x(t)-\sum_{j=1}^{n} \frac{x_{j} t^{\alpha -j}}{\varGamma (\alpha -j+1) } . $$
(25)

Then we get the following equation:

$$ \textstyle\begin{cases} (D^{\alpha }\tilde{x})(t)+p(t)\tilde{x}(t)=h(t)-\sum_{j=1}^{n} \frac{x_{j} t^{\alpha -j} p(t)}{\varGamma (\alpha -j+1) }, \quad t \in J , \\ ((D^{n-j} I^{n-\alpha }\tilde{x})(0)=0, \quad j=1,\dots ,n, \end{cases} $$
(26)

where we use the relation in (22).

Set

$$ \tilde{y}(t)=y(t)-\sum_{j=1}^{n} \frac{x_{j} t^{\alpha-j}}{\Gamma(\alpha-j+1)}. $$
(27)

Note that inequality (10) is equivalent to

$$ \Biggl\vert \bigl(D^{\alpha }\tilde{y}\bigr) (t)+p(t)\tilde{y}(t)-h(t)+ \sum_{j=1}^{n} \frac{x_{j} t^{\alpha -j} p(t)}{\varGamma (\alpha -j+1) } \Biggr\vert \leq \varepsilon $$
(28)

and that \(\tilde{x}(t)\), \(\tilde{y}(t)\) still satisfy the hypotheses of the Proposition 2.4, thus the assertion of the theorem is true. □

3.2 Hyers–Ulam stability of Caputo FDEs

In this section, we investigate the Hyers–Ulam stability of equations with Caputo derivatives (2). Compared with the previous theorems, here we can utilize (8) in Proposition 2.5. Virtually by the same method, we can establish the stability as for Riemann–Liouville FDEs. Note that the Caputo derivative of a constant is 0.

Theorem 3.3

Let\(x(t)\)be the solution of equation (2) and\(x(t)\in \mathrm{AC}^{n}[0,b]\)or\(x(t)\in C^{n}[0,b]\). Suppose\(y(t) \in \mathrm{AC}^{n}[0,b]\)or\(y(t)\in C^{n}[0,b]\), \(y^{(k)}(0)=x_{k}\), \(k=0,1, \ldots , n-1\)and that

$$ \bigl\vert \bigl({}^{C} D^{\alpha } y \bigr) (t)+p(t) y(t)-h(t) \bigr\vert \leq \varepsilon , \quad t\in J, $$
(29)

for\(\varepsilon >0\). Suppose also that there exists a constant\(M> 0\)such that

$$ \bigl\vert (t-u)^{\alpha -1} p(u) \bigr\vert \leq M, \quad \forall 0 \leq u \leq t , $$
(30)

for every\(0< t< b\). Then there exists a constant\(K>0\)such that

$$ \bigl\vert y(t)-x(t) \bigr\vert \leq K \varepsilon ,\quad \forall t\in J . $$
(31)

Proof

If \(x_{k}=0\), \(j=0,1,\dots ,n-1\), then we can invoke the Gronwall’s inequality and Proposition 2.5 to prove the theorem in just the same way as Theorem 3.1.

In the general case, set

$$ \tilde{x}(t)=x(t)-\sum_{k=0}^{n-1} \frac{x_{k} t^{k}}{k!} . $$
(32)

Then convert equation (2) to

$$ \textstyle\begin{cases} ({}^{C} D^{\alpha }\tilde{x})(t)+p(t) \tilde{x}(t)=h(t)-\sum_{k=0}^{n-1} \frac{x_{k} t^{k} p(t)}{k!}, \quad t \in J, \\ \tilde{x}^{(k)}(0)=0, \quad k=0,1,\dots ,n-1,\end{cases} $$
(33)

where we use formula (8) and relation (6). Again, set

$$ \tilde{y}(t)=y(t)-\sum_{k=0}^{n-1} \frac{x_{k} t^{k}}{k!} . $$
(34)

Notice that inequality (29) is equivalent to

$$ \Biggl\vert \bigl({}^{C} D^{\alpha }\tilde{y}\bigr) (t)+p(t) \tilde{y}(t)-h(t)+\sum_{k=0}^{n-1} \frac{x_{k} t^{k} p(t)}{k!} \Biggr\vert \leq \varepsilon $$
(35)

and \(\tilde{x}(t)\), \(\tilde{y}(t)\) still satisfy the hypotheses of Proposition 2.5, so the assertion of the theorem is true. □

4 Conclusion

In this paper, we deal with the Hyers–Ulam stability of linear fractional differential equations with variable coefficients under certain conditions. Moreover, our results can be established for both Riemann–Liouville and Caputo type derivatives. In [38], Shen et al. established the Hyers–Ulam stability of similar equations but with constant coefficients. They used the Laplace method to solve the problem, but it’s difficult to deal with it by the same way when the equations have variable coefficients. Fortunately, we find another way (by invoking Gronwall’s inequality) to overcome the problem. Besides, when \(\alpha >1\) and \(p(t) \equiv \lambda \) (λ is a constant) in Theorem 3.2 or Theorem 3.3, obviously the restrictions on \(p(t)\) in these two theorems will be satisfied, therefore we obtain more general results in this case.