1 Introduction

Higher order boundary value problems play important roles in various branches of applied sciences. These problems arise in modeling many physical phenomena such as chemical reactions, spring–mass systems and beam bending. For instance, the celebrated problem in physics regarding thin film flow of a liquid requires the solution of third-order ordinary differential equations (see [1]). Moreover, the induction motor behavior is represented by a fifth-order or a seventh-order differential equation model [2]. Ninth-order differential equations occur in mathematical modeling of AFTI-F16 fighters [3].

In this paper, we are interested in treating the general nonlinear odd-order ordinary differential equation

$$\begin{aligned} y^{(2\, m+1)}(x) =f\left( x,\mathbf{y}(x)\right) , \qquad x\in I=\left[ a,b\right] ,\quad \;\; m\ge 1, \end{aligned}$$
(1)

where \(\mathbf{y}(x)= \left( y(x),y'(x),\ldots , y^{(q)}(x)\right) , 0\le q\le 2m\). We associate with Eq. (1) the boundary conditions

$$\begin{aligned} {\left\{ \begin{array}{ll} y^{(\ell )}(a)=\alpha _\ell ,&{}\quad 0\le \ell \le m,\\ y^{(\ell )}(b)=\beta _\ell , &{}\quad 0\le \ell \le m-1, \end{array}\right. } \end{aligned}$$
(2)

where \(\alpha _\ell , \beta _\ell \) are real constants and \(f: [a,b]\times {\mathbb {R}}^{q+1} \rightarrow {\mathbb {R}}\) is continuous at least in the interior of the domain of interest.

We assume that f is Lipschitzian in \(\mathbf{y}\) with constants \(L_k\), \(k=0,\ldots , q\). This means that if \((x, y_0, y_1,\ldots , y_q)\) and \((x, {\overline{y}}_0, {\overline{y}}_1,\ldots , {\overline{y}}_q)\) are in the domain of f, then

$$\begin{aligned} \left| f\left( x, y_0, y_1,\ldots , y_q\right) -f\left( x, {\overline{y}}_0, {\overline{y}}_1,\ldots , {\overline{y}}_q\right) \right| \le \sum _{k=0}^q L_k\left| y_k- {\overline{y}}_k\right| . \end{aligned}$$

We assume the satisfaction of existence and uniqueness conditions of the solution of problem (1)–(2) in a certain appropriate domain of \([a,b]\times {\mathbb {R}}^{q+1}\) (see [4]).

Due to the distinguished roles of odd-order boundary value problems (BVPs) in many applications, many researchers investigate them. In this regard, several algorithms are developed for obtaining numerical solutions of odd-order BVPs. Spline solutions are proposed in some articles (see, for example, [5]); nonpolynomial spline solutions are introduced in [6, 7]; and Adomian decomposition methods have been used in [8,9,10]. Lang and Xu [11] have suggested an enhanced quartic B-spline method for solving a class of nonlinear fifth-order BVPs. Also, intelligent computing techniques are developed in [12] to solve fifth-order BVPs.

Spectral methods are crucial in the field of differential and integral equations. In these methods, the solution of a certain problem is represented as a combination of orthogonal functions. One of the most important advantages of spectral methods is that they provide exponential convergence of the solutions under some assumptions. For books interested in spectral methods and their applications, one can consult [13,14,15].

All well-known types of spectral methods have their parts in the numerical solutions of different differential equations. Collocation methods are very useful in handling almost all kinds of differential equations and in particular nonlinear problems (see, for example, [16,17,18,19,20,21,22]). Galerkin methods also serve in solving some types of ordinary and partial differential equations. For example, this method has been employed to solve even- order BVPs (see [23]). Moreover, a new Galerkin method for solving linear hyperbolic telegraph-type equations is presented in [24].

Matrices of derivatives for different orthogonal polynomials have distinguished parts in solving several kinds of differential equations. These kinds of matrices have been used for the solution of both linear and nonlinear differential equations ([25,26,27,28,29,30]).

In this paper, we are interested in presenting a unified approach for solving both linear and nonlinear odd-order BVPs based on the application of the collocation method. We choose a certain combination of Legendre polynomials as basis functions.

The current paper is organized as follows: In Sect. 2, we review some useful elementary properties and definitions; in Sect. 3, we introduce a new operational matrix of derivatives. Moreover, in this section, a unified algorithm for treating odd-order BVPs is implemented and presented. The convergence and error analysis of the presented method are investigated in Sect. 4. In Sect. 5, we perform some numerical tests and comparisons to validate the efficiency and applicability of the proposed algorithm. Finally, some conclusions are reported in Sect. 6.

2 Preliminaries and Basic Definitions

Here, we present some definitions and properties that will be useful in this paper.

Definition 1

[31] The Legendre polynomial of degree j, \(L_j(x)\), \(x\in [-1,1]\) may be generated with the aid of the following recurrence relation

$$\begin{aligned} (j+1)L_{j+1}(x)=(2j+1)xL_j(x)-j L_{j-1}(x),\quad j\ge 1, \end{aligned}$$
(3)

with the initial values: \(L_0(x)=1, L_1(x)=x\).

These polynomials are orthogonal on \([-1, 1]\) with respect to the unit weight function, that is

$$\begin{aligned} \int _{-1}^{1} L_k(x) L_j(x)\mathrm{d}x = \frac{2}{2j + 1}\ \delta _{kj}, \end{aligned}$$

where \(\delta _{kj}\) is the Kronecker delta function. The shifted Legendre polynomials on [ab] are defined as

$$\begin{aligned} L_j^{*}(x)=L_j\left( \frac{2x-b-a}{b-a}\right) , \end{aligned}$$

with the following orthogonality relation

$$\begin{aligned} \int _{a}^b L_k^{*}(x) L_j^{*}(x)\mathrm{d}x = \frac{b-a}{2j + 1}\ \delta _{kj} . \end{aligned}$$

Definition 2

The harmonic number \(H_j\) may be defined as: \(H_j=\sum \limits _{\ell =1}^j \frac{1}{\ell }\), \(j\ge 1\), and \(H_0=0\).

The following two identities are satisfied by \(H_{j}\):

$$\begin{aligned}&\qquad\qquad\displaystyle H_j = \displaystyle H_{j-1} + \frac{1}{j},\qquad j\ge 1, \nonumber \\&\displaystyle (2j-1)H_{j-1}-(j-1) H_{j-2}= j\, H_j\, , \quad j\ge 2. \end{aligned}$$
(4)

3 A Unified Collocation Algorithm for Solving (1)–(2)

The principal objective of the current section is twofold:

  • Establishing a matrix of derivatives of a class of orthogonal polynomials given in terms of Legendre polynomials.

  • Presenting a unified algorithm for treating \((2m+1)th\)-order BVPs, for all \(m\ge 1\).

Now, consider the (\(2m+1\))th-order differential Eq. (1) governed by the homogeneous boundary conditions:

$$\begin{aligned} y^{(\ell )}(a)=0,\quad \ell =0,\ldots , m; \qquad y^{(\ell )}(b)=0\quad \ell =0,\ldots , m-1. \end{aligned}$$
(5)

Remark 1

Equation (1) with nonhomogeneous boundary conditions can be handled easily by considering \(v(x) = y(x) -{\tilde{y}}(x)\), where \({\tilde{y}}(x)\) is the unique polynomial of degree 2m satisfying the nonhomogeneous boundary conditions (see, [32]).

The basis functions are selected to be

$$\begin{aligned} \phi _{j,m}(x)=(b-x)^m (x-a)^{m+1} L_j^{*}(x),\quad j=0,1,2,\ldots . \end{aligned}$$

It can be easily shown from (3) that the polynomials \(\phi _{j,m}(x)\, ,j\ge 2\) satisfy the three-term recurrence relation

$$\begin{aligned} \phi _{j,m}(x)=\frac{2\, j-1}{j} \, \frac{2x-b-a}{b-a}\ \phi _{j-1,m}(x) -\frac{j-1}{j} \phi _{j-2,m}(x), \end{aligned}$$
(6)

which, for \([a,b]\equiv [0,1]\), can be written as

$$\begin{aligned} x \phi _{j,m}(x)=\frac{j+1}{2(2j+1)} \phi _{j+1,m}(x)+\frac{1}{2}\phi _{j,m}(x)+\frac{j}{2(2j+1)}\ \phi _{j-1,m}(x). \end{aligned}$$

Moreover, the set of polynomials \(\{\phi _{j,m}(x)\}_j, j\ge 0\) is a linearly independent orthogonal set on [ab] with respect to \(\displaystyle w(x)=\frac{1}{(b-x)^{2m} (x-a)^{2m+2}}\). In fact, we have

$$\begin{aligned} \int _a^b \frac{\phi _{i,m}(x) \phi _{j,m}(x)}{(b-x)^{2m} (x-a)^{2m+2}} \mathrm{d}x=\frac{b-a}{2i+1}\delta _{ij}. \end{aligned}$$

We note that the basis \(\phi _{j,m}(x)\) forms a complete orthogonal system in \(L^2_w(a,b)\). Let us denote by \(H_w^m(a,b)\) the weighted Sobolev space (see [31])

$$\begin{aligned} H_w^m(a,b)=\left\{ f\in L_w^2(a,b): \frac{d^{\ell }f}{d x^{\ell }}\in L_w^2(a,b)\ \text { for } 0\le \ell \le m \right\} . \end{aligned}$$

Let us consider the following subspace of \(H_w^m(a,b)\)

$$\begin{aligned} H_{0,w}^m(a,b)=\left\{ f\in H_w^m(a,b): \,f^{(j)}(a)=f^{(j)}(b)=0, \ 0\le j\le m\right\} . \end{aligned}$$

Assume that the function \(y(x)\in H_{0,w}^m(a,b)\) has the following expansion:

$$\begin{aligned} y(x)=\sum _{j=0}^{\infty } b_j\, \phi _{j,m}(x), \end{aligned}$$
(7)

with

$$\begin{aligned} b_j= \frac{2j+1}{b-a} \int _a^b \frac{y(x) \phi _{j,m}(x)}{(b-x)^{2m} (x-a)^{2m+2}}\mathrm{d}x. \end{aligned}$$

Now, consider the following approximation for y(x)

$$\begin{aligned} y(x)\approx y_M(x)=\sum _{j=0}^{M} b_j \phi _{j,m}(x)= {{\varvec{\Phi }}} (x) B, \end{aligned}$$
(8)

where

$$\begin{aligned} {{\varvec{\Phi }}} (x)= \left[ \phi _{0,m}(x),\phi _{1,m}(x),\ldots , \phi _{M,m}(x)\right] ,\qquad B= \left[ b_0,b_1,\ldots , b_M\right] ^T . \end{aligned}$$

Since each member of \(\phi _{j,m}(x),\ j\ge 0\) satisfies the homogeneous boundary conditions (5), then \(y_M(x)\) also satisfies (5). Moreover, differential Eq. (1) can be approximated in the following form:

$$\begin{aligned} {{\varvec{\Phi }}}^{(2m+1)} (x) B=f\left( x, {{\varvec{\Phi }}} (x) B,{{\varvec{\Phi }}}' (x) B,\ldots , {{\varvec{\Phi }}}^{(q)} (x) B\right) \,. \end{aligned}$$
(9)

Theorem 1

The first derivative of the polynomials \(\phi _{j,m}(x)\) for \(j\ge 0\) is linked to the original polynomials by the following formula:

$$\begin{aligned} D\phi _{j,m}(x)= & {} \displaystyle \frac{2}{b-a} \left[ \sum _{\begin{array}{c} \ell =0\\ (j+\ell )\ \mathrm{even} \end{array}}^{j-2} (1+2\ell )(H_\ell -H_j) \phi _{\ell ,m}(x)\right. \nonumber \\&\displaystyle +\left. \sum _{\begin{array}{c} \ell =0\\ (j+\ell )\ \mathrm{odd} \end{array}}^{j-1} (1+2\ell )(1+(2m+1)(H_j-H_\ell )) \phi _{\ell ,m}(x)\right] +\xi _{j,m}(x),\nonumber \\ \end{aligned}$$
(10)

where

$$\begin{aligned} \xi _{j,m}(x)=(x-a)^m (b-x)^{m-1} \left\{ \begin{array}{ll} am+b(1+m)-x(1+2m), &{}\quad j\ \mathrm{even},\\ am-b(1+m)+x, &{}\quad j\ \mathrm{odd}. \end{array}\right. \end{aligned}$$

Proof

First, we assume that \([a,b]\equiv [0,1]\). In this case,

$$\begin{aligned} \phi _{j,m}(x)= & {} x^{m+1}(1-x)^m\ L_j(2x-1), \\ \xi _{j,m}(x)= & {} x^m (1-x)^{m-1} \left\{ \begin{array}{ll} 1+m-x(1+2m), &{} j \; \text {even},\\ x-1-m,&{} j \; \text {odd}. \end{array}\right. \end{aligned}$$

We prove now that relation (10) is true for \(j=1\). In such case, \(\phi _{1,m}(x)=x^{m+1}\, (1-x)^m\, (2x-1)\), and therefore

$$\begin{aligned} D \phi _{1,m}(x)=- x^m \, (1-x)^{m-1}\left( 1+m-(5+4 m) x+4 (1+m) x^2\right) . \end{aligned}$$
(11)

On the other hand, the right-hand side of (10) in such case is equal to

$$\begin{aligned} 4 (1+m)\, x^{m+1}\, (1-x)^m + x^m\, (1-x)^{m-1}(-1-m+x), \end{aligned}$$

which is equal to (11). This proves the theorem in case of \(j=1.\)

Now, assume that (10) holds for all \(j<i\), and we have to show that (10) itself holds. From (6), we get

$$\begin{aligned} D\phi _{j,m}(x)= & {} \frac{2(2j-1)}{j}\ \phi _{j-1,m}(x)+\frac{2j-1}{j}\ (2x-1)\ D\phi _{j-1,m}(x)\\&-\frac{j-1}{j}\, D\phi _{j-2,m}(x),\quad j\ge 2 . \end{aligned}$$

Therefore, the induction hypothesis yields

$$\begin{aligned} D\phi _{j,m}(x)= & {} \frac{2(2j-1)}{j}\ \phi _{j-1,m}(x)+\frac{2(2j-1)}{j}\ (2x-1)\nonumber \\&\left[ \displaystyle \sum _{\begin{array}{c} \ell =0\\ (j+\ell )\ \mathrm{odd} \end{array}}^{j-3}(1+2\ell )(H_\ell -H_{j-1}) \phi _{\ell ,m}(x)\right. \nonumber \\&\left. \displaystyle + \sum _{\begin{array}{c} \ell =0\\ (j+\ell )\ \mathrm{even} \end{array}}^{j-2} (1+2\ell )(1+(2m+1)(H_{j-1}- H_\ell )) \phi _{\ell ,m}(x)+\xi _{j-1,m}(x)\right] \nonumber \\- & {} \frac{2(j-1)}{j}\, \left[ \displaystyle \sum _{\begin{array}{c} \ell =0\\ (j+\ell )\ \mathrm{even} \end{array}}^{j-4} (1+2\ell )(H_\ell -H_{j-2}) \phi _{\ell ,m}(x)\displaystyle \right. \nonumber \\&\left. + \sum _{\begin{array}{c} \ell =0\\ (j+\ell )\ \mathrm{odd} \end{array}}^{j-3}(1+2\ell )(1+(2m+1)(H_{j-2}-H_\ell )) \phi _{\ell ,m}(x)+\xi _{j,m}(x)\right] .\nonumber \\ \end{aligned}$$
(12)

If we substitute the recurrence relation (6) into relation (12) and make use of the recurrence relation (4), then after performing some algebraic computations, relation (10) can be obtained for \(x\in [0,1]\). The corresponding result for [ab] follows by making the change of variable \(\displaystyle x\rightarrow \frac{x-a}{b-a}\). \(\square \)

The following two corollaries express the derivatives of the vector \({{\varvec{\Phi }}}(x)\) in terms of \({{\varvec{\Phi }}}(x)\). These expressions will serve in deriving the proposed spectral solutions.

Corollary 1

The first derivative of \({{\varvec{\Phi }}}(x)\) can be expressed in the form

$$\begin{aligned} D {{\varvec{\Phi }}}(x)= {{\varvec{\Phi }}}(x) G+ \varvec{\xi }(x), \end{aligned}$$
(13)

where \(\varvec{\xi }(x)=\left( \xi _{0,m}(x),\ldots ,\xi _{M,m}(x)\right) ^T\), and \(G=\left( g_{ij}\right) _{i,j=0}^{M}\) is \((M+1)\times (M+1)\) matrix with the following entries:

$$\begin{aligned} g_{ij}=\frac{2(2i+1)}{b-a}\left\{ \begin{array}{lll} \displaystyle 1+(2m+1)(H_j-H_i), &{} &{}\mathrm{if} \, i< j,\;\; \mathrm{and}\ (i+j) \; \mathrm{odd},\\ \displaystyle H_i- H_j, &{} &{} \mathrm{if}\, i< j,\;\; \mathrm{and}\ (i+j) \; \mathrm{even},\\ \displaystyle 0, &{} &{}\mathrm{otherwise}. \end{array}\right. \end{aligned}$$
(14)

Corollary 2

The \(\ell \)-th derivative of \({{\varvec{\Phi }}}(x)\) can be calculated by the formula

$$\begin{aligned} {{\varvec{\Phi }}}^{(\ell )}(x)= \left\{ \begin{array}{ll} \displaystyle {{\varvec{\Phi }}}(x)G^\ell + \sum _{r=0}^{\ell -1}G^{\ell -r-1} \varvec{\xi }^{(r)}(x), &{}\quad 1\le \ell \le M,\\ \displaystyle \sum _{r=0}^{\ell -1}G^{\ell -r-1} \varvec{\xi }^{(r)}(x), &{}\quad \ell >M,\\ \end{array} \right. \end{aligned}$$
(15)

and \(G^0\) is the identity matrix of order \((M+1)\).

Remark 2

Equation (14) shows that the matrix G is an upper triangular matrix whose elements in the main diagonal are zeros. This leads to the nilpotency of G. That is \(G^\ell =\mathbf {0}\) for \(\ell >M\).

Now, we can obtain numerical approximations for problem (1)–(5). We apply a typical collocation technique, by enforcing (9) to be satisfied exactly at \((M+1)\) distinct points \(x_j,\)\(j=0,\ldots , M\) in [ab]:

$$\begin{aligned}&{{\varvec{\Phi }}}^{(2m+1)} (x_j) B=f\left( x_j, {{\varvec{\Phi }}} (x_j) B, {{\varvec{\Phi }}}' (x_j) B,\ldots , {{\varvec{\Phi }}}^{(q)} (x_j) B\right) , \ \nonumber \\&\quad q =0,1,\ldots ,2m,\ j=0,\ldots , M. \end{aligned}$$
(16)

Equation (16) represents an algebraic system of equations of dimension \((M+1)\) in the unknowns \(b_0,\ldots , b_M\). This system can be written in the form

$$\begin{aligned} \Omega B= F(B), \end{aligned}$$
(17)

where

$$\begin{aligned} F(B)=\left[ \begin{array}{c} f\left( x_0, {{\varvec{\Phi }}} (x_0) B, {{\varvec{\Phi }}}' (x_0) B,\ldots , {{\varvec{\Phi }}}^{(q)} (x_0) B\right) \\ \vdots \\ f\left( x_N, {{\varvec{\Phi }}} (x_M) B, {{\varvec{\Phi }}}' (x_M) B,\ldots , {{\varvec{\Phi }}}^{(q)} (x_M) B\right) \\ \end{array}\right] , \end{aligned}$$

and

$$\begin{aligned} \Omega =\left[ \begin{array}{ccc} \phi _{0,m}^{(2m+1)}(x_0) &{} \cdots &{} \phi _{M,m}^{(2m+1)}(x_0)\\ \vdots &{} &{} \vdots \\ \phi _{0,m}^{(2m+1)}(x_M) &{} \cdots &{} \phi _{M,m}^{(2m+1)}(x_M) \end{array}\right] . \end{aligned}$$

Observe that \(\phi _{j,m}(x)\), \(0\le j\le M\) are linearly independent; then, also the polynomials \(\phi ^{(2m+1)}_{j,m}(x)\), \(0\le j\le M\) are linearly independent. Moreover, \(\{\phi ^{(2m+1)}_{j,m}(x)\}\), \(0\le j\le M\), forms a basis of the space of polynomials of degree which does not exceed M. Therefore, the \((M+1)\) columns of \(\Omega \) are linearly independent and hence \(\Omega \) is a nonsingular matrix.

Following the same techniques used in [26], the following theorem can be proved.

Theorem 2

If \(T=\left\| \Omega ^{-1}\right\| \sum _{j=0}^q L_j<1\), where \(L_j\), \(j=0,\ldots , q\), are the Lipschitz constants of f, then the system in (17) has a unique solution. This solution can be obtained with the aid of the iterative method

$$\begin{aligned} B^{(\eta +1)}=G\left( B^{(\eta )}\right) ,\qquad \eta \ge 0, \end{aligned}$$
(18)

with \(B^{(0)}\) fixed and \(G(B)= \Omega ^{-1}F(B)\). Moreover,

$$\begin{aligned} \left\| B-B^{(\eta )} \right\| _\infty \le \frac{T^{\eta }}{1-T} \left\| B^{(1)}-B^{(0)} \right\| _\infty . \end{aligned}$$
(19)

Remark 3

If f is linear, then system (17) is linear too.

4 Convergence of the Method

Under the hypothesis of Theorem 2, let \(\eta \) be the number of iterations required by method (18) for a fixed tolerance, and let \(B^{(\eta )}=\left[ b_0^{(\eta )},b_1^{(\eta )},\ldots , b_M^{(\eta )}\right] \) be the solution of system (17). Then, the numerical solution of problem (1)–(5) can be written as

$$\begin{aligned} y_{\eta ,M}(x) =\sum _{i=0}^M b^{(\eta )}_i \phi _{i,m}(x). \end{aligned}$$

Hence, for all \(x\in (a,b)\), we have

$$\begin{aligned} y_M(x)-y_{\eta ,M}(x) =\sum _{i=0}^M \left( b_i-b^{(\eta )}_i\right) \phi _{i,m}(x)={\varvec{\phi }} (x) \left( B- B^{(\eta )}\right) . \end{aligned}$$

Since \(|L_j^{*}(x)|\le 1,\forall x\in [a,b]\) ([33]), then (19) yields

$$\begin{aligned} |y_M(x)-y_{\eta ,M}(x)| \le \frac{T^{\eta }}{1-T} \left\| B^{(1)}-B^{(0)} \right\| _\infty (b-a)^{2m+1}. \end{aligned}$$

From this, the following proposition holds.

Proposition 1

Under the hypothesis of Theorem 2, for all M

$$\begin{aligned} \lim _{\eta \rightarrow \infty } \Vert y_{M}-y_{\eta ,M}\Vert _w=0. \end{aligned}$$

Now, assume that

$$\begin{aligned} y(x)=(b-x)^m (x-a)^{m+1} g(x) , \end{aligned}$$

with \(g(x)\in C^{m}[a,b]\) and \(|g^{(m)}(x)|\le S\), \(\forall x\in [a,b]\), and S a positive integer.

In this case, the coefficients \(b_j\) of the expansion (7) are given by

$$\begin{aligned} b_j=\frac{2j+1}{b-a}\int _{a}^b g(x) L_j^{*} (x)\mathrm{d}x. \end{aligned}$$

Hence, we have (see [26])

$$\begin{aligned} |b_j|< \frac{S (b-a)^m}{j^{m-1}}, \qquad j\ge m>2, \end{aligned}$$

and the following estimate for the proposed expansion (7) holds

$$\begin{aligned} \Vert y-y_{M}\Vert _{w} <\frac{S(b-a)^{m+\frac{1}{2}}}{2\,\sqrt{m-1}\, M^{m-1}}, \end{aligned}$$
(20)

where \(y_M(x)\) is given in (8) and \(\Vert \cdot \Vert _w\) is the \(L^2_w\) norm with \(w(x)=\frac{1}{(b-x)^{2m}(x-a)^{2m+2}}\).

Theorem 3

Under the hypothesis of Theorem 2, it results

$$\begin{aligned} \lim _{M\rightarrow \infty } \Vert y- y_{M}\Vert _w =0. \end{aligned}$$
(21)

Proof

The proof follows from (20), taking into account relation (19). \(\square \)

5 Numerical Examples

In this section, we present five numerical examples of different odd-order BVPs. We apply the operational collocation method (OCM) which is proposed in detail in Sect. 3. In all examples, the collocation points are taken to be the zeros of \(L^{*}_{M}(t)\) in the interval [ab]. In addition, in all examples of this section, the errors are evaluated in maximum norm, namely \(E=\max \limits _{a\le t\le b}\left| y(t)-y_{N}(t)\right| \), where \(y_{N}(t)\) is the approximate solution.

Example 1

Consider the following third-order linear BVP [5, 34]:

$$\begin{aligned} y^{(3)}(t)-t\, y(t)=\left( t^3-2\, t^2-5\, t-3\right) \, e^t,\quad t\in [0,1], \end{aligned}$$
(22)

governed by the boundary conditions:

$$\begin{aligned}&y(0)=y(1)=0,\quad y'(0)=1, \end{aligned}$$

with exact solution

$$\begin{aligned} y(t)=t\, (1-t)\, e^t. \end{aligned}$$

Table 1 lists the maximum absolute errors E resulting from the application of OCM for different values of M.

Table 1 Maximum absolute error for Example 1

The problem in (22) was solved before using the following methods:

  • The Sinc collocation method in [34]. The method was built on employing the Sinc functions as basis functions and utilizing the collocation method for obtaining the desired numerical solution. The collocation points \(x_{j},\, j=-M+1,\ldots ,M+1\) were chosen suitably. The used collocation method transforms the method into a nonlinear algebraic system of order \((2M+3)\). Table 2 illustrates the maximum errors \(e_{M}\) obtained in [34] for some values of M.

    It is to be noted here that to obtain an error less than \(10^{-15}\) using the method developed in [34], we take \(M=128\). This means that a nonlinear system of order 259 should be solved to achieve such accuracy. However, in our proposed method, only a linear system of order 11 is required to be solved to obtain the error: \(2.339\cdot 10^{-16}\). This demonstrates an advantage of our method.

  • The quintic splines in [5]. The method was built on using a certain fourth-order method, and uniform Mesch points \(\{x_{j}: j=0,1,\ldots ,M\}\) are used with mech size h. The minimum error obtained in [5] was \(6.32\cdot 10^{-9}\) when \(h=\frac{1}{32}\).

Table 2 Maximum errors obtained for Example  1 in [34]

Example 2

Consider the following seventh-order linear BVP ([10]):

$$\begin{aligned} y^{(7)}(t)-y(t)=-7\, e^t,\quad t\in [0,1], \end{aligned}$$

governed by the boundary conditions:

$$\begin{aligned}&y(0)=1,\quad y^{(1)}(0)=0,\quad y^{(2)}(0)=-1,\quad y^{(3)}(0)=-2,\\&y(1)=0,\quad y^{(1)}(0)=-e,\quad y^{(2)}(1)=-2e. \end{aligned}$$

The exact solution is

$$\begin{aligned} y(t)=(1-t)\, e^t. \end{aligned}$$

Table 3 displays a comparison between the absolute errors obtained by our proposed method (OCM) for \(M=8\) and those obtained by the two methods: Adomian decomposition method (ADM) and homotopy perturbation method (HPM), which are developed in [10].

Table 3 Comparison between different methods for Example 2

Example 3

Consider the fifth-order linear BVP (see, [35, 36]):

$$\begin{aligned} y^{(5)}(t)+y^{(4)}(t)+e^{-2\, t}\, y^2(t)=2\, e^t+1, \quad 0\leqslant t \leqslant 1 , \end{aligned}$$

governed by the boundary conditions

$$\begin{aligned} y(0)=1,\quad y'(0)=1,\quad y''(0)=1,\quad y(1)=e,\quad y'(1)=e, \end{aligned}$$

with the analytic solution \(y(t)=e^t.\)

In Table 4, we list the maximum absolute errors resulting from the application of OCM for different values of M. Table  5 presents a comparison between the best errors obtained by the application of OCM and the best errors obtained by the application of the following two methods:

  • Sinc method used in [35].

  • Sextic spline collocation method used in [36].

Table 4 Maximum absolute error for Example 3
Table 5 Comparison between different methods for Example 3

Example 4

Consider the nonlinear seventh-order BVP ([10]):

$$\begin{aligned}&y^{(7)}(t)-y^2(t)=e^t \left( -8 (t+6) \sin (t)-e^t (t-1)^2 \cos ^2(t)-8 (t-1) \cos (t)\right) , \nonumber \\&\quad t\in [0,1], \end{aligned}$$
(23)

with the boundary conditions:

$$\begin{aligned}&y(0)=1,\quad y^{(1)}(0)=0,\quad y^{(2)}(0)=-2,\quad y^{(3)}(0)=-2,\\&y(1)=0,\quad y^{(1)}(0)=-e\quad \cos (1),\quad y^{(2)}(1)=-2\quad e(\cos (1)-\sin (1)). \end{aligned}$$

The exact solution of (23) is

$$\begin{aligned} y(t)=(1-t)\, e^t\, \cos (t). \end{aligned}$$

A comparison between the results obtained by the application of OCM for \(M=8\) and the two methods, namely Adomian decomposition method (ADM) and homotopy perturbation method (HPM), developed in [10] is presented in Table 6.

Table 6 Comparison between different methods for Example 4

Example 5

Consider the following ninth-order linear BVP ([37]):

$$\begin{aligned} y^{(9)}(t)+y(t)=(t (t+18)-1) \cos (t)-\left( t^2-73\right) \sin (t),\quad t\in [-1,1], \end{aligned}$$
(24)

governed by the boundary conditions:

$$\begin{aligned} y(-1)&=0,\, y^{(1)}(-1)=2\, \cos (1),\, y^{(2)}(-1)=2\, \cos (1)-4\, \sin (1),\, y^{(3)}(-1)\\&=6(\cos (1)+\sin (1)),\\ y(1)&=0,\, y^{(1)}(-1)=2\, \cos (1),\, y^{(2)}(-1)=2\, \cos (1)-4\, \sin (1),\, y^{(3)}(-1)\\&=6(\cos (1)+\sin (1)),\\ y^{(4)}(1)&=-12\, \cos (1)+8\, \sin (1). \end{aligned}$$

The exact solution of (24) is

$$\begin{aligned} y(t)=(t^2-1)\, \cos (t). \end{aligned}$$

In Table 7, we list the maximum absolute errors obtained when OCM is applied for different values of M. This table shows that we reach highly accurate solutions for small values of M. In addition, Table 8 displays a comparison between the best errors obtained by the application of OCM and the so-called nonpolynomial spline method developed in [37].

Table 7 Maximum absolute error for Example 5
Table 8 Comparison between OCM and the method in [37] for Example  5

6 Conclusions

In this paper, we have introduced a new matrix of derivatives of a certain basis of Legendre polynomials. This matrix, whose nonzero elements are expressed in terms of the harmonic numbers, is utilized to find approximate solutions of both linear and nonlinear odd-order BVPs. Given a set of \((M+1)\) distinct points in (ab), the exact solution y(t) of the odd-order problem is approximated by a polynomial \(y_M(t)\). Convergence of the method has been studied. The numerical experiments show the efficiency and applicability of the proposed algorithm. Moreover, highly accurate solutions are achieved by taking few terms of the proposed expansion.