1 Introduction

Fractional calculus is an old mathematical topic from the 17th century, used to model many phenomena. Its applications in physics and engineering include viscoelastic materials (Bagley and Torvik 1985), statistical mechanics (Mainardi 1997), solid mechanics (Rossikhin and Shitikova 1997), etc. An application to economics is reported in (Baillie 1996).

Different numerical methods have been used to solve a variety of various kind of fractional equations. For example, Legendre wavelet method (Jafari et al. 2011), B-Spline functions (Lakestani 2017), Chebyshev polynomials (Sedaghat et al. 2012), fractional-order general Lagrange scaling functions (Sabermahani et al. 2019) and so on.

In recent years, the concepts of variable-order fractional integral and derivative have been introduced. Researchers have studied the applications of this type of problem. Variable-order fractional calculus is used to model such phenomena as transient dispersion in heterogeneous media (Sun et al. 2014), anomalous diffusions with variable and random orders (Sun et al. 2010), alcoholism (Gomez-Aguilar 2018), glass transition from amorphous networks to shape-memory behavior (Xiao et al. 2013), viscoelastic and elastoplastic spherical indentation (Ingman et al. 2000) and so on.

An important application of fractional calculus of variable-order is the modelling of shape-memory polymers (SMPs) (Li et al. 2017).

A SMP is a polymer material which can be temporarily deformed in response to an external stimulus such as change in temperature and light, then return to its initial shape (Xiao et al. 2013).

SMPs have attracted the attention of many researchers in fundamental investigation and technology innovation. An important particular case of SMP is the shape-memory nanocomposites (SMCs), where the incorporation of functional inorganic nanofillers in the shape-memory polymer matrices is purposely performed. Such materials can be used in medical devices, self-healing systems, sensors, controllable devices, adaptive and deployable structures, etc (Pilate et al. 2016).

Figure 1 shows examples of the ability to change the shape memory in photoresponsive materials and the effect of light and temperature on restoring its initial shape.

Fig. 1
figure 1

Adapted from Pilate et al. (2016)

Shape-memory effect of photoresponsive polymers. a A film of grafted polymer. (a) Permanent shape; (b) temporary shape; (c) recovered permanent shape. b An IPN polymer film. (a) Permanent shape; (b) corkscrew spiral temporary shape; (c) recovered shape obtained by irradiation with UV light.

In this study, one of our examples is dedicated to the numerical solution of the SMP model.

There have not been many studies on the numerical analysis of VOFDEs. Lin et al. 2009 have examined the stability and convergence of finite difference method for the variable-order fractional diffusion equation. Several numerical techniques have been used to solve this type of problems such as the method based on Legendre wavelets (Chen et al. 2015; Hosseininia and Heydari 2019a), finite difference method (Sun et al. 2012), Bernstein operational matrices (Omar and Mohammed 2017), a shifted Legendre–Gauss–Radau collocation approach (Bhrawyi et al. 2017), Gegenbauer wavelets (Usman et al. 2018), Bernstein polynomials (Chen et al. 2016), method based on Chebyshev cardinal functions (Heydari et al. 2019a), Adams–Bashforth–Moulton method (Ma et al. 2012), reproducing kernel (Li and Wu 2017; Jia et al. 2017), the polynomial least squares method (Bota and Căruntu 2017), wavelet method (Hosseininia et al. 2019; Heydari et al. 2019b), meshfree approach (Shekari et al. 2019), meshfree moving least squares method (Hosseininia and Heydari 2019b) and so on.

Lagrange polynomials are a well-known mathematical tool. There are different ways of choosing the nodes for Lagrange interpolation (\(t_{i}, i=0, 1, \ldots , N\)). If we consider \(t_{i}\) as zeros of orthogonal polynomials (such as Legendre polynomials, Chebyshev polynomials, etc), we derive a set of orthogonal Lagrange polynomials (Szegö 1967).

In this case, the properties of the orthogonal polynomials can be combined with features of Lagrange interpolation.

In this work, we first recall in Sect. 2 some known preliminaries which are used in this study. In Sect. 3, we present the Tau-Collocation algorithm and matrix representation of present method for solving fractional differential equations of variable-order. Also, we discuss the numerical solvability of the Lagrange-Tau algebraic system in the case of a linear equation. Error analysis is proposed in Sect. 4. In Sect. 5, we present some tests and their numerical results to display the high accuracy and efficiency of proposed method.

Here, the general form of the fractional differential equations of variable-order is considered as follows:

$$\begin{aligned} D^{\gamma (t)}u(t) = F(t, u(t), D^{\gamma _{1}(t)}u(t), D^{\gamma _{2}(t)}u(t), \ldots , D^{\gamma _{n}(t)}u(t)), \end{aligned}$$
(1)

on the interval \(t \in [0, 1]\), subject to

$$\begin{aligned} u(0)=u_{0}, \end{aligned}$$

where \(0 < \gamma (t) \le 1\), \(0< \gamma _{1}(t)< \gamma _{2}(t)< \ldots \gamma _{n}(t) < \gamma (t)\).

2 Preliminaries

This section provides some definitions and notations that are used in this study.

Definition 2.1

The Caputo’s fractional derivative of order \(\gamma \) is defined as (Podlubny 1999)

$$\begin{aligned} D^ \gamma u(t) = \left\{ \begin{array}{ll} \frac{1}{\varGamma (m- \gamma )}\int _{0}^{t} \frac{u^{(m)}(\tau )}{(t-\tau )^{\gamma -m+1}} {\rm d} \tau ,&{} m-1< \gamma < m,\;m \in N, t > 0 \\ \\ \frac{d^{m}f(t)}{{\rm d}t^{m}} &{} \gamma =m \end{array}\right. \end{aligned}$$

For the Caputo derivative, we have:

  1. 1.
    $$\begin{aligned} D^ \gamma t^k = \left\{ \begin{array}{ll} 0,&{}\gamma \in N_{0},\; k < \gamma ,\\ \frac{\varGamma (k+1)}{\varGamma (k- \gamma +1)} t^{k- \gamma }, &{} {\text{otherwise}}. \end{array}\right. \end{aligned}$$
    (2)
  2. 2.
    $$\begin{aligned} D^ \gamma \lambda =0, \end{aligned}$$

    where \(\lambda \) is constant.

Definition 2.2

Let \(u:\;[0, 1] \rightarrow R\) be a function, \(\gamma > 0\) a real number and \(m= \lceil \gamma \rceil \), where \(\lceil \gamma \rceil \) denotes the smallest integer greater than or equal to \(\gamma \), the Riemann–Liouville fractional integral is defined as (Podlubny 1999)

$$\begin{aligned} I^{\gamma }u(t) = \frac{1}{\varGamma (\gamma )} \int _{0}^{t} (t-\tau )^{\gamma -1} u (\tau ) {\rm d} \tau , \quad \gamma>0,\;t>0, \end{aligned}$$

For this fractional integral, we have

$$\begin{aligned} I^{\gamma } t^{n} = \frac{\varGamma (n+1)}{\varGamma (n+1+ \gamma )} t^{\gamma + n},\;\;\;n> -1. \end{aligned}$$
(3)

and

$$\begin{aligned}&(D^{\gamma } I^{\gamma } u)(t) = u(t),\\&(I^{\gamma } D^{\gamma }u)(t) = u(t) - \sum _{i=0}^{\lceil \gamma \rceil -1} u^{(i)}(0) \frac{t^{i}}{i!},\\&I^{\gamma }(\lambda _{1}u(t)+\lambda _{2}w(t))=\lambda _{1}I^{\gamma }u(t)+\lambda _{2} I^{\gamma }w(t). \end{aligned}$$

Definition 2.3

The variable order of Riemann–Liouville fractional integral operator is defined by (Doha et al. 2017; Samko 1995)

$$\begin{aligned} I^{\gamma (t)}u(t)= \frac{1}{\varGamma (\gamma (t))} \int _{0}^{t} (t- \tau )^{\gamma (t)-1}u(\tau ) {\rm d} \tau . \end{aligned}$$
(4)

Moreover, we have the following property (Bahaa 2017)

$$\begin{aligned} I^{\gamma (t)}t^{k}= \left\{ \begin{array}{ll} \frac{\varGamma (k+1)}{\varGamma (k+ \gamma (t) +1)} t^{k+ \gamma (t)}, &{} m \le k \in N,\\ 0 &{} {\text{otherwise}}. \end{array}\right. \end{aligned}$$
(5)

Definition 2.4

The variable order of Caputo’s fractional derivative operator is defined by (Bhrawyi et al. 2017; Zhao et al. 2015)

$$\begin{aligned} D^{\gamma (t)}u(t) = \frac{1}{\varGamma (m-\gamma (t))} \int _{0}^{t} \frac{u^{(m)}(\tau )}{(t-\tau )^{\gamma (t) -m+1}} {\rm d} \tau , \quad t>0, \end{aligned}$$
(6)

where \(m-1<\gamma (t) < m\).

Also, we get the following property (Hassani et al. 2017)

$$\begin{aligned} D^{\gamma (t)}t^{k}= \left\{ \begin{array}{ll} \frac{\varGamma (k+1)}{\varGamma (k- \gamma (t) +1)} t^{k- \gamma (t)}, &{} m \le k \in N,\\ 0 &{} {\text{otherwise}}. \end{array}\right. \end{aligned}$$
(7)

Definition 2.5

Suppose that \(\forall t\in [0, 1], 0< \gamma (t) <1, I^{1-\gamma (t)} f \in C[0, 1]\). Then, the variable of Caputo fractional derivative for \(t>0\) is defined by (Bahaa 2017; Bhrawyi et al. 2017)

$$\begin{aligned} D^{\gamma (t)}f(t) = I^{1- \gamma (t)} \frac{\rm d}{{\rm d}t} f(t). \end{aligned}$$
(8)

2.1 Lagrange Polynomials

Consider a set of nodes \(t_{i} \in [0, 1],\;i=0, 1, \ldots , N\). Then, the Lagrange polynomials can be defined as follows (Stoer and Bulirsch 2013):

$$\begin{aligned} L_{i}(t) := \prod _{\tiny {\begin{array}{c} j=0 \\ i \ne j \end{array}}}^{N} \frac{(t-t_{j})}{(t_{i} -t_{j})}. \end{aligned}$$
(9)

Moreover, in these points, the Lagrange polynomials are also described by (Sabermahani et al. 2018)

$$\begin{aligned} L_{i}(t) = \sum _{s=0}^{N} \beta _{is} t^{N-s}, \quad i=0, 1, \ldots , N, \end{aligned}$$
(10)

where

$$\begin{aligned} \beta _{i0}= & {} \frac{1}{\prod _{\tiny {\begin{array}{c} j=0 \\ i \ne j \end{array}}}^{N}(t_{i}-t_{j})} \\ \beta _{is}= & {} \frac{(-1)^{s}}{\prod _{\tiny {\begin{array}{c} j=0 \\ i \ne j \end{array}}}^{N}(t_{i}-t_{j})} \sum _{k_{s}=k_{s-1}+1}^{N} \cdots \sum _{k_{1}=0}^{N-s+1} \prod _{r=1}^{s} t_{k_{r}}, \end{aligned}$$

where \(s=1,\;2, \ldots ,\;N, \; \; i \ne k_{1} \ne \ldots \ne k_{s}\).

In this study, the nodes \(t_{i},\;(i=0, 1, \ldots , N)\) are the zeros of the shifted Legendre polynomial \(P_{N+1}\) of order \(N+1\) on [0, 1]. The system \(L_i, i=0,1,2, \ldots , N\) forms a set of orthogonal polynomials (Szegö 1967).

3 Description of Numerical Method

Let \(L(t)= \{ L_{0}(t), L_{1}(t), \ldots , L_{N}(t) \}\) be a set of Lagrange polynomials. We define \(u_{N}(t)\) as a Tau approximation of u(t) as follows

$$\begin{aligned} u_{N}(t) \simeq \sum _{i=0}^{N}u_{i}L_{i}(t) = U_{N}^{T}L(t), \end{aligned}$$
(11)

where

$$\begin{aligned} U_{N}=[u_{0}, u_{1}, \ldots , u_{N}]^{T}, \end{aligned}$$
(12)

and using Eq. (10), we have

$$\begin{aligned} L(t) = B X_t. \end{aligned}$$
(13)

where

$$\begin{aligned} X_{t} = [1, t, t^{2}, \ldots , t^{N}]^{T}, \quad B=[\beta _{ij}], \end{aligned}$$
(14)

The following lemma describes the effect of the variable-order of derivative on a given set of Lagrange polynomials.

Lemma 3.1

Matrix representing the effect Caputo’s variable-order derivative on the coefficients of the Lagrange polynomials in Eq. ( 13 ) is given by

$$\begin{aligned} D^{\gamma (t)}u_{N}(t) = I^{1- \gamma (t)} \frac{\rm d}{{\rm d}t} u_{N}(t) \simeq U_{N}^{T} \tilde{\mu } ^{\gamma }_{t} X_{t}, \end{aligned}$$
(15)

where \(\tilde{\mu } ^{\gamma }_{t}= B D_{t} \mu ^{\gamma }_{t}\) , \(D_{t}\) is derivative operational matrix of Taylor polynomials and

$$\begin{aligned} \mu ^{\gamma }_{t} = \left[ {\begin{array}{cccccccccccc} \frac{ t^{1-\gamma (t)} \varGamma (1)}{\varGamma (2-\gamma (t))} &{} 0&{} \cdots &{} 0 &{} \cdots &{} 0 \\ 0 &{} \frac{ t^{1-\gamma (t)} \varGamma (2)}{\varGamma (3-\gamma (t))} &{} \cdots &{} 0 &{} \cdots &{} 0 \\ \vdots &{} \vdots &{} \ddots &{} \vdots &{}\ddots &{} \vdots \\ 0 &{}0&{}0&{} \frac{ t^{1-\gamma (t)} \varGamma (m+1)}{\varGamma (m+2-\gamma (t))} &{} \cdots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \ddots &{} \vdots \\ 0 &{} 0 &{} 0&{} \cdots &{} 0 &{} \frac{ t^{1-\gamma (t)} \varGamma (N+1)}{\varGamma (N+2-\gamma (t))}\\ \end{array}} \right] . \end{aligned}$$

Proof

The analytic form of the Lagrange polynomials is given by Eq. (13). Using Eqs. (5), (13) and \(0 < \gamma (t) \le 1\), for the variable-order derivative, we get

$$\begin{aligned} D^{\gamma (t)} u_{N}(t)= & {} I^{1- \gamma (t)} \frac{\rm d}{{\rm d}t} u_{N}(t) \simeq I^{1- \gamma (t)} \frac{\rm d}{{\rm d}t} (U_{N}^{T} B X_{t}) \nonumber \\= & {} U_{N}^{T}B I^{1- \gamma (t)} \frac{\rm d}{{\rm d}t} (X_{t}) = U_{N}^{T}B D_{t} I^{1- \gamma (t)} (X_{t})\nonumber \\= & {} U_{N}^{T}B D_{t} \left[ \frac{\varGamma (1)}{\varGamma (2- \gamma (t))}t^{1- \gamma (t)}, \frac{\varGamma (2)}{\varGamma (3-\gamma (t))} t^{2- \gamma (t)}, \right. \\&\left. \ldots , \frac{ \varGamma (N+1)}{\varGamma (N+2-\gamma (t))}t^{N+1- \gamma (t)}\right] ^{T} \nonumber \\= & {} U_{N}^{T}B D_{t} \mu _{t}^{\gamma }X_{t} , \end{aligned}$$

so the proof is complete. \(\square \)

Now, using the Lagrange polynomials as basis functions, we employ the Tau-Collocation method together with matrix representing the effect Caputo’s variable-order derivative in order to transform the problem (1) into a system of algebraic equations.

Substituting Eqs. (11)–(15) in problem (1), we derive

$$\begin{aligned} U_{N}^{T}\tilde{\mu } ^{\gamma }_{t} X_{t} = F( t, U_{N}^{T}\tilde{\mu } ^{\gamma _{1}}_{t} X_{t}, U_{N}^{T}\tilde{\mu } ^{\gamma _{2}}_{t} X_{t} , \ldots , U_{N}^{T}\tilde{\mu } ^{\gamma _{n}}_{t} X_{t}), \end{aligned}$$
(16)

with initial condition

$$\begin{aligned} U_{N}^{T} B X_{t}(0) = u_{0}. \end{aligned}$$

As in the Tau method, the basic idea of the Tau-Collocation method is to add, a perturbation term \(H_{N}(t)\) to the right hand side of Eq. (16). We consider \(H_{N}(t)\) as follows

$$\begin{aligned} H_{N}(t)=g(t, \tau _{0}, \tau _{1}, \ldots , \tau _{\phi -1})L_{N-m+1}(t), \end{aligned}$$

where \(g(t, \tau _{0}, \tau _{1}, \ldots , \tau _{\phi -1})\) is a function of t and \(\tau _{i}, i = 1,2, \ldots , \phi -1\) are free parameters for this function. Since \(L_{N-m + 1} (t)\) is an orthogonal polynomial, then we get

$$\begin{aligned} U_{N}^{T}\tilde{\mu } ^{\gamma }_{t} X_{t}-F( t, U_{N}^{T}\tilde{\mu } ^{\gamma _{1}}_{t} X_{t}, U_{N}^{T}\tilde{\mu } ^{\gamma _{2}}_{t} X_{t} , \ldots , U_{N}^{T}\tilde{\mu } ^{\gamma _{n}}_{t} X_{t}) = H_{N}(t), \end{aligned}$$
(17)

with initial condition

$$\begin{aligned} U_{N}^{T} B X_{t}(0) = u_{0}. \end{aligned}$$

As proved in (Ortiz and El-Daou 1998), the classical collocation method with collocation points \(c_j\) is equivalent to the Tau method with a polynomial perturbation term M(t), if \(c_j\) are the roots of M(t). In the case of the Tau-Collocation method proposed here, the roots of the perturbation term \(H_{N}(t)\) coincide with the roots of the polynomial \(L_{N-m+1}(t)\), which are also the collocation points. Therefore, the Tau-Collocation method can be applied as the usual collocation method, independently of the form of the perturbation term \(H_{N}(t)\). When the collocation method is applied to Eq. (17) using \(N-m+1\) roots of \(L_{N-m+1}(t)\) as collocation nodes, we derive a system of algebraic equations. Solving this system by an adequate numerical method, we achieve the unknown vector \(U_N\).

3.1 Numerical Solvability of the Lagrange-Tau Algebraic System

Here, we consider the Lagrange-Tau algebraic system, Eq. (16), and we discuss the numerical solvability of this system in the case of a linear equation.

In this discussion, we use the bounded and compact operator’s theory. For simplicity, consider following equation

$$\begin{aligned} D^{\gamma (t)}u(t)=u(t)+f(t), \quad t \in \varOmega = [0, 1] \end{aligned}$$
(18)

with the initial conditions

$$\begin{aligned} u(0) = u_{0}, \end{aligned}$$
(19)

where u(t) satisfies in Eqs. (18), (19).

Suppose that \(K \in (L^{2}(\varOmega ))^{2}\) and \({\mathcal {K}}: L^{2}(\varOmega ) \rightarrow L^{2}(\varOmega )\) is defined as follows

$$\begin{aligned} ({\mathcal {K}}u)(t) = \int _{0}^{t} K(t, s)u(s) {\rm d}s, \quad t \in \varOmega , \end{aligned}$$

\({\mathcal {K}}\) is a linear and compact operator. The integral operators with weakly singular kernel functions are linear, bounded and compact operators. So, if \(u(t) \in H^{1}(\varOmega )\), then the variable-order Caputo’s fractional derivative operator \(D^{\gamma (t)}u(t): H^{1}(\varOmega ) \rightarrow L^{2}(\varOmega )\) is a linear and compact operator, where \(H^{1}(\varOmega )\) is the well-known Sobolev space.

Theorem 3.1

(Atkinson and Han 2009) Assume that \(V, {\tilde{V}}\)are Banach spaces and \(\{{\mathcal {P}}_{N}\}\)is a family of bounded projections on\({\tilde{V}}\)with

$$\begin{aligned} {\mathcal {P}}_{N} \nu \rightarrow \nu , \quad as \quad n \rightarrow \infty , \end{aligned}$$

where\( \nu \in V\). Let\( {\mathcal {W}}: V \rightarrow {\tilde{V}}\)be a compact operator, then

$$\begin{aligned} \Vert {\mathcal {W}}-{\mathcal {P}}_{N} {\mathcal {W}} \Vert \rightarrow 0, \quad as \quad n \rightarrow \infty . \end{aligned}$$

Theorem 3.2

(Atkinson and Han 2009) Let \({\mathcal {W}}: V \rightarrow {\tilde{V}}\)be bounded and at least one is a Banach space and\(\lambda - {\mathcal {W}}: V \rightarrow {\tilde{V}}, \lambda \in {\mathcal {C}}\)is bijective. Moreover, suppose that

$$\begin{aligned} \Vert {\mathcal {W}}-{\mathcal {P}}_{N} {\mathcal {W}} \Vert \rightarrow 0, \quad as \quad n \rightarrow \infty , \end{aligned}$$

then, the bounded operator\((\lambda - {\mathcal {P}}_{N}{\mathcal {W}})^{-1}: {\tilde{V}} \rightarrow V\)exists.

We presume the orthogonal projection \(Y_{N}: {\tilde{V}} \rightarrow V\) , where \({\tilde{V}} = R \times L^{2}(\varOmega )\), \(V= R \times {\mathcal {P}}_{N}^{M}\) and \({\mathcal {P}}_{N}^{M} = \{ L_{0}(t), L_{1}(t), \ldots , L_{N}(t) \}\).

Now, consider Eq. (18) that is a special form of Eq. (1). Let the Eq. (18) must be solved. By approximating this equation by Lagrange-Tau method, we have the following problem

$$\begin{aligned} Y_{N} \left( \begin{array}{ll} I_{d} + D^{\gamma (t)}\\ \quad \quad B \end{array}\right) {\tilde{u}}_{N}= Y_{N} \left( \begin{array}{ll} f\\ 0 \end{array}\right) , \quad {\tilde{u}}_{N} \in {\mathcal {P}}_{N}^{M}. \end{aligned}$$

where B and \(I_{d}\) are the linear initial and the identity operator, respectively. The method is implemented in this form, as it converts directly to an equivalent finite linear system, special form of Eq. (16). We can rewrite this equation as

$$\begin{aligned} \left( \begin{array}{ll} I_{d} \\ 0 \end{array}\right) {\tilde{u}}_{N}- Y_{N} \left( \begin{array}{ll} - D^{\gamma (t)}\\ -B \end{array}\right) {\tilde{u}}_{N}= Y_{N} \left( \begin{array}{ll} f\\ 0 \end{array}\right) , \quad {\tilde{u}}_{N} \in {\mathcal {P}}_{N}^{M}. \end{aligned}$$

Let

$$\begin{aligned} {\tilde{I}}= \left( \begin{array}{ll} I_{d} \\ 0 \end{array}\right) , \quad {\tilde{D}} = \left( \begin{array}{ll} - D^{\gamma (t)}\\ -B \end{array}\right) , \quad {\tilde{f}} = \left( \begin{array}{ll} f\\ 0 \end{array}\right) . \end{aligned}$$

Therefore, we have

$$\begin{aligned} ({\tilde{I}}-Y_{N} {\tilde{D}}) {\tilde{u}}_{N} = Y_{N} {\tilde{f}}. \end{aligned}$$

\({\tilde{u}} \in H^{1}(\varOmega )\), the operator \(D^{\gamma (t)}: H^{1}(\varOmega ) \rightarrow L^{2}(\varOmega )\) is bounded and compact, then \({\tilde{D}}\) is a linear, bounded and compact operator. Therefore, by Theorems 3.1 and 3.2 display the operator \(({\tilde{I}}-Y_{N} {\tilde{D}})^{-1}\) exists and is bounded. Thus, the Legendre-Tau numerical solution of Eq. (18) exists and is unique.

4 Error Analysis

Here, we propose a technique for estimating the error of the Lagrange-Tau-Collocation method.

For simplicity, we rewrite this problem in the following form

$$\begin{aligned} D^{\gamma (t)}u(t)=u(t)+f(t), \end{aligned}$$
(20)

with the initial conditions

$$\begin{aligned} u(0) = u_{0}, \end{aligned}$$
(21)

where u(t) satisfies in Eqs. (20), (21). Moreover, \(u_{N}(t)\) satisfies in the Tau problem as follows

$$\begin{aligned} D^{\gamma (t)}u_{N}(t)=u_{N}(t)+f(t)+H_{N}(t), \end{aligned}$$
(22)

with

$$\begin{aligned} u_{N}(0) = u_{0}, \end{aligned}$$
(23)

We define an error function as

$$\begin{aligned} \varepsilon _{N}(t) = u(t)- u_{N}(t). \end{aligned}$$

Subtracting Eq. (22) from (20), we obtain

$$\begin{aligned} D^{\gamma (t)}u(t) - D^{\gamma (t)}u_{N}(t) = u(t)-u_{N}(t) +f(t) - (f(t)+H_{N}(t)), \end{aligned}$$

which can be rewritten as

$$\begin{aligned} D^{\gamma (t)} \varepsilon _{N}(t) = \varepsilon _{N}(t) -H_{N}(t). \end{aligned}$$
(24)

Moreover, from Eqs. (23) and (21), we conclude that

$$\begin{aligned} \varepsilon _{N}(0) = 0, \end{aligned}$$
(25)

Now, if we apply the Tau-Collocation method to solve Eqs. (24), (25), we obtain the Tau problem

$$\begin{aligned} D^{\gamma (t)} \varepsilon _{N,M}(t) = \varepsilon _{N,M}(t) -H_{N}(t)+H_{M}(t), \end{aligned}$$
(26)

with initial conditions

$$\begin{aligned} \varepsilon _{N,M}(0) = 0, \end{aligned}$$
(27)

By solving the problem (26), (27) we obtain \( \varepsilon _{N,M}(t)\) which is an approximation of \( \varepsilon _{N}(t)\) by the Lagrange-Tau-Collocation method with \(M \ge N\) and can be used to achieve a more accurate result.

Remark 4.1

Suppose that \(u_{N}(t)= \sum _{i=0}^{N} u_{i}L_{i}(t)\) is the best approximation of u on the interval [0, 1] and \(U= span \{ L_{0}(t), L_{1}(t), \ldots , L_{N}(t) \}\). Then, using Taylor’s formula and according to concept of the best approximation, we have

$$\begin{aligned} \Vert u- u_{N} \Vert _{L^{2}[0,1]} \le \frac{\sup _{t \in [0,1]} \vert u^{(N)}(t) \vert }{N!(2N+1)} \end{aligned}$$

Since, N is constant. We conclude that \(u_{N}(t)\) converges to u(t) as N tends to infinity.

Remark 4.2

Matrix representing the effect Caputo’s variable-order derivative presented in Lemma 3.1 is obtained without any approximation. So its error is zero. On the other hand, Tau-Collocation method is convergent (Canuto et al. 2006). Consequently, with respect to this and Remark 4.1, it can be concluded that the proposed method is convergent.

5 Numerical Results and Illustrative Test Problems

In order to evaluate the advantages and the efficiency and accuracy of this method to solve VOFDEs, we have applied this method to some examples. The computations associated with the tests have been performed using Mathematica 10.0.

Example 1

Here, we consider the variable order \(\gamma (t)\) for a linear VOFDE modelling the shape-memory behavior which has the form (Li et al. 2017)

$$\begin{aligned} D^{\gamma (t)}u(t)=f(t), \quad 0< \gamma (t) <1, \quad t \in [0, 1], \end{aligned}$$
(28)

with \(u(0) =0\) and \(\gamma (t)=0.65+0.2t^{2}, f(t)= \frac{2t^{1.35-0.2t^{2}}}{\varGamma (2.35-0.2t^{2})}\). The analytic solution of Eq. (28) is \(u(t)=t^{2}\). We apply the present method with \(N=2\) for solving this problem. Figure 2a displays the absolute error of numerical results for this equation. By comparing the numerical results obtained from our method with the method presented in Li and Wu (2017), we can see that our results are much more accurate even with a smaller number of basis functions.

Additionally, we present an error estimate obtained by the method described in Sect. 4. Figure 2b displays the error estimate of this problem for \(M=N=2\).

Fig. 2
figure 2

a Absolute error of approximate solutions for \(N=2\), b error estimate of the present method for \(N=2\) in Example 1

Example 2

Consider the following linear VOFDE (Chen et al. 2015)

$$\begin{aligned} D^{\gamma (t)}u(t)-10u^{\prime }(t)+u(t) = f(t), \quad t \in [0, 1], \quad 0< \gamma (t) <1, \end{aligned}$$
(29)

subject to

$$\begin{aligned} u(0)=5, \end{aligned}$$

the variable order is chosen to be \(\gamma (t) = \frac{t+2e^{t}}{7}\), and

$$\begin{aligned} f(t) = 10\left[\frac{2-\gamma (t)}{\varGamma (3- \gamma (t)} + \frac{t^{1-\gamma (t)}}{\varGamma (2- \gamma (t))}\right]+5t^{2}-90t-95. \end{aligned}$$

The analytic solution of Eq. (29) is \(u(t) = 5(1+t)^{2}\). We apply the present method for solving this problem with \(N=2\), then the problem can be transformed into the following equation

$$\begin{aligned} U_{2}^{T} \tilde{\mu }_{t}^{\gamma }X_{t} - 10 U_{2}^{T} \tilde{\mu }_{t}^{\gamma _{1}}X_{t} +U_{2}^{T} BX_{t}=f(t)+H_{2}(t). \end{aligned}$$
(30)

Then, by using the collocation method, we derive the numerical solution for this problem. The absolute error of the present scheme is displayed in Table 1 and compared with the errors obtained by the finite difference scheme(FDS) (Chen et al. 2015) and Legendre wavelet method reported in (Chen et al. 2015). From this Table, we can see that this method is efficient to solve this equation.

Table 1 Comparison of absolute errors of approximate solutions for Example 2

Example 3

We consider the following VOFDE (Bhrawyi et al. 2017)

$$\begin{aligned} D^{\gamma (t)}u(t) +3u^{\prime }(t)-u(t)= f(t), \quad 0< \gamma (t) < 1, \end{aligned}$$
(31)

with \(u(0)=0\),

$$\begin{aligned} f(t)=e^{t}\left[3-\frac{\varGamma (1-\gamma (t),t)}{\varGamma (1-\gamma (t))}\right] \end{aligned}$$

and \(\gamma (t)= \frac{1+\cos ^{2}(t)}{4}\).

The analytic solution is \(u(t)=e^{t}\). The absolute errors of the approximation obtained by the present method using various values of N are shown in Table 2. From these results, we can see that this method provides high accuracy when applied to the given equation.

Table 2 Comparison of absolute errors of the approximate solutions for Example 3

Example 4

Consider the nonlinear VOFDE (Hassani et al. 2017)

$$\begin{aligned} D^{\gamma (t)}u(t) +\sin (t)u^{2}(t) = f(t), \quad 0< \gamma (t) \le 1, \end{aligned}$$
(32)

with \(u(0)=0, \; \gamma (t)=1-0.5 e^{-t}\) and \(f(t) = \frac{\varGamma (\frac{9}{2})+t^{\frac{7}{2}- \gamma (t)}}{\varGamma (\frac{9}{2}- \gamma (t))}+\sin (t)t^{7}\).

The exact solution of Eq. (32) is \(u(t) = t^{\frac{7}{2}}\). This equation is solved by using the present method with \(N=6, 10\). The graph of the absolute error for this problem is displayed in Fig. 3. The absolute errors of our results with \(N=6, 10\) are displayed in Table 3.

Fig. 3
figure 3

Absolute error of the present method for \(N=10\), in Example 4

Table 3 Absolute errors of the present method for Example 4

Example 5

Consider the following nonlinear VOFDE

$$\begin{aligned} D^{\gamma (t)}u(t)-2Du(t)-u^{2}(t) = f(t), \quad t \in [0, 1],\quad 0< \gamma (t) <1, \end{aligned}$$
(33)

and the function f(t) is selected so that the analytical solution of Eq. (33) is \(u(t)=\cos (t)\). By applying the proposed technique, we solve this problem, numerically with \(N=6\). Figure 4a displays a comparison between the curves of the analytic and approximate solutions this value of N. The absolute error of the numerical solutions for \(N=6\) is plotted in Fig. 4b. In conclusion, Fig. 4 demonstrates the effectiveness of the present method when applied to this nonlinear problem.

Fig. 4
figure 4

a Analytic and numerical solution, b absolute error of the present method for \(N=6\), in Example 5

6 Conclusion

The aim of the present paper is to develop an efficient and accurate method to solve VOFDEs by using the well-known Tau-Collocation method based on Lagrange polynomials. The effect of the Caputo’s variable-order derivative on the coefficients of the Lagrange polynomials is obtained. This effect and the Tau-Collocation method are utilized to transform the initial equation into a system of algebraic equations. Moreover, we employ the present technique for the numerical solution of an equation modelling the behavior of a the shape-memory polymer. We discuss the numerical solvability of the variable-order of Lagrange-Tau algebraic system and presented the convergence analysis. The accuracy, validity and applicability of this scheme are confirmed by the numerical results.