1 Introduction

In recent years, considerable attention has been given to the fractional calculus, which is used in modeling and analysis of a wide range of problems in science and engineering, including chemistry, finance, physics, aerodynamics, electrodynamics, polymer rheology, economics and biophysics [2, 3, 7, 11, 27, 32, 35, 36].

Fractional calculus extends the concept of ordinary differentiation and integration to an arbitrary non-integer order. Recently, there has been a growing interest in fractional differential equations. Since most fractional differential equations do not have analytic solutions, several numerical methods such as the homotopy-perturbation method [1], variational iteration method [33], Adomian decomposition method [5] and finite difference approximation methods [39] have been used to obtain approximate solutions.

Here, we recall the basic definitions of fractional calculus theory [24, 27] which will be used further in this article.

Definition 1

Suppose that \(f \in L_1[a,b], t>0, \alpha ,t \in {\mathbb {R}}\), then the fractional operator

$$\begin{aligned} {D}^{\alpha }f(t)=\left\{ \begin{array}{ll} \frac{1}{\Gamma (n-\alpha )}\int _0^t \frac{f^{(n)}(s)}{(t-s)^{\alpha +1 -n}}{{\text{d }}s},& n-1 < \alpha n,\\ \frac{{\text{ d }}^n}{{\text{ d }}t^n}f(t), & \alpha =n \in {\mathbb {N}}, \end{array} \right. \end{aligned}$$

is referred to as the Caputo fractional derivative of order \(\alpha\).

Caputo’s differential operator coincides with the usual differential operator of an integer order and has the linear operation property as follows:

$$\begin{aligned} D^{\alpha }(\lambda f(x)+\mu g(x))=\lambda D^{\alpha } f(x)+\mu D^{\alpha } g(x), \;\;\; \forall \;\lambda , \mu \in {\mathbb {R}}. \end{aligned}$$
(1)

Also, the Caputo fractional derivative of power function \(f(x)=x^k,k \in {\mathbb {N}}\) is (see [24])

$$\begin{aligned} D^{\alpha }x^k= \left\{ \begin{array}{ll} 0 & k < \alpha \\ \frac{\Gamma (k+1)}{\Gamma (k- \alpha +1)}x^{k-\alpha } & k\ge \alpha . \end{array} \right. \end{aligned}$$

For a constant as c, we have

$$\begin{aligned} D^{\alpha }c=0. \end{aligned}$$

The convection–diffusion equation is an equation that appears when a particle, energy or in general physical quantities are transferred in a system. It is a combination of the diffusion and convection. The most famous form of convection–diffusion equation is

$$\begin{aligned} \frac{\partial u}{\partial t}=\nabla \cdot (D \cdot \nabla u)-\nabla \cdot (\nu u)+R, \end{aligned}$$

where u is the variable of interest, D is the diffusivity, such as mass diffusivity for particle motion or thermal diffusivity for heat transport, \(\nu\) is the average velocity at which the quantity is moving, \(\nabla\) represents gradient and \(\nabla \cdot\) represents divergence. Application of convection–diffusion equation in fluid dynamics, heat transfer and mass transfer is discussed in Refs. [10, 12, 20]. Several numerical methods for solving this equation is introduced by the authors, such as the variational iteration method [23], Adomian’s decomposition method [26], homotopy perturbation method [9], Bessel collocation method [40], B-spline collocation method [16, 17], finite element method [21], Crank–Nicolson method [15] and rational spectral method [8]. A history of analytical methods for solving diffusion equations can be found in Ref. [14]. However, most fractional diffusion equations do not have analytical solutions. In (2011), Khader [18] used the Chebyshev collocation method as well as the finite difference method and in Ref. [19], the authors used the Legendre pseudospectral method to obtain numerical approximations. Again, in Ref. [22], Li et al. derived numerical solutions by the finite difference method. In Ref. [31], Saha Ray and Bera have applied Adomian’s decomposition method to find the solution of a time-fractional diffusion equation of order \(\beta =\frac{1}{2}\). In Ref. [6], Das has used variational iteration method for time-fractional diffusion equation of order \(0<\beta \le 1\). Fractional calculus of convection–diffusion equations has been widely considered in recent years. But there are few works devoted to numerical solutions of fractional convection–diffusion equations. Zhong et al. [41] applied the Legendre polynomials and also the associated operational matrix for solutions.

In this study, we present the Ritz–Galerkin method based on Legendre multiwavelet functions to numerically solving multi-term time-space convection–diffusion equation of fractional order:

$$\begin{aligned} D^{\alpha }_tu= & {} \sum _{i=1}^r a_i(x){D^{\alpha _i}_tu}+b(x)D^{\beta }_xu\nonumber \\&+ \, c(x)D^{\beta _1}_xu+d(x)u+h(x,t),\;x \in [0,L],\;t \in [0,T], \end{aligned}$$
(2)

with initial and boundary conditions:

$$\begin{aligned} u(x,0)&=f_1(x),\;x \in [0,L], \end{aligned}$$
(3)
$$\begin{aligned} u(0,t)&=g_1(t),\;u(L,t)=g_2(t),\;t \in [0,T]. \end{aligned}$$
(4)

Here \(0<\alpha _r< \ldots<\alpha _1<\alpha \le 1, 0<\beta _1\le 1<\beta \le 2\), the functions \(a_i(x)\) for \(i=1,2, \ldots ,r, b(x), c(x), d(x), f_1(x), g_1(t)\) and \(g_2(t)\) are known and the function u(xt) is unknown. The terms \(b(x)D^{\beta }_xu, c(x)D^{\beta _1}_xu\) and h(xt), respectively, are called the diffusive or viscous term, the convection term and the source term. The operator \(D^{\alpha _i}_t\) is the fractional derivative in the Caputo sense of order \(\alpha _i\) with respect to variable t.

The theory of wavelets is a relatively new and an emerging area in mathematical research. It has been applied in a wide range of engineering disciplines and, in particular, has been very successfully used in signal analysis for waveform representation and segmentations, time–frequency analysis, and can be used to construct fast algorithms for easy implementation [4]. Moreover, wavelet analysis has many useful properties, such as orthogonality, compact support, and the ability to obtain exact representation of polynomials up to a given degree, and to represent functions at different level of resolution [25].

Recently, Yousefi [34]–[37], Razzaghi and Yousefi [28, 29] and Yousefi and Razzaghi [38], and Jafari et al. [13] have used the Legendre multiwavelet method to obtain approximate solutions of hyperbolic telegraph equations, the differential equation of Lane–Emden, the Emden–Fowler equations, Abel’s integral equations, as well as solutions to variational problems, nonlinear problems in the calculus of variations, the nonlinear Volterra–Fredholm integral equations and fractional differential equations.

The paper is organized as follows: in Sect. 2, we give the basic definition of Legendre multiwavelet functions and state their properties. In Sect. 3, we discuss approximations to functions using Legendre multiwavelet functions basis and present a convergence analysis for function approximations together with an upper bound for the error of the estimates. In Sect. 4, we solve Eqs. (2)–(4) using the Ritz–Galerkin method based on the Legendre multiwavelet functions for solutions. Numerical results to demonstrate the accuracy of this technique are reported in Sect. 5 and, finally, Section 6 contains a conclusion.

2 Legendre multiwavelet functions

The Legendre multiwavelet functions on interval [0, T) are defined by [13, 34]

$$\begin{aligned} \psi _{nm}(t)=\left\{ \begin{array}{ll} \sqrt{2m+1}\frac{2^{\frac{k}{2}}}{\sqrt{T}}p_m {}\left( \frac{ 2^k}{T}t-n\right) , & \frac{nT}{2^k}\le t < \frac{(n+1)T}{2^k},\\ 0,& \mathrm{otherwise}, \end{array} \right. \end{aligned}$$

where \(m=0,1, \ldots ,M-1, n=0,1, \ldots ,2^{k}-1, k\) can assume any positive integer, m is the order for Legendre polynomials and t is the normalized time. \(\left\{ \psi _{nm}(t) \right\}\) is an orthonormal set. The coefficient \(\sqrt{2m+1}\) is needed for orthonormality.

Legendre polynomials on the interval [0, 1] can be determined using the following recursive formula:

$$\begin{aligned}&p_0(t)=1,\;\;p_1(t)=2t-1,\;\;\\&p_{m+1}(t)=\frac{(2m+1)(2t-1)}{m+1}p_m(t)-\frac{m}{m+1}p_{m-1}(t),\;\;m \in {\mathbb {N}}. \end{aligned}$$

The two-dimensional Legendre multiwavelet functions on interval \([0,L)\times [0,T)\) are defined by [34]

$$\begin{aligned} \psi _{nlij}(x,t)=\left\{ \begin{array}{ll} A p_{l}\left( \frac{ 2^{p}}{L}x-n\right) p_{j}\left( \frac{ 2^{k_2}}{T}t-i\right) , & \frac{nL}{2^{p}}\le x < \frac{(n+1)L}{2^{p}},\\ & \frac{iT}{2^{k}}\le t < \frac{(i+1)T}{2^{p}},\\ 0, & \mathrm{otherwise}, \end{array} \right. \end{aligned}$$
(5)

where

$$\begin{aligned} A=\frac{\sqrt{(2l+1)(2j+1)}2^{\frac{(p+k)}{2}}}{\sqrt{LT}}, \end{aligned}$$

for \(n=0,1, \ldots ,2^{p}-1, l=0,1, \ldots ,M-1, i=0,1, \ldots ,2^{k}-1,j=0,1, \ldots ,N-1,\) and pk are positive integers. Here lj are the order of Legendre polynomials. \(\left\{ \psi _{nlij}(x,t) \right\}\) is an orthonormal set. The coefficient \(\sqrt{(2l+1)(2j+1)}\) is needed for orthonormality. It is obvious that \(\psi _{nlij}(x,t)=\psi _{nl}(x)\psi _{ij}(t)\).

3 Function approximation

Consider the function f(xt) defined over \({\mathscr {R}}:=[0,L)\times [0,T )\). We can approximate f(xt) as

$$\begin{aligned} f(x,t)\approx \, & {} \sum _{n=0}^{2^{p}-1}\sum _{l=0}^{M-1}\sum _{i=0}^{2^{k}-1} \sum _{j=0}^{N-1}a_{nl}^{ij}\psi _{nl}(x)\psi _{ij}(t)\nonumber \\= & {} {\Psi }^T(x){\mathbf {A}}{\Psi }(t), \end{aligned}$$
(6)

where

$$\begin{aligned} a_{nl}^{ij}=\left\langle f,\psi _{nl}\psi _{ij}\right\rangle ={\int _{0}^L\int _{0}^T f(x,t)\psi _{nl}(x)\psi _{ij}(t)\mathrm{d}t\mathrm{d}x}, \end{aligned}$$
(7)

with

$$\begin{aligned}&n=0,1, \ldots ,2^{p}-1,\quad l=0,1, \ldots ,M-1,\;\;\\&i=0,1, \ldots ,2^{k}-1,\quad j=0,1, \ldots ,N-1, \end{aligned}$$

are the elements of \({\mathbf {A}}\) which is a \({\hat{m}}\times {\hat{n}}({\hat{m}}=2^{p}M,\;{\hat{n}}=2^{k}N)\) matrix. Also, the vectors of \({\Psi }(x)\) and \({\Psi }(t)\) are, respectively, \({\hat{m}}\times 1\) and \({\hat{n}}\times 1\) matrices such that

$$\begin{aligned}&{\Psi }(x)=[\psi _{00}(x),\psi _{01}(x), \ldots ,\psi _{0(M-1)}(x),\psi _{10}(x), \ldots ,\\&\qquad \psi _{1(M-1)}(x), \ldots ,\psi _{(2^{p}-1)0}(x), \ldots ,\psi _{(2^{p}-1)(M-1)}(x)]^T, \\&{\Psi }(t)=[\psi _{00}(t),\psi _{01}(t), \ldots ,\psi _{0(N-1)}(t),\psi _{10}(t), \ldots ,\\&\qquad \psi _{1(N-1)}(t), \ldots ,\psi _{(2^{k}-1)0}(t), \ldots ,\psi _{(2^{k}-1)(N-1)}(t)]^T. \end{aligned}$$

Theorem 1

Let \(M,N\rightarrow \infty\), then the truncated series (6) converges to f(xt).

Proof

We shall use the following notations for convenience:

$$\begin{aligned}&\sum ^{MN}_{\begin{array}{c} l=a \\ j=b \end{array}}:=\sum _{n=0}^{2^{p}-1}\sum _{l=a}^{M-1}\sum _{i=0}^{2^{k}-1}\sum _{j=b}^{N-1},\\&f_{MN}(x,t):=\sum _{n=0}^{2^{p}-1}\sum _{l=0}^{M-1} \sum _{i=0}^{2^{k}-1}\sum _{j=0}^{N-1}a_{nl}^{ij}\psi _{nl}(x)\psi _{ij}(t). \end{aligned}$$

We will prove that the sequence of partial sums of \(f_{MN}(x,t)\) is a Cauchy sequence in the Hilbert space \({\mathscr {H}}=L^2({\mathscr {R}})\). Assume \(f_{RS}(x,t)\) be an arbitrary partial sums of \(a_{rs}^{qz}\psi _{rsqz}(x,t)\), and \(M > R\), \(N> S\). Then we have

$$\begin{aligned} \Vert f_{MN}(x,t)-f_{RS}(x,t)\Vert _2^2&=\Vert \sum ^{MN}_{\begin{array}{c} l=R \\ j=S \end{array}}a_{nl}^{ij}\psi _{nlij}(x,t) \Vert _2^2\\&=\left\langle \sum ^{MN}_{\begin{array}{c} l=R \\ j=S \end{array}}a_{nl}^{ij}\psi _{nlij}(x,t), \sum ^{MN}_{\begin{array}{c} s=R \\ z=S \end{array}}a_{rs}^{qz}\psi _{rsqz}(x,t) \right\rangle \\&=\sum ^{MN}_{\begin{array}{c} l=R \\ j=S \end{array}}\sum ^{MN}_{\begin{array}{c} s=R \\ z=S \end{array}}a_{nl}^{ij}\overline{a_{rs}^{qz}} \left\langle \psi _{nlij}(x,t),\psi _{rsqz}(x,t) \right\rangle \\&= \sum ^{MN}_{\begin{array}{c} l=R \\ j=S \end{array}}\mid a_{nl}^{ij}\mid ^2. \end{aligned}$$

Since \(\sum\nolimits_{\begin{subarray}{l} l = 0 \\ j = 0 \end{subarray} }^{{\infty \infty }} {{\mid }a_{{nl}}^{{ij}} {\mid }} ^{2}\) is a monotone series and bounded by \(\Vert f\Vert _2^2\), it converges and hence its partial sums form a Cauchy sequence. Thus, \(\sum\nolimits_{\begin{subarray}{l} l = R \\ j = S \end{subarray} }^{{MN}} {{\mid }a_{{nl}}^{{ij}} {\mid }} ^{2}\) converges to zero as \(M,N,R,S\rightarrow \infty .\) So \(\Vert f_{MN}(x,t)-f_{RS}(x,t)\Vert _2^2\) converges to zero as \(M,N,R,S\rightarrow \infty .\) Thus, \(f_{MN}(x,t)\) is a Cauchy sequence and hence \(f_{MN}(x,t)\) converges to \(g \in {\mathscr {H}}.\) We claim that \(g(x,t)=f(x,t)\). By (7), we have

$$\begin{aligned} \left\langle g(x,t)-f(x,t),\psi _{nlij}(x,t)\right\rangle&=\left\langle g(x,t),\psi _{nlij}(x,t)\right\rangle \\&\quad -\left\langle f(x,t),\psi _{nlij}(x,t)\right\rangle \\&=\lim _{M,N \rightarrow \infty } \left\langle f_{MN}(x,t),\psi _{nlij}(x,t)\right\rangle -a_{nl}^{ij}\\&=a_{nl}^{ij}-a_{nl}^{ij}=0; \end{aligned}$$

hence, \(g(x,t)=f(x,t)\). This completes the proof of the theorem. \(\square\)

The following lemma gives an upper bound for the error of estimate.

Lemma 1

Let \(f:{\mathscr {R}}\rightarrow {\mathbb {R}}\) be a function with J (maximum of M and N) continuous partial derivatives, and suppose that \({\Psi }^T(x){\mathbf {A}}{\Psi }(t)\) approximates f(xt). Then an upper bound for the error of approximation is as follows:

$$\begin{aligned} \Vert f(x,t)-{\Psi }^T(x){\mathbf {A}}{\Psi }(t)\Vert _2\le \frac{S(J+1)\left( {\begin{array}{c}J\\ \left[ \frac{J}{2}\right] \end{array}}\right) {(LT)}^{\frac{2J+1}{2}}}{J!{(2J+1)}(2^{p+k})^{\frac{2J+1}{2}}}, \end{aligned}$$
(8)

where

$$\begin{aligned} S=\max _{k=0,1, \ldots ,J}\Bigg |\frac{\partial ^{J}f(x,t)}{\partial x^{J-k}\partial t^{k}}\bigg |_{( \eta , \zeta ) \in {\mathscr {R}}} \Bigg |. \end{aligned}$$
(9)

Proof

A Taylor polynomial approximation for f(xt) is

$$\begin{aligned} f(x,t)&=\underbrace{\sum _{p=0}^{J-1}\Big \{\frac{1}{p!}\sum _{k=0}^p \left( {\begin{array}{c}p\\ k\end{array}}\right) \frac{\partial ^{p}f(x,t)}{\partial x^{p-k}\partial t^{k}}\bigg |_{( \frac{nL}{2^{p}},\frac{iT}{2^{k}})}(x-\frac{nL}{2^{p}})^{p-k} (t-\frac{iT}{2^{k}})^k\Big \}}_{I(x,t)}\\&\quad +\frac{1}{J!}\sum _{k=0}^J \left( {\begin{array}{c}J\\ k\end{array}}\right) \frac{\partial ^{J}f(x,t)}{\partial x^{J-k}\partial t^{k}}\bigg |_{( \eta , \zeta ) \in {\mathscr {R}}}(x-\frac{nL}{2^{p}})^{J-k}(t-\frac{iT}{2^{k}})^k, \end{aligned}$$

where \(\left( {\begin{array}{c}p\\ k\end{array}}\right)\) is the binomial coefficient and computed as

$$\begin{aligned} \left( {\begin{array}{c}p\\ k\end{array}}\right) =\frac{p!}{(p-k)!k!}. \end{aligned}$$

We know that

$$\begin{aligned} |f(x,t)-I(x,t)|&\le \frac{1}{J!}\sum _{k=0}^J \left( {\begin{array}{c}J\\ k\end{array}}\right) \Bigg |\frac{\partial ^{J}f(x,t)}{\partial x^{J-k}\partial t^{k}}\bigg |_{( \eta , \zeta ) \in {\mathscr {R}}}\nonumber \\&\quad \Bigg |\left( x-\frac{nL}{2^{p}}\right) ^{J-k}\left( t-\frac{iT}{2^{k}}\right) ^k\nonumber \\&\le \frac{1}{J!}S(J+1) \left( {\begin{array}{c}J\\ \left[ \frac{J}{2}\right] \end{array}}\right) \left( x-\frac{nL}{2^{p}}\right) ^{J}\left( t-\frac{iT}{2^{k}}\right) ^{J}, \end{aligned}$$
(10)

where S was defined in (9). Since \({\Psi }^T(x){\mathbf {B}}{\Psi }(t)\) is the polynomial of degree \(J-1\) with respect to variables x and t that approximates f(xt) with the minimum mean error bound, we have by (10),

$$\begin{aligned}&\Vert f(x,t)-{\Psi }^T(x){\mathbf {B}}{\Psi }(t)\Vert _2^2 \le \Vert f(x,t)-I(x,t)\Vert _2 ^2\\&\quad =\int _0^L \int _0^T |f(x,t)-I(x,t)|^2\mathrm{d}t\\&\quad \le \frac{1}{(J!)^2}S^2(J+1)^2 \left( {\begin{array}{c}J\\ \left[ \frac{J}{2}\right] \end{array}}\right) ^2\\&\quad \int _0^L \int _0^T \bigg [ (x-\frac{nL}{2^{p}})^{J}(t-\frac{iT}{2^{k}})^J \bigg ]^2\mathrm{d}t\mathrm{d}x\\&\quad =\frac{1}{(J!)^2}S^2(J+1)^2 \left( {\begin{array}{c}J\\ \left[ \frac{J}{2}\right] \end{array}}\right) ^2\\&\quad \Bigg (\sum _{n=0}^{2^{p}-1}\int _{\frac{nL}{2^{p}}}^{\frac{(n+1)L}{2^{p}}} \left( x-\frac{nL}{2^{p}}\right) ^{2J}\mathrm{d}x\Bigg ) \Bigg (\sum _{i=0}^{2^{k}-1}\int _{\frac{iT}{2^{k}}}^ {\frac{(i+1)T}{2^{k}}}\left( t-\frac{iT}{2^{k}}\right) ^{2J}\mathrm{d}t\Bigg )\\&\quad = \frac{S^2(J+1)^2\left( {\begin{array}{c}J\\ \left[ \frac{J}{2}\right] \end{array}}\right) ^2{(LT)}^{{2J+1}}}{(J!)^2{(2J+1)^2}(2^{p+k})^{2J+1}}. \end{aligned}$$

Taking square roots, we have (8). \(\square\)

The upper bound of the error depends on \(\frac{(J+1)\left( {\begin{array}{c}J\\ \left[ \frac{J}{2}\right] \end{array}}\right) {(LT)}^{\frac{2J+1}{2}}}{J!{(2J+1)}(2^{p+k})^\frac{2J+1}{2}}\) which shows that as J increases, the error rapidly approaches zero. This is an advantage of Legendre multiwavelet function approximations.

4 Method of solution

4.1 Ritz approximation function

Consider

$$\begin{aligned} v(x,t)=u(x,t)+\frac{x-L}{L} g_1(t)-\frac{x}{L}g_2(t). \end{aligned}$$

We set

$$\begin{aligned} v(0,t)=v(L,t)=0. \end{aligned}$$

Now, Eqs. (2)–(4) are equivalent to

$$\begin{aligned} D^{\alpha }_tv(x,t)&=\sum _{i=1}^r a_i(x){D^{\alpha _i}_tv(x,t)}+b(x)D^{\beta }_xv(x,t)\nonumber \\&\quad + \, c(x)D^{\beta _1}_xv(x,t)+d(x)v(x,t)+s(x,t), \end{aligned}$$
(11)

with the initial condition:

$$\begin{aligned} v(x,0)=f_1(x)+\frac{x-L}{L}g_1(0)-\frac{x}{L}g_2(0), \end{aligned}$$
(12)

and homogenous boundary conditions:

$$\begin{aligned} v(0,t)=v(L,t)=0, \end{aligned}$$
(13)

where

$$\begin{aligned} s(x,t)&=h(x,t)+\frac{x-L}{L}D^{\alpha }_tg_1(t)\\&\quad -\frac{x}{L}D^{\alpha }_tg_2(t)+\frac{L-x}{L}\sum _{i=1}^r a_i(x)D^{\alpha _i}_t g_1(t)\\&\quad +\frac{x}{L}\sum _{i=1}^r a_i(x)D^{\alpha _i}_t g_2(t)+\frac{b(x)}{L}(g_2(t)-g_1(t))D^{\beta }_x x\\&\quad +\frac{c(x)}{L}(g_2(t)-g_1(t))D^{\beta _1}_x x\\&\quad +\frac{L-x}{L}d(x)g_1(t)+\frac{x}{L}d(x)g_2(t). \end{aligned}$$

Now a Ritz approximation function for (11) is in the form

$$v_{{MN}} (x,t) = \sum\limits_{\begin{subarray}{l} l = 0 \\ j = 0 \end{subarray} }^{{MN}} x (x - L)tc_{{nl}}^{{ij}} \psi _{{nl}} (x)\psi _{{ij}} (t) + w(x,t),$$
(14)

where w(xt) is an interpolating function:

$$\begin{aligned} w(x,t)&=f_1(x)+\frac{x-L}{L}g_1(t)-\frac{x}{L}g_2(t). \end{aligned}$$
(15)

The function w(xt) satisfies nonhomogeneous conditions and so \(v_{MN}(x,t)\) satisfies the initial and boundary conditions (12) and (13). This approximation provides greater flexibility when imposing initial and boundary conditions. In general, w(xt) is not unique.

4.2 Ritz–Galerkin method

Without loss of generality, we set \(M=N\) and \(p=k\) in relation (14). Consider

$$\begin{aligned} \phi _{nl}(x):=x(x-L)\psi _{nl}(x),\;\;\gamma _{ij}(t):=t\psi _{ij}(t), \end{aligned}$$

for \(n,i=0,1, \ldots ,2^{p}-1\) and \(l,j=0,1, \ldots ,M-1\). We may write the series solution \(v_{MN}(x,t)\) in (14) as follows:

$$\begin{aligned} v_{M}(x,t)={\Phi }(x){\mathbf {X}}(t){\mathbf {Q}}+w(x,t), \end{aligned}$$
(16)

where

$$\begin{aligned} {\Phi }(x)= \, & {} [\phi _{00}(x), \ldots ,\phi _{0(M-1)}(x),\phi _{10}(x), \ldots ,\\&\phi _{1(M-1)}(x), \ldots ,\phi _{(2^{p}-1)0}(x), \ldots ,\phi _{(2^{p}-1)(M-1)}(x)]_{1\times {\hat{m}}}, \end{aligned}$$
$$\begin{aligned} {\mathbf {X}}(t)=\left[ \begin{array}{ccccc} {\Gamma }(t)&{}0&{}\ldots &{}0\\ 0&{}{\Gamma }(t)&{}\ldots &{}0\\ 0&{}0&{}\ddots &{} \vdots \\ 0&{} 0 &{} 0&{}{\Gamma }(t) \\ \end{array} \right] _{{\hat{m}}\times {\hat{m}}^2}, \end{aligned}$$
(17)
$$\begin{aligned} {\Gamma }(t)= \, & {} [\gamma _{00}(t),\gamma _{01}(t), \ldots ,\\&\gamma _{0(M-1)}(t),\gamma _{10}(t), \ldots ,\gamma _{1(M-1)}(t), \ldots ,\\&\gamma _{(2^{p}-1)0}(t), \ldots ,\gamma _{(2^{p}-1)(M-1)}(t)]_{1\times {\hat{m}}}, \end{aligned}$$

and \({\mathbf {Q}}\) is a \({\hat{m}}^2\times 1\) matrix with unknown coefficients (see “Appendix”). We know that the elements of \({\Phi }(x)\) are the polynomials of degree no greater than \(M+1\). Hence, we can write \({\Phi }(x)\) using the Taylor vector as

$$\begin{aligned} {\Phi }(x)={\mathbf {T}}_{M+1}(x){\mathbf {D}}, \end{aligned}$$
(18)

where

$$\begin{aligned} {\mathbf {T}}_{M+1}(x)=[1\; x\;x^2\; \ldots \;x^{M+1}]_{1\times (M+2)}, \end{aligned}$$

and \({\mathbf {D}}\) is the \((M+2)\times {\hat{m}}\) transformation matrix of \({\Phi }(x)\) to \({\mathbf {T}}_{M+1}(x)\). Similarly,

$$\begin{aligned} {\Gamma }(t)={\mathbf {T}}_{M}(t){{\mathbf {M}}}, \end{aligned}$$
(19)

where \({{\mathbf {M}}}\) is the \((M+1)\times {\hat{m}}\) transformation matrix of \({\Gamma }(t)\) to \({\mathbf {T}}_M(t)\). We write the fractional derivative of \({\mathbf {T}}_{M+1}(x)\) and \({\mathbf {T}}_{M}(t)\) as follows:

$$\begin{aligned} D^{\beta }_x{\mathbf {T}}_{M+1}(x)=[0\; D^{\beta }_xx\;D^{\beta }_xx^2\; \ldots \;D^{\beta }_xx^{M+1}]_{1\times (M+2)}={\mathbf {X}}^{\beta }(x), \end{aligned}$$
(20)
$$\begin{aligned} D^{\alpha }_t{\mathbf {T}}_M(t)=[0\; D^{\alpha }_tt\;D^{\alpha }_tt^2\; \ldots \;D^{\alpha }_tt^{M}]_{1\times (M+1)}={\mathbf {S}}^{\alpha }(t). \end{aligned}$$
(21)

Using (17), (19) and (21) gives us

$$\begin{aligned} D^{\alpha }_t{\mathbf {X}}(t)=\left[ \begin{array}{ccccc} {\mathbf {S}}^{\alpha }(t){{\mathbf {M}}}&{}0&{}\ldots &{}0\\ 0&{}{\mathbf {S}}^{\alpha }(t){{\mathbf {M}}}&{}\ldots &{}0\\ 0&{}0&{}\ddots &{} \vdots \\ 0&{} 0 &{} 0&{}{\mathbf {S}}^{\alpha }(t){{\mathbf {M}}} \\ \end{array} \right] _{{\hat{m}}\times {\hat{m}}^2}={\mathbf {F}}^{\alpha }(t). \end{aligned}$$
(22)

Also, by (18) and (20),

$$\begin{aligned} D^{\beta }_x{\Phi }(x)={\mathbf {X}}^{\beta }(x){\mathbf {D}}. \end{aligned}$$
(23)

By (1), (16) and (23), the \(\beta\)-order fractional derivative of \(v_M(x,t)\) with respect to x is

$$\begin{aligned} D^{\beta }_xv_M(x,t)={\mathbf {X}}^{\beta }(x){\mathbf {D}}{\mathbf {X}}(t){\mathbf {Q}}+D^{\beta }_x w(x,t). \end{aligned}$$
(24)

Similarly, by (1), (16) and (22), the \(\alpha\)-order fractional derivative of \(v_M(x,t)\) with respect to t is

$$\begin{aligned} D^{\alpha }_tv_M(x,t)={\Phi }(x){\mathbf {F}}^{\alpha }(t){\mathbf {Q}}+D^{\alpha }_t w(x,t). \end{aligned}$$
(25)

Now, substituting (16), (24) and (25) into (11), we have

$$\begin{aligned} {\mathbf {G}}(x,t){\mathbf {Q}}=p(x,t), \end{aligned}$$
(26)

where

$$\begin{aligned} {\mathbf {G}}(x,t)= \, & {} {\Phi }(x)\mathbf {F^{\alpha }}(t)-\sum _{i=1}^r a_i(x){\Phi }(x)\mathbf {F^{\alpha _i}}(t)\\&\quad - \, b(x)\mathbf {X^{\beta }}(x){\mathbf {D}}{\mathbf {X}}(t)\\&\quad - \, c(x)\mathbf {X^{\beta _1}}(x){\mathbf {D}}{\mathbf {X}}(t)-d(x){\Phi }(x){\mathbf {X}}(t), \\ p(x,t)= & {} \sum _{i=1}^r a_i(x)D^{\alpha _i}_tw(x,t)+b(x)D^{\beta }_xw(x,t)\\&\quad + \, c(x)D^{\beta _1}_xw(x,t)\\&\quad + \, d(x)w(x,t)-D^{\alpha }_tw(x,t)+s(x,t). \end{aligned}$$

Suppose

$$\begin{aligned} {\Psi }(x,t)=[\varphi _{1,1}(x,t), \varphi _{1,2}(x,t), \ldots ,\varphi _{1,{\hat{m}}^2}(x,t)] \end{aligned}$$

is a \(1\times {\hat{m}}^2\) basis vector for \(L^{2}({\mathscr {R}})\).

Now, to apply the Ritz–Galerkin method to compute the unknown coefficients of \({\mathbf {Q}}\), we take the inner product of Eq. (26) with the \({\hat{m}}^2\) elements of \({\Psi }(x,t)\) as

$$\begin{aligned} {\mathbf {G}}{\mathbf {Q}}={\mathbf {P}}, \end{aligned}$$
(27)

where

$$\begin{aligned} {\mathbf {G}}_{i,j}= \, & {} \left\langle \varphi _{1,i}(x,t),{\mathbf {G}}_{1,j}(x,t)\right\rangle ,\\ \;{\mathbf {P}}_{i,1}= \, & {} \left\langle \varphi _{1,i}(x,t),p(x,t)\right\rangle ,\quad i,j=1,2, \ldots ,{\hat{m}}^2, \end{aligned}$$

and \(\left\langle .\right\rangle\) denotes the inner product defined by

$$\begin{aligned}&\left\langle \varphi _{1,i}(x,t),{\mathbf {G}}_{1,j}(x,t)\right\rangle =\int _0^L\int _0^T \varphi _{1,i}(x,t) {\mathbf {G}}_{1,j}(x,t)\mathrm{d}t\mathrm{d}x, \\&\left\langle \varphi _{1,i}(x,t),p(x,t)\right\rangle =\int _0^L\int _0^T \varphi _{1,i}(x,t) p(x,t)\mathrm{d}t\mathrm{d}x. \end{aligned}$$

Hence, we have

$$\begin{aligned} {{\mathbf {G}}}= & {} \small {\left[ \begin{array}{ccccc} \left\langle \varphi _{1,1}(x,t),{\mathbf {G}}_{1,1}(x,t)\right\rangle &{}\left\langle \varphi _{1,1}(x,t),{\mathbf {G}}_{1,2}(x,t)\right\rangle &{}\ldots &{}\left\langle \varphi _{1,1}(x,t),{\mathbf {G}}_{1,{\hat{m}}^2}(x,t)\right\rangle \\ \left\langle \varphi _{1,2}(x,t),{\mathbf {G}}_{1,1}(x,t)\right\rangle &{}\left\langle \varphi _{1,2}(x,t),{\mathbf {G}}_{1,2}(x,t)\right\rangle &{}\ldots &{}\left\langle \varphi _{1,2}(x,t),{\mathbf {G}}_{1,{\hat{m}}^2}(x,t)\right\rangle \\ \vdots &{}\vdots &{}\vdots &{} \vdots \\ \left\langle \varphi _{1,{\hat{m}}^2}(x,t),{\mathbf {G}}_{1,1}(x,t)\right\rangle &{} \left\langle \varphi _{1,{\hat{m}}^2}(x,t),{\mathbf {G}}_{1,2}(x,t)\right\rangle &{} \ldots &{}\left\langle \varphi _{1,{\hat{m}}^2}(x,t),{\mathbf {G}}_{1,{\hat{m}}^2}(x,t)\right\rangle \\ \end{array} \right] }, \\ {\mathbf {P}}= & {} \left[ \begin{array}{ccccc}\left\langle \varphi _{1,1}(x,t),p(x,t)\right\rangle &{}\left\langle \varphi _{1,2}(x,t),p(x,t)\right\rangle &{}\ldots &{}\left\langle \varphi _{1,{\hat{m}}^2}(x,t),p(x,t)\right\rangle \\ \end{array} \right] ^T. \end{aligned}$$

Equation (27) corresponds to a system of \({\hat{m}}^2\) linear algebraic equations with unknown coefficients. If \(\mathrm{rank}({\mathbf {G}})=\mathrm{rank}([{\mathbf {G}};{\mathbf {P}}])={\hat{m}}^2\), then Eq. (11) has a unique solution and so the solution of Eq. (2) is also unique. If \(\mathrm{rank}({\mathbf {G}})=\mathrm{rank}([{\mathbf {G}};{\mathbf {P}}])<{\hat{m}}^2\), then Eq. (11) and thus (2) have a particular solution that may find and if \(\mathrm{rank}({\mathbf {G}})\ne \mathrm{rank}([{\mathbf {G}};{\mathbf {P}}])\), then it is not a solution.

In this section, we give examples to demonstrate the accuracy of approximation solution to multi-term time-space convection–diffusion equations of fractional order using our technique. The error functions is defined as

$$\begin{aligned} e_M(x,t)=|u_\mathrm{exact}(x,t)-v_M(x,t)|. \end{aligned}$$

Example 1

Consider the time-space convection–diffusion equation of fractional order

$$\begin{aligned} &{D}^{\alpha }_tu=0.5D^{\alpha _1}_tu-xD^{\beta }_xu+xD^{\beta _1}_xu+h(x,t),\;\nonumber \\& \quad x\in [0,1],\;t\in [0,1], \end{aligned}$$
(28)

where

$$\begin{aligned} h(x,t)&=2x^2(1-x)\frac{t^{2-\alpha }}{\Gamma (3-\alpha )}-x^2(1-x)\frac{t^ {2-\alpha _1}}{\Gamma (3-\alpha _1)}\\&\quad + \, t^2\left( \frac{2x^{3-\beta }}{\Gamma (3-\beta )}-\frac{6x^{4-\beta }}{\Gamma (4-\beta )}\right) \\&\quad - \, t^2\left( \frac{2x^{3-\beta _1}}{\Gamma (3-\beta _1)}-\frac{6x^{4-\beta _1}}{\Gamma (4-\beta _1)}\right) , \end{aligned}$$

with the initial and boundary conditions, respectively,

$$\begin{aligned} u(x,0)= \, & {} 0,\;x\in [0,1],\\ u(0,t)= \, & {} u(1,t)=0,\; t \in [0,1]. \end{aligned}$$

The exact solution is \(u(x,t)=x^2(1-x)t^2\). The Ritz–Galerkin solution \(v_M(x,t)\) for \(M=2\) and \(p=0\) is

$$\begin{aligned} v_2(x,t)={\Phi }(x){\mathbf {X}}(t){\mathbf {Q}}+w(x,t), \end{aligned}$$
(29)

where \(a_1(x)=0.5, b(x)=-x, c(x)=x, d(x)=0, f_1(x)=0, g_1(t)=g_2(t)=0, w(x,t)=0, {\Phi }(x)=\left[ x(x-1), \sqrt{3}x(x-1)(2x-1) \right] , {\Gamma }(t)=\left[ t, \sqrt{3}t(2t-1) \right],\)

$$\begin{aligned} {\mathbf {X}}(t)=\left[ \begin{array}{ccccc} {\Gamma }(t)&{}0\\ 0&{}{\Gamma }(t) \end{array} \right] , \quad {\mathbf {Q}}=\left[ c_{00}^{00},c_{00}^{01},c_{01}^{00},c_{01}^{01} \right] ^T . \end{aligned}$$

The fundamental matrix relation of the problem is

$$\begin{aligned} {\mathbf {G}}(x,t){\mathbf {Q}}={P(x,t)}, \end{aligned}$$
(30)

where

$$\begin{aligned} {\mathbf {G}}(x,t)= \, & {} {\Phi }(x)\mathbf {F^{\alpha }}(t)-0.5{\Phi }(x)\mathbf {F^{\alpha _1}}(t)\\&+ \, x\mathbf {X^{\beta }}(x){\mathbf {D}}{\mathbf {X}}(t)-x\mathbf {X^{\beta _1}}(x){\mathbf {D}}{\mathbf {X}}(t),\\ p(x,t)= \, & {} h(x,t), \end{aligned}$$

with

$$\begin{aligned} {\mathbf {D}}=\left[ \begin{array}{ccccc} 0&{}0\\ -1&{}1351/780\\ 1&{}-1351/260\\ 0&{}1351/390\\ \end{array} \right] ,\quad {\mathbf {M}}=\left[ \begin{array}{ccccc} 0&{}0\\ 1&{}-1351/780\\ 0&{}1351/390\\ \end{array} \right] . \end{aligned}$$

We put \({\Psi }(x,t)=[1,t,x,xt]\). By taking the inner product of Eq. (30) for \(\alpha _1=0.1, \beta =1.8, \beta _1=0.8\) and \(\alpha =0.7\) with the elements of \({\Psi }(x,t)\), we have the augmented matrix \([{\mathbf {G}};{\mathbf {P}}]\) as

$$\begin{aligned} {\left[ \begin{array}{cccccc} 0.3617103291&{}0.1120602997&{}0.3993838574&{}0.2305843776&{};&{}-0.1834635525\\ 0.2551082358&{}0.1341812003&{}0.2662559049&{}0.2305843776&{};&{}-0.1407905414\\ 0.2458067810&{}0.0935299831&{}0.4640067960&{}0.2511328289&{};&{}-0.1628529334\\ 0.1708551955&{}0.1045904334&{}0.3117571954&{}0.2549642813&{};&{}-0.1240554262\\ \end{array} \right] }. \end{aligned}$$
Fig. 1
figure 1

The absolute error functions for \(\alpha _1=0.1\), \(\beta =1.8\), \(\beta _1=0.8\) when \(\alpha =1,\) 0.9, 0.8 and 0.7 of Example 1

By solving this system, the unknown coefficient matrix \({\mathbf {Q}}\) is obtained as

$$\begin{aligned}{\mathbf {Q}}=\left[ \begin{array}{cccccc} -0.25\\ -0.1443375673\\ -0.1443375673\\ -0.0833333333\\ \end{array} \right] . \end{aligned}$$

Substituting the elements of the column matrix \({\mathbf {Q}}\) into (29), we have

$$\begin{aligned} v_2(x,t)&=- \, 0.25\underbrace{0 \ldots 0}_\text {14 times}4533xt(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times}1643xt(2t-1)(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times} 3754xt(2x-1)(x-1)\\&\quad -0.25\underbrace{0 \ldots 0}_\text {14 times}4529xt(2t-1)(2x-1)(x-1). \end{aligned}$$

Similarly for other cases, we obtain the approximate solution of the problem by the present method as for case \(\alpha _1=0.1, \beta =1.8, \beta _1=0.8, \alpha =0.8\):

$$\begin{aligned} v_2(x,t)&=- \, 0.25\underbrace{0 \ldots 0}_\text {15 times}295xt(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {15 times}359xt(2t-1)(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times} 4842xt(2x-1)(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times}3326xt(2t-1)(2x-1)(x-1), \end{aligned}$$

for case \(\alpha _1=0.1, \beta =1.8, \beta _1=0.8, \alpha =0.9\):

$$\begin{aligned} v_2(x,t)&=- \, 0.24\underbrace{9 \ldots 9}_\text {14 times}7254xt(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times}7762xt(2t-1)(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times} 5515xt(2x-1)(x-1)\\&\quad -0.25\underbrace{0 \ldots 0}_\text {14 times}1256xt(2t-1)(2x-1)(x-1), \end{aligned}$$

for case \(\alpha _1=0.1, \beta =1.8, \beta _1=0.8, \alpha =1\):

$$\begin{aligned} v_2(x,t)&=- \, 0.25\underbrace{0 \ldots 0}_\text {14 times}4107xt(x-1)\\&\quad - \, 0.24\underbrace{9 \ldots 9}_\text {15 times}354xt(2t-1)(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times} 4171xt(2x-1)(x-1)\\&\quad - \, 0.25\underbrace{0 \ldots 0}_\text {14 times}5313xt(2t-1)(2x-1)(x-1). \end{aligned}$$

Figure 1 displays the graphs of the absolute error functions \(e_2(x,t)\) for \(\alpha _1=0.1, \beta =1.8, \beta _1=0.8\) when \(\alpha =1, 0.9, 0.8, 0.7\). It is clear that even with \(M=2\), our approximations are very good.

Example 2

Consider the following time-fractional diffusion equation [30]

$$\begin{aligned} {D}^{\alpha }_tu=-D^{\alpha _1}_tu+D^{\beta }_xu+h(x,t),\;x\in [0,1],\;t\in [0,1], \end{aligned}$$
(31)

where

$$\begin{aligned} h(x,t)= \, & {} \frac{6}{\Gamma (4-\alpha )}t^{3-\alpha }sin(\pi x)\\&+\frac{6}{\Gamma (4-\alpha _1)}t^{3-\alpha _1}sin(\pi x)+\pi ^2t^3sin(\pi x), \end{aligned}$$

with the initial and boundary conditions, respectively:

$$\begin{aligned} u(x,0)= \, & {} 0,\;x\in [0,1], \\ u(0,t)= \, & {} u(1,t)=0,\; t \in [0,1]. \end{aligned}$$

The exact solution for \(\beta =2\) is \(u(x,t)=t^3sin(\pi x)\). The Ritz–Galerkin solution \(v_M(x,t)\) for \(M=3\) and \(p=0\) is

$$\begin{aligned} v_3(x,t)={\Phi }(x){\mathbf {X}}(t){\mathbf {Q}}+w(x,t), \end{aligned}$$
(32)

where \(a_1(x)=-1, b(x)=1, c(x)=d(x)=0, f_1(x)=0, g_1(t)=g_2(t)=0, w(x,t)=0,\)

$$\begin{aligned}&{\Phi }(x)=\left[ x(x-1), \sqrt{3}x(x-1)(2x-1),\sqrt{5}x(x-1)(6x^2-6x+1) \right] ,\\&{\mathbf {X}}(t)=\left[ \begin{array}{ccccc} {\Gamma }(t)&{}0&{}0\\ 0&{}{\Gamma }(t)&{}0\\ 0&{}0&{}{\Gamma }(t)\\ \end{array} \right] ,\\&{\Gamma }(t)=\left[ t, \sqrt{3}t(2t-1),\sqrt{5}t(6t^2-6t+1) \right] , \\&{\mathbf {Q}}=\left[ c_{00}^{00},c_{00}^{01},c_{00}^{02},c_{01}^{00},c_{01}^{01}, c_{01}^{02},c_{02}^{00},c_{02}^{01},c_{02}^{02} \right] ^T . \end{aligned}$$

The fundamental matrix relation of Eq. (31) is

$$\begin{aligned} {\mathbf {G}}(x,t){\mathbf {Q}}={P(x,t)}, \end{aligned}$$
(33)

where

$$\begin{aligned}&{\mathbf {G}}(x,t)={\Phi }(x)\mathbf {F^{\alpha }}(t)+{\Phi }(x)\mathbf {F^{\alpha _1}}(t)-\mathbf {X^{\beta }}(x){\mathbf {D}}{\mathbf {X}}(t), \\&p(x,t)=h(x,t), \end{aligned}$$

with

$$\begin{aligned}&{\mathbf {D}}=\left[ \begin{array}{ccccc} 0&{}0&{}0\\ -1&{}1351/780&{}-2889/1292\\ 1&{}-1351/260&{}2207/141\\ 0&{}1351/390&{}-8667/323\\ 0&{}0&{}4253/317 \end{array} \right] ,\\&{\mathbf {M}}=\left[ \begin{array}{ccccc} 0&{}0&{}0\\ 1&{}-1351/780&{}2889/1292\\ 0&{}1351/390&{}-4253/317\\ 0&{}0&{}4253/317 \end{array} \right] . \end{aligned}$$

We put \({\Psi }(x,t)=[1,t,t^2,x,xt,xt^2,x^2,x^2t,x^2t^2]\). By taking the inner product of Eq. (33) for \(\alpha =0.9, \alpha _1=0.1\) and \(\beta =2\) with the elements of \({\Psi }(x,t)\), we have the augmented matrix \([{\mathbf {G}};{\mathbf {P}}]\) as

$$\begin{aligned} {\left[ \begin{array}{cccccccccccc} -1.250&{}-0.887&{}-0.300&{}0&{}0&{}0&{}-2.124&{}-1.153&{}0.134&{};&{}2.316\\ -0.810&{}-0.847&{}-0.469&{}0&{}0&{}0&{}-1.430&{}-1.170&{}-0.190&{};&{}1.828\\ -0.601&{}-0.743&{}-0.534&{}0&{}0&{}0&{}-1.073&{}-1.062&{}-0.361&{};&{}1.510\\ -0.625&{}-0.443&{}-0.150&{}-0.909&{}-0.554&{}-0.052&{}-1.062&{}-0.576&{}0.067&{};&{}1.158\\ -0.405&{}-0.424&{}-0.234&{}-0.602&{}-0.547&{}-0.184&{}-0.713&{}-0.585&{}-0.952&{};&{}0.914\\ -0.300&{}-0.371&{}-0.267&{}-0.450&{}-0.489&{}-0.247&{}-0.536&{}-0.531&{}-0.181&{};&{}0.755\\ -0.408&{}-0.285&{}-0.090&{}-0.909&{}-0.554&{}-0.052&{}-1.17&{}-0.659&{}0.029&{};&{}0.689\\ -0.265&{}-0.273&{}-0.146&{}-0.602&{}-0.547&{}-0.184&{}-0.781&{}-0.663&{}-0.147&{};&{}0.543\\ -0.197&{}-0.240&{}-0.168&{}-0.450&{}-0.489&{}-0.247&{}-0.587&{}-0.598&{}-0.237&{};&{}0.449\\ \end{array} \right] }. \end{aligned}$$

By solving this system, the unknown coefficients matrix \({\mathbf {Q}}\) is obtained as

$$\begin{aligned}{\mathbf {Q}}=\left[ \begin{array}{cccccc} -1.2357367097\\ -1.0701682394\\ -0.2762990367\\ 0\\ 0\\ 0\\ 0.08435771343\\ 0.07303560565\\ 0.01884433223 \end{array} \right] . \end{aligned}$$

Substituting the elements of the column matrix \({\mathbf {Q}}\) into (32), we have

$$\begin{aligned} v_3(x,t)&=0.1886295816xt(x-1)(6x^2-6x+1)\\&\quad - \, 1.853585763xt(2t-1)(x-1)\\&\quad - \, 0.6178234281xt(x-1)(6t^2-6t+1)\\&\quad - \, 1.23573671xt(x-1)\\&\quad + \, 0.09422166116xt(x-1)(6t^2-6t+1)(6x^2-6x+1)\\&\quad + \, 0.2828656844xt(2t-1)(x-1)(6x^2-6x+1). \end{aligned}$$

Similarly for other cases, we have for case \(\alpha =1, \alpha _1=0.1, \beta =2\):

$$\begin{aligned} v_3(x,t)&=0.1886587424xt(x-1)(6x^2-6x+1)\\&\quad - \, 1.853603232xt(2t-1)(x-1)\\&\quad - \, 0.6178204887xt(x-1)(6t^2-6t+1)\\&\quad - \, 1.235748223xt(x-1)\\&\quad + \, 0.09421450199xt(x-1)(6t^2-6t+1)(6x^2-6x+1)\\&\quad + \, 0.28288847783xt(2t-1)(x-1)(6x^2-6x+1), \end{aligned}$$

for case \(\alpha =1.1, \alpha _1=0.1, \beta =2\):

$$\begin{aligned} v_3(x,t)&=0.1886850925xt(x-1)(6x^2-6x+1)\\&\quad - \, 1.85367291xt(2t-1)(x-1)\\&\quad - \, 0.6177962154xt(x-1)(6t^2-6t+1)\\&\quad - \, 1.235715861xt(x-1)\\&\quad + \, 0.09420280809xt(x-1)(6t^2-6t+1)(6x^2-6x+1)\\&\quad + \, 0.2829110114xt(2t-1)(x-1)(6x^2-6x+1), \end{aligned}$$

for case \(\alpha =1.2, \alpha _1=0.1, \beta =2\):

$$\begin{aligned} v_3(x,t)&=0.188715454xt(x-1)(6x^2-6x+1)\\&\quad - \, 1.853758001xt(2t-1)(x-1)\\&\quad - \, 0.6177680172xt(x-1)(6t^2-6t+1)\\&\quad - \, 1.235679379xt(x-1)\\&\quad + \, 0.09418952804xt(x-1)(6t^2-6t+1)(6x^2-6x+1)\\&\quad + \, 0.28293763xt(2t-1)(x-1)(6x^2-6x+1). \end{aligned}$$

Figure 2 displays the graphs of the absolute error functions for \(\alpha _1=0.1, \beta =2\) when \(\alpha =1.2, 1.1, 1, 0.9\). Table 1 is used to show the numerical results by the present method at \(t=0.3\) and \(t=0.5\) for \(\alpha =\alpha _1=1, \beta =2\). According to Table 1, the present method gives better results as compared to [30].

Fig. 2
figure 2

The absolute error functions for \(\alpha _1=0.1, \beta =2\) when \(\alpha =1.2, 1.1, 1\) and 0.9 of Example 2

Table 1 Comparison of the absolute errors for \(\alpha =\alpha _{1}=1\) and \(\beta =2\) of Example 2

5 Conclusion

In this paper, we have presented a numerical method to solve multi-term time-space convection–diffusion equations of fractional order with variable coefficients and initial-boundary conditions. We have successfully applied the Ritz–Galerkin method based on Legendre multiwavelet functions and obtained very good approximate solutions using only a few terms. The main advantage of the present method is that the approximate solutions are very easily and rapidly calculated using computer programs such as Matlab.