1 Introduction

Fractional calculus, the theory of differentiation and integration to non-integer order, is very useful for the description of various physical phenomena, such as damping laws, diffusion process, etc. Fractional derivatives provide an excellent instrument for the description of memory and hereditary properties of various materials and processes [110]. Especially, fractional differential equations provide outstanding tools for illustration of many engineering and physical problems. Since most fractional differential equations do not have exact and analytic solutions, the accurate numerical techniques for solving these fractional equations are a challenging and motivational research area in mathematics and engineering.

The fractional Bagley-Torvik equation was originally formulated in a description of a real material by the use of fractional calculus. Moreover, the Bagley-Torvik equation has appeared in simulating the motion of a rigid plate immersed in a Newtonian fluid [1113]. This equation has been studied both analytically and numerically in [3]. Diethelm [14] transformed this equation into a system of fractional differential equation and solved the problem with the Adams predictor and the corrector method. Recently, considerable attention has been devoted to numerical solutions of the fractional Bagley-Torvik equation. For example the spectral tau method [15, 16], the operational formulation of collocation methods [17, 18], collocation methods [1921], wavelet methods [22, 23], pseudospectral methods [24], differential transform methods [25], hybrid functions methods [26], and fractional Taylor methods [27] have been used to solve this fractional differential equation. In this study, a fractional-order Legendre collocation method is proposed for solving the Bagley-Torvik equations.

Applications of orthogonal functions and polynomials for numerical solution of ordinary differential equations refer, at least, to the time of Lanczos [28]. Moreover, the origin of some current spectral method, such as the Galerkin, tau, and pseudospectral methods can be found in the ‘weighted residual method’ of Finlayson and Scriven [29]. Nowadays, spectral methods are efficient techniques for solving a different kind of fractional differential and integral equations accurately [15, 17, 30, 31]. The main advantage of spectral methods lies in their accuracy for a given number of unknowns. For smooth problems in simple geometries, they offer exponential rates of convergence (spectral accuracy). By using the operational matrices for basis functions, spectral methods reduce the solution of fractional differential and integral equations into a solution of systems of algebraic equations which produce highly accurate solutions for these equations [22, 23, 30, 32].

This paper is structured as follows: In Section 2 some basic preliminaries of the fractional calculus are presented. The FSLPs and their properties are introduced in Section 3. Section 4 is devoted to an operational matrix of fractional integration for the FSLPs. Application of the FSLPs for solving the Bagley-Torvik equation is considered in Section 5. Convergence and an error estimate for the FSLPs expansion are given in Section 6. The efficiency and superiority of the proposed method is demonstrated by considering some numerical examples in Section 7. Finally, a conclusion is given in Section 8.

2 Preliminaries

In this section we review some basic definitions and preliminaries of the fractional calculus which are used in the next sections.

2.1 Fractional calculus

Fractional-order calculus is a branch of calculus which deals with integration and differentiation operators of non-integer order. Among the several formulations of the generalized derivative, the Riemann-Liouville and Caputo definition are most commonly used, which can be described as follows [3].

Definition 1

A real function \(f (t)\), \(t>0\), is said to be in the space \(C_{\mu}\), \(\mu \in\mathbb{R}\) if there exist a real number \(p >\mu\) and a function \(f_{1}(t)\in C[0,\infty)\) such that \(f (t)=t^{p} f_{1}(t)\), and it is said to be in the space \(C_{\mu}^{n}\), \(n \in\mathbb{N}\) if \(f ^{(n)} \in C_{\mu}\).

Definition 2

The Riemann-Liouville fractional integration of order \(\nu\geq0\) of a function \(f \in C_{\mu}\), \(\mu\geq-1\), is defined as

$$\begin{aligned} \bigl(\mathcal{J}^{\nu}f \bigr) (t)=\left \{ \textstyle\begin{array}{l@{\quad}l} \frac{1}{\Gamma(\nu)}\int_{0}^{t}{(t-\tau)^{\nu-1}{f(\tau)}\, d\tau}, & \nu>0, \\ f(t), & \nu=0. \end{array}\displaystyle \right . \end{aligned}$$

The Riemann-Liouville fractional operator \(\mathcal{J}^{\nu}\) has the following properties:

$$\begin{aligned}& \mathcal{J}^{\nu_{1}} \bigl( {\mathcal{J}^{\nu_{2}} f(t)} \bigr) = \mathcal{J}^{\nu_{2}} \bigl( {\mathcal{J}^{\nu_{1}} f(t)} \bigr),\quad \nu _{1}, \nu_{2} \geq0, \\& \mathcal{J}^{\nu_{1}} \bigl( {\mathcal{J}^{\nu_{2}} f(t)} \bigr) = \mathcal{J}^{\nu_{1} + \nu_{2}} f(t), \quad \nu_{1}, \nu_{2} \geq0, \\& \mathcal{J}^{\nu} t^{\lambda}= \frac{{\Gamma( {\lambda+ 1} )}}{{\Gamma( {\lambda+ \nu+ 1} )}}t^{\nu+ \lambda},\quad \nu\geq0, \lambda>-1. \end{aligned}$$

Definition 3

The fractional derivative of order \(\nu>0\) in the Caputo sense is defined as

$$\begin{aligned} \mathcal{D}^{\nu}f(t)=\left \{ \textstyle\begin{array}{l@{\quad}l} \frac{d^{n}f(t)}{dt^{n}}, & \nu=n \in\mathbb{N}, \\ \frac{1}{\Gamma(n-\nu)}\int_{0}^{t}{\frac{f^{(n)}(\tau)}{(t-\tau )^{\nu-n+1}}\,d\tau}, & t>0,0 \leq n-1< \nu< n, \end{array}\displaystyle \right . \end{aligned}$$

where n is an integer, \(t>0\), and \(f \in C_{1}^{n}\).

For \(\mathbb{N}_{0}=\lbrace0, 1, 2, \ldots\rbrace\), \(f \in C_{\mu }\), \(\mu , \lambda\geq-1\), and \(n-1<\nu\leq n\) some useful and practical properties of the Caputo fractional operators \(\mathcal{D}^{\nu}\) are given by the following expressions:

$$\begin{aligned}& \mathcal{J}^{\nu}D^{\nu} f(t)=f(t)-\sum _{k=0}^{n-1}{f^{(k)}\bigl(0^{+} \bigr)}\frac {t^{k}}{k!}, \quad t>0, \\& \mathcal{D}^{\nu} \mathcal{J}^{\nu} f(t) = f(t), \\& \mathcal{D}^{\nu} t^{\lambda} = \left \{ \textstyle\begin{array}{l@{\quad}l} 0 & \mbox{for } \lambda\in\mathbb{N}_{0}\mbox{ and }\lambda< \nu, \\ \frac{{\Gamma(\lambda+ 1)}}{{\Gamma(\lambda- \nu+ 1)}}t^{\lambda - \nu} & \mbox{otherwise}. \end{array}\displaystyle \right . \end{aligned}$$

For more details of fractional calculus and their applications please refer to [13].

3 The FSLPs and their properties

The FSLPs can be defined based on the definition of the shifted Legendre polynomials by introducing the change of variable \(t=x^{\alpha }\) for \(\alpha>0\) [10]. Let \(P_{n}(x)\) is the nth shifted Legendre polynomial and \(P_{ ( {n,\alpha} )} (x)\) denote the nth FSLPs, i.e. \(P_{n} (x^{\alpha})\). By using the recurrence formula for the shifted Legendre polynomials, it can be given as

$$\begin{aligned} P_{ ( {n,\alpha} )} (x) = \frac{{2n - 1}}{{n }}\bigl(2x^{\alpha} - 1\bigr) P_{ ( {n-1,\alpha} )} (x) - \frac{n-1}{{n }}P_{ ( {n-2,\alpha} )} (x), \quad n = 2, 3, \ldots, \end{aligned}$$

where \(P_{ ( {0,\alpha} )} (x)=1\) and \(P_{ ( {1,\alpha} )} (x)=2x^{\alpha} - 1\). The set of FSLPs are orthogonal with respect to the weight function \(w_{\alpha}(x)=x^{\alpha-1}\) in the interval \([0,1]\) with the orthogonality property

$$\begin{aligned} \int_{0}^{1} {P_{ ( {m,\alpha} )} (x)P_{ ( {n,\alpha} )} (x)w_{\alpha}(x)}\,dx = \frac{\delta_{mn}}{\alpha(2n+1)}. \end{aligned}$$

Moreover, the analytical form of the FSLP \(P_{ ( {n,\alpha} )} (x)\) can be written as [10]

$$\begin{aligned} P_{ ( {n,\alpha} )} (x)=\sum_{k = 0}^{n} {{a_{n,k}} {x^{\alpha k}}}, \quad n = 0, 1, 2, 3, \ldots, \end{aligned}$$
(1)

where \(a_{n,k}\) are defined as

$$\begin{aligned} {a_{n,k}} = \frac{{{{( - 1)}^{n}}(n + k)!}}{{(n - k)!{{(k!)}^{2}}}}. \end{aligned}$$
(2)

Any function \(f(t)\) defined over \([0,1]\) may be expanded in terms of FSLPs as

$$\begin{aligned} f(x) = \sum_{k = 0}^{\infty}{c_{k} P_{ (k,\alpha) } (x)}, \end{aligned}$$
(3)

in which the \(c_{k}\) are derived by

$$\begin{aligned} c_{k} =\alpha(2k+1) \int_{0}^{1} {P_{ ( {m,\alpha} )} (x)P_{ ( {n,\alpha} )} (x)w_{\alpha}(x)}\,dx . \end{aligned}$$

If the infinite series in equation (3) is truncated, then it can be written as

$$\begin{aligned} f(x)\simeq f_{M}(x) = \sum_{k = 0}^{M-1} {c_{k}}P_{ (k,\alpha)(x)} = C^{T} \Phi_{\alpha} (x), \end{aligned}$$
(4)

where C and \(\Phi_{\alpha} (x)\) are \(M \times1\) vectors given by

$$\begin{aligned} C = [ {c_{0} ,c_{2} ,\ldots,c_{M-1} } ]^{T}, \quad\quad \Phi_{\alpha} (x) = \bigl[ {P_{ ( {0,\alpha} )} (x), P_{ ( {1,\alpha} )} (x), \ldots, P_{ ( {M-1,\alpha} )} (x)} \bigr]. \end{aligned}$$
(5)

4 Operational matrix of fractional integration of FSLPs

In recent years various operational matrices for the polynomials have been developed to cover the numerical solution of differential, integral and integro-differential equations. The main advantage of these operational matrices is that they replace differential and integral operators with some matrices. Consequently, they reduce such problems to those of solving a system of algebraic equations, greatly simplifying the problem [3338]. In this section the operational matrix of fractional integration for FSLPs will be derived.

Theorem 4.1

The Riemann-Liouville fractional integration of order ν for the \(M \times1\) FSLPs vector \(\Phi_{\alpha} (x)\) can be defined as

$$\begin{aligned} \mathcal{J}^{\nu} \Phi_{\alpha} (x)=x^{\nu} \mathcal{M}^{(\nu) }\Phi_{\alpha} (x), \end{aligned}$$
(6)

where \(\mathcal{M}^{(\nu)}\) is \(M \times M\) matrix and its \((i,j)\) th element is defined by

$$\begin{aligned} \mathcal{M}^{(\nu) }_{i,j} ={ {\sum _{r = 0}^{i - 1} {\sum_{l = 0}^{j} {\frac{\alpha( {2j + 1} ){{a _{i - 1,r}}{a_{j,l}\Gamma( {s\alpha+ 1} )}}}{{(\alpha r + \alpha l + \alpha)}\Gamma( {r\alpha+ \nu+ 1} )}} } } },\quad i,j=1, 2, \ldots, M, \end{aligned}$$
(7)

where \(a _{i - 1, s}\) is defined in equation (2).

Proof

The ith element of the vector \(\Phi_{\alpha} (x)\) is \(P_{(i - 1,\alpha )} (x)\). Using the analytical form of \(P_{(i - 1,\alpha)} (x)\), the fractional integration of order ν for this function can be written as

$$\begin{aligned} \mathcal{J}^{\nu} P_{(i - 1,\alpha)} (x) = \sum _{r = 0}^{i - 1} {{a_{i - 1,r}}\frac{{\Gamma( {s\alpha+ 1} )}}{{\Gamma ( {r\alpha+ \nu+ 1} )}}{x^{r\alpha+ \nu}}}=x^{\nu} \sum_{r = 0}^{i - 1} {{a_{i - 1,r}} \frac{{\Gamma( {s\alpha+ 1} )}}{{\Gamma( {r\alpha+ \nu+ 1} )}}{x^{r\alpha}}}. \end{aligned}$$
(8)

Now the term \(x^{\alpha r}\) is expanded exactly by FSLPs as

$$\begin{aligned} {x^{\alpha r }} = \sum_{j= 0}^{M-1} {{\rho_{r,j}} {P_{(j,\alpha)}}(x)}, \end{aligned}$$
(9)

in which the \(\rho_{r,s}\) can be derived as

$$\begin{aligned} {\rho_{r,j}} =& \alpha(2j + 1) \int_{0}^{1} {{P_{(j,\alpha)}}(x)} {x^{\alpha r }} {w_{\alpha}(x)}\,dx = \alpha(2j + 1) \int_{0}^{1} {{P_{(j,\alpha)}}(x)} {x^{\alpha r }} {x^{\alpha-1}}\,dx \\ =& \alpha(2j + 1)\sum_{l = 0}^{j} {{a_{j,l}}} \int_{0}^{1} {{x^{\alpha r + \alpha l + \alpha-1}}} \,dx=\alpha(2j + 1) \sum_{l = 0}^{j} {\frac {{{a_{j,l}}}}{{\alpha l + \alpha r + \alpha}}}. \end{aligned}$$
(10)

By substituting equations (9) and (10) in (8) we have

$$\begin{aligned} \mathcal{J}^{\nu} P_{(i - 1,\alpha)} (x) =x^{\nu} \sum_{j = 0}^{M - 1} { \Biggl( {\sum _{r = 0}^{i - 1} {\sum_{l = 0}^{j} {\frac{\alpha( {2j + 1} ){{a _{i - 1,r}}{a_{j,l}\Gamma ( {s\alpha+ 1} )}}}{{(\alpha r + \alpha l + \alpha)}\Gamma ( {r\alpha+ \nu+ 1} )}} } } \Biggr)} {P_{(j,\alpha)}}(x), \end{aligned}$$
(11)

this means that the fractional integration of ith element of \(\Phi _{\alpha} (x)\) can be expanded in FSLPs as derived in equation (11) and this yields the desired result directly. □

5 Numerical solution of Bagley-Torvik equations

The fractional Bagley-Torvik equation is of the form

$$\begin{aligned} A_{1}{\mathcal{D}^{2}}y(x) + A_{2}{\mathcal{D}^{\nu}}y(x) + A_{3}y(x) = f(x), \quad 0 \leq x \leq R, 1< \nu< 2, \end{aligned}$$
(12)

subject to the initial conditions

$$\begin{aligned} y(0)=\alpha_{0}, \quad\quad y^{\prime}(0)= \alpha_{1}, \end{aligned}$$
(13)

or the boundary conditions

$$\begin{aligned} y(0)=\beta_{0},\quad\quad y(R)=\beta_{1}, \end{aligned}$$
(14)

where \(A_{1}\), \(A_{2}\), \(A_{3}\), \(\alpha_{0}\), \(\alpha_{1}\), \(\beta_{0}\), and \(\beta_{1}\) are constants with \(A\neq0\). To solve this fractional Bagley-Torvik equation we consider two cases.

Case (1) Intitial conditions: For solving the Bagley-Torvik equation (12) with intitial conditions (16), we use the change of variable \(t=\frac{x}{R}\) to transform \(x \in[0, R]\) in \(t \in[0, 1]\). So, we get

$$\begin{aligned} \frac{A}{{{R^{2}}}}{\mathcal{D}^{2}}Y(t) + \frac{B}{{{R^{\alpha}}}}{\mathcal{D}^{\nu}} {Y(t)} + CY(t) = F(t), \quad 0 \leq t \leq1, 1< \nu< 2, \end{aligned}$$
(15)

subject to the initial conditions

$$\begin{aligned} Y(0)=\alpha_{0}, \quad\quad Y^{\prime}(0)=R \alpha_{1}, \end{aligned}$$
(16)

in which \(Y(t)=y(Rt)\) and \(F(t)=f(Rt)\). Now, we approximate the functions \(Y(t)\) and \(F(t)\) in terms of FSLPs as

$$\begin{aligned} Y(t) \simeq C^{T }\Psi_{\alpha} (t), \quad\quad F(t) \simeq \Gamma^{T }\Psi_{\alpha } (t) , \end{aligned}$$
(17)

where C is an unknown \(M \times1\) vector. Substituting equation (17) in equation (15) and applying the Riemann-Liouville integral operator \(\mathcal{J}^{2}\) we get

$$\begin{aligned}& \frac{A_{1}}{{{R^{2}}}} \bigl( {C^{T }\Psi_{\alpha} (t) - { \alpha_{0}} - Rt{\alpha_{1}}} \bigr) + \frac{A_{2}}{{{R^{\alpha}}}}{ \mathcal{J}^{2 - \nu}} \bigl( {C^{T }\Psi_{\alpha} (t) - { \alpha_{0}} - Rt{\alpha_{1}}} \bigr) \\& \quad{} + A_{3}{\mathcal{J}^{2}}C^{T } \Psi_{\alpha} (t) = {\mathcal{J}^{2}}\Gamma^{T } \Psi_{\alpha} (t), \end{aligned}$$
(18)

by using the operational matrix of fractional integration \(\mathcal {M}^{(\nu)}\) we have

$$\begin{aligned}& \frac{A_{1}}{{{R^{2}}}} \bigl( {C^{T }\Psi_{\alpha} (t) - { \alpha_{0}} - Rt{\alpha_{1}}} \bigr) \\& \quad{} + \frac{A_{2}}{{{R^{\alpha}}}}{} \biggl( {t^{2 - \nu }C^{T }\mathcal{M}^{(2 - \nu) } \Psi_{\alpha} (t) - {\alpha_{0}\frac {t^{2-\nu}}{\Gamma(3-\nu)}} - R{ \alpha_{1}\frac{t^{3-\nu}}{\Gamma(4-\nu )}}} \biggr) \\& \quad{} +t^{2}A_{3}C^{T }{ \mathcal{M}^{2}}\Psi_{\alpha} (t) = t^{2} \Gamma^{T }{\mathcal{M}^{2}}\Psi_{\alpha} (t). \end{aligned}$$
(19)

Now we collocate the equation (19) at the M zeros of the shifted Legendre polynomial \(P_{M}(x)\). This generates a system of M algebraic equations for the unknown vector C. After finding the solution of this algebraic system, the solution \(Y(t)\) can be derived by substituting the vector C in equation (17).

Case (2) Boundary conditions: To solve the Bagley-Torvik equation (12) with boundary conditions (14), similar to the previous case, by using the change of variable \(t=\frac{x}{R}\) we obtain

$$\begin{aligned} \frac{A}{{{R^{2}}}}{\mathcal{D}^{2}}Y(t) + \frac{B}{{{R^{\alpha}}}}{\mathcal{D}^{\nu}} {Y(t)} + CY(t) = F(t), \quad 0 \leq t \leq1, 1< \nu< 2, \end{aligned}$$
(20)

subject to boundary conditions

$$\begin{aligned} Y(0)=\beta_{0}, \quad\quad Y(1)=\beta_{1}, \end{aligned}$$

substituting the approximation functions \(Y(t)\) and \(F(t)\) defined in equation (17) into equation (20) and using the operational matrix of fractional integration \(\mathcal{M}^{(\nu)}\) we get

$$\begin{aligned}& \frac{A_{1}}{{{R^{2}}}} \bigl( {C^{T }\Psi_{\alpha} (t) - { \beta_{0}} - Rt{w}} \bigr) \\& \quad{} + \frac{A_{2}}{{{R^{\alpha}}}} \biggl( {t^{2 - \nu}C^{T }\mathcal{M}^{(2 - \nu) }\Psi_{\alpha} (t) - {\beta_{0}\frac{t^{2-\nu }}{\Gamma(3-\nu)}} - R{w\frac{t^{3-\nu}}{\Gamma(4-\nu)}}} \biggr) \\& \quad{} +t^{2}A_{3}C^{T }{ \mathcal{M}^{2}}\Psi_{\alpha} (t) = t^{2} \Gamma^{T }{\mathcal{M}^{2}}\Psi_{\alpha} (t), \end{aligned}$$
(21)

in which \(w=Y^{\prime}(0)\) is unknown. To obtain the solution \(Y(t)\) we collocate the equation (21) at the M zeros of the shifted Legendre polynomial \(P_{M}(x)\) and this gives a system of M algebraic equations for the unknown vector C. Moreover, the boundary condition \(y(R)=Y(1)=\beta_{1}\) give a linear equation. This equation together with M algebraic equations derived by collocation method, generates a system of \(M+1\) equations which can be solved for the unknown vector C and initial condition w. By substituting the derived vector C in equation (17) the solution \(Y(t)\) can be derived.

6 Error analysis

In this section, in order to demonstrate the efficiency of the proposed FSLPs method, we have given some theorems on convergence and error estimation. The next theorem gives an upper bound for the error function of the truncated FSLPs series.

Theorem 6.1

Let \(f(x)\) be a defined function on \([0,1]\) and \(g ( x ) = f ( {{x^{\frac{1}{\alpha}}}} ) \in{C^{n+1}} [ {0,1} ]\), the mean error bound for the truncated FSLPs series \(f_{M}(x) = \sum_{k = 0}^{M-1} {c_{k}}P_{ (k,\alpha)(x)}\) can be derived as follows:

$$\begin{aligned} {\Vert {f - {f_{M}} } \Vert _{\alpha}} \le \frac{{{{\Vert {{g^{(n + 1)}}} \Vert }_{\infty}}}}{{(n + 1)!{2^{2n + 1}}}}. \end{aligned}$$

Proof

The truncated FSLPs series \(f_{M}(x)\) can be written as a polynomial \({q_{n}}(x^{\alpha})\) of degree \(M-1\) which approximates \(f(x)\) with minimum mean error, so

$$\begin{aligned} \Vert {f - {f_{M}} } \Vert _{\alpha}^{2} = \int_{0}^{1} {{{\bigl\vert {f(x) - {f_{M}}(x)} \bigr\vert }^{2}} {x^{\alpha- 1}}\,dx} = { \int_{0}^{1} {{{\bigl\vert {f(x) - {q_{n}}(x)} \bigr\vert }^{2}} {x^{\alpha- 1}}\,dx}} , \end{aligned}$$

by the change of variable \(t=x^{\alpha}\) we get

$$\begin{aligned} \Vert {f - {f_{M}} } \Vert _{\alpha}^{2} = \alpha \int_{0}^{1} {{{\bigl\vert {g(t) - {q_{n}}(t)} \bigr\vert }^{2}}\,dt}\le\alpha \int_{0}^{1} {{{\bigl\vert {g(t) - {Q_{n}}(t)} \bigr\vert }^{2}}\,dt}, \end{aligned}$$

in which \(Q_{n}(x)\) is the well-known polynomial interpolation for \(g(t)\) at shifted zeros of Chebyshev polynomials in the interval \([ 0, 1 ]\). Now by using an error bound of the polynomial interpolation \(Q_{n}(t)\) (Theorem 8.7 in [39]) we have

$$\begin{aligned} \Vert {f - {f_{M}} } \Vert _{\alpha}^{2} \le \alpha \int_{0}^{1} {{{ \biggl( \frac{{{{\Vert {{g^{(n + 1)}}} \Vert }_{\infty}}}}{{(n + 1)!{2^{2n + 1}}}} \biggr)}^{2}}\,dt} = \biggl( \frac{{{{\Vert {{g^{(n + 1)}}} \Vert }_{\infty}}}}{{(n + 1)!{2^{2n + 1}}}} \biggr)^{2}, \end{aligned}$$

taking the square root of both sides completes the proof. □

Now, we give the error estimation of the numerical method given in the previous section. Suppose \(y(x)\) is the exact solution of (12) and \(y_{M}(x)\) is the approximate solution for \(y(x)\). Here, we introduce a process for estimating the error of the approximate solution, i.e. \(e_{M}(x)=y(x)-y_{M}(x)\). Consider the perturbation function \(R_{M}(x)\), depending only on the approximate solution \(y_{M}(x)\) as

$$\begin{aligned} R_{M}(x)=A_{1}{\mathcal{D}^{2}}y(x) + A_{2}{\mathcal{D}^{\nu}}y(x) + A_{3}y(x) - f(x), \end{aligned}$$
(22)

subtracting (22) from (12) we obtain

$$\begin{aligned} A_{1}{\mathcal{D}^{2}}e_{M}(x) + A_{2}{\mathcal{D}^{\nu}}e_{M}(x) + A_{3}e_{M}(x)=R_{M}(x), \end{aligned}$$
(23)

these Bagley-Torvik equations with initial conditions \(e_{M}(0)=0\), \(e_{M}^{\prime}(0)=0\) or boundary conditions \(e_{M}(0)=0\), \(e_{M}(R)=0\) can be solved by using the proposed FSLPs method as given in previous section for this system to find an approximation of the error function \(e_{M}(x)\).

7 Numerical examples

In this section, the efficiency and superiority of the proposed method is demonstrated by some illustrative examples. All algorithms are performed by Maple 17.

Example 1

Let us consider the Bagley-Torvik equation (12) with the following conditions [23, 26, 27]:

$$\begin{aligned}& A_{1}=A_{2}=A_{3}=1, \quad \quad \nu=1.5,\quad\quad 0 \leq x< 1,\quad\quad f(x)=x+1, \\& y(0) = 0, \quad\quad y(1)=2. \end{aligned}$$

The exact solution of this problem is

$$\begin{aligned} y(x) = x+1. \end{aligned}$$

The FSLPs basis and its fractional operational matrix have been applied for solving this fractional Bagley-Torvik equation. For \(\alpha=1\) and \(M=2\) the presented FSLPs collocation method results in the following linear system for the unknowns \(c_{0}\), \(c_{1}\), and w:

$$\begin{aligned} \left \{ \textstyle\begin{array}{l} 0.4815412180557289w-1.315554297200718c_{1}+2.313088247066488c_{0}\\ \quad{} -2.394848682426879=0,\\ -0.9690934013575259w-0.2844033784165936c_{1}+1.541045954136598c_{0}\\ \quad{} -1.542618852109541=0,\\ c_{1}+c_{2}-2=0, \end{array}\displaystyle \right . \end{aligned}$$

in which \(w=y^{\prime}(0)\) and \(y(x) = {c_{0}}{P_{(0,\alpha)}}(x) + {c_{1}}{P_{(1,\alpha)}}(x)\). Solving this linear system we obtain

$$\begin{aligned}& c_{0}=1.50000000000000000, \quad\quad c_{1}=0.499999999999999999,\\& w=1.00000000000000001. \end{aligned}$$

Hence, we get \(y(x)=1+x\) up to 15 digits precision which is the exact solution.

Example 2

In this example, we consider the Bagley-Torvik equation (12) with the following conditions [23, 26, 27]:

$$\begin{aligned}& A_{1}=0, \quad\quad A_{2}=A_{3}=1, \quad\quad \nu=1.5, \quad\quad 0 \leq x< 1,\\& f(x)=\frac{4\sqrt {x}}{\sqrt{\pi}}+t^{2}-t,\quad\quad y(0) = y(1)=0. \end{aligned}$$

The exact solution of this problem is

$$\begin{aligned} y(x) = x^{2}-x. \end{aligned}$$

To solve this problem we implemented the proposed FSLPs collocation method for \(M=3\) and \(\alpha=1\). For unknown \(c_{0}\), \(c_{1}\), \(c_{2}\), and \(w=y^{\prime}(0)\) this collocation method results in the following linear system:

$$\begin{aligned} \left \{ \textstyle\begin{array}{l} 0.2659615202674w-0.128326912161c_{3}-0.3492948536003c_{2}\\ \quad{} +0.9228845608024c_{1}-0.09075960810699=0, \\ -0.02846159933843w+0.2284361636687c_{3}-0.3277594131366c_{2}\\ \quad{} +0.3851597780939c_{1}-0.002340996934235=0, \\ -0.6287359595537w-0.026715336267c_{3}+0.033785072968c_{2}\\ \quad{} +1.456543013193c_{1}-0.3815262346441=0, \\ c_{1}+c_{2}+c_{3}=0, \end{array}\displaystyle \right . \end{aligned}$$

where \(w=y^{\prime}(0)\) and \(y(x) = {c_{0}}{P_{(0,\alpha)}}(x) + {c_{1}}{P_{(1,\alpha)}}(x)+{c_{2}}{P_{(2,\alpha)}}(x)\). By solving this linear system we get

$$\begin{aligned}& c_{0}=-0.166666666666684, \quad\quad c_{1}=2.06238653134019 \times10^{-14}, \\& c_{2}=0.166666666666664, \quad\quad w=-1.00000000000068, \end{aligned}$$

and this results the exact solution \(y(x) = x^{2}-x\) up to 14 digits precision.

Example 3

In this example, we consider the Bagley-Torvik equation (12) with the following conditions [23, 26, 27]:

$$\begin{aligned}& A_{1}=1, \quad\quad A_{2}=\frac{8}{17}, \quad\quad \quad A_{3}=\frac{13}{51}, \quad\quad\nu=1.5, \quad\quad0 \leq x< 1, \\& f(x)=\frac{x^{-0.5}}{89250\sqrt{\pi}} \bigl( 48p(t)+7\sqrt{\pi t}q(t) \bigr), \quad\quad y(0) = y(1)=0, \end{aligned}$$

in which

$$\begin{aligned}& p(t)= 16000x^{4}-32480x^{3}+21280x^{2}-4746x, \\& q(t)= 3250 x^{5}-9425x^{4}+264880x^{3}-448107x^{2}+233262x-34578. \end{aligned}$$

The exact solution of this problem is

$$\begin{aligned} y(x)= x^{5}-\frac{29x^{4}}{10}+\frac{76x^{3}}{25}-\frac {339x^{2}}{250}+ \frac{27x}{125}. \end{aligned}$$

Similar to the previous examples the FSLPs method has been used for solving this problem. After solving the linear system derived by the presented collocation method for \(\alpha=1\) and \(M=6\) we get the following values for the unknown coefficients:

$$\begin{aligned}& c_{0}= 0.002666666666667251, \quad\quad c_{1} = -0.004857142857142414, \\& c_{3} = 0.003047619047618773,\quad\quad c_{4} = 0.0008888888888886262, \\& c_{5} = -0.005714285714285992,\quad\quad c_{6} = 0.003968253968253756, \\& w= 0.2160000000000013, \end{aligned}$$

and this results in

$$\begin{aligned} y(x) =&0.9999999999999465x^{5}-2.899999999999885x^{4}+3.039999999999914x^{3} \\ &{}-1.355999999999974x^{2}+0.2159999999999985x+6.6 \times10^{-17}, \end{aligned}$$

which is the exact solution up to 17 digits precision.

Example 4

In this example, we consider the Bagley-Torvik equation (12) with the following conditions [22]:

$$\begin{aligned}& A_{1}=1,\quad\quad A_{2}=A_{3}=1, \quad\quad\nu=1.5, \quad\quad0 \leq x< 5, \\& f(x)=\frac{4\sqrt {x}}{\sqrt{\pi}}+x^{2}+x, \quad\quad y(0) =0, \quad\quad y(5)=25. \end{aligned}$$

The exact solution of this problem is

$$\begin{aligned} y(x)= x^{2}. \end{aligned}$$

Similar to the previous examples the FSLPs method has been used for solving this problem and by solving the linear system derived by the presented collocation method for \(\alpha=1\) and \(M=3\) we get

$$\begin{aligned}& c_{0}= 8.333333333333209, \quad\quad c_{1} = 12.50000000000000,\\& c_{3} = 4.166666666666795, \quad\quad c_{4} = -0.1407964170385217\times10^{-12}. \end{aligned}$$

and this results in the solution function in the interval \([0, 1]\) as

$$\begin{aligned} y(t)=25.00000000000077x^{2}-7.710^{-13}x+4.010^{-15}. \end{aligned}$$

By the change of variable \(t=\frac{x}{5}\) in this function we get

$$\begin{aligned} 1.000000000000031x^{2}-1.54000000000000010^{-13}x+4.0 \times10^{-15}, \end{aligned}$$

which is the exact solution up to 15 digits precision.

Example 5

Consider the fractional Bagley-Torvik equation (12) with the following conditions [23, 2527]:

$$\begin{aligned}& A_{1}=1, \quad\quad A_{2}=0.5,\quad\quad A_{3}=0.5, \quad\quad \nu=1.5, \quad\quad 0 \leq x< 20, \\& y(0) = 0, \quad\quad y^{\prime}(0)=0, \quad\quad f(x) = \left \{ \textstyle\begin{array}{l@{\quad}l} 8, & 0 \le x \le1,\\ 0, & x > 1. \end{array}\displaystyle \right . \end{aligned}$$

The exact solution of equation is given by

$$\begin{aligned} y(x) = \int_{0}^{x} {{G_{3}}(x - t)f(t)\,dt,} \end{aligned}$$

in which \({G_{3}}(t) = \frac{1}{{{A_{1}}}}\sum_{r = 0}^{\infty}{\frac {{{{ ( { - 1} )}^{r}}}}{{r!}}} { ( {\frac {{{A_{3}}}}{{{A_{1}}}}} )^{r}}{t^{2r + 1}}E_{\frac{1}{2},\frac {{3r}}{2} + 2}^{(r)} ( {\frac{{{A_{2}}}}{{{A_{1}}}}{t^{\frac{1}{2}}}} )\) and \(E_{\lambda, \mu}\) is called the Mittag-Leffler function in two parameters \(\lambda, \mu>0\) and

$$\begin{aligned} E_{\lambda,\mu}^{(r)}(z) = \frac{{{d^{r}}{E_{\lambda,\mu }}(z)}}{{d{x^{r}}}} = \sum _{j = 0}^{\infty}{\frac{{ ( {j + r} )!{z^{j}}}}{{j!\Gamma(\lambda j + \lambda r + \mu)}}}, \quad r = 0,1,2,\ldots. \end{aligned}$$

The proposed FSLPs collocation method is implemented for solving this fractional Bagley-Torvik equation. Figure 1 shows the exact and approximate solution for \(\alpha=0.5, 1\) and \(M=20\). The absolute errors for the obtained numerical solutions with \(\alpha=0.5\) and \(\alpha=1\) are plotted in Figure 2. Moreover, a comparison between the results achieved by the proposed FSLPs method with \(M=17\) and other methods in Refs. [23, 27] is presented in Table 1. From Table 1 we can immediately see that the FSLPs method, in comparison to other existing methods, is more efficient and accurate.

Figure 1
figure 1

The exact and approximate solution for \(\pmb{\alpha =0.5, 1}\) and \(\pmb{M=20}\) .

Figure 2
figure 2

The absolute error of the obtained results. We took (a) \(\alpha=1\) and (b) \(\alpha=0.5\).

Table 1 Comparison of the numerical solution for \(\pmb{\nu=1.5}\) , \(\pmb{\alpha =0.5, 1}\) , and \(\pmb{M=17}\) with other results in [ 23 , 27 ]

8 Discussion and conclusion

A new type of orthonormal fractional-order Legendre polynomials is defined. The operational matrix of fractional integration for this fractional-order basis is derived. By using this fractional operational matrix and collocation method a numerical method is proposed for solving the fractional Bagley-Torvik equations. A comparison is made between numerical results derived by the presented collocation method and other existing numerical method. According to the numerical results, we can conclude that the presented method is more accurate and effective for a numerical solution of the fractional Bagley-Torvik equations.