1 Introduction

In this paper, we aim to exhibit a collocation spectral method for numerically solving the nonlinear boundary value problems (BVPs) using operational matrices of Bernstein polynomials to make a comparison between the proposed method and the some other existing methods. Therefore, we utilize all of the boundary values to derive an equivalent integro-differential equation before applying the scheme to calculate the solution components. Unknown functions in the equivalent integro-differential equation are approximated in terms of Bernstein polynomials. By applying the operational matrices and collocation method, a system of algebraic equations is obtained which is solved by \(Mathematica^{TM}\).

As mentioned in [10], for the sake of generality, \(k\)th-order nonlinear differential equation is considered as

$$\begin{aligned} \frac{d^k u(x)}{dx^k}=Nu(x)+g(x),\qquad k\ge 2 \end{aligned}$$
(1.1)

subject to \(k\) boundary conditions

$$\begin{aligned} u^{(p_0)}(x_0)=\alpha _0\,, \quad u^{(p_1)}(x_1)=\alpha _1\,, \ldots , u^{(p_{k-1})}(x_{k-1})=\alpha _{k-1}\,, \end{aligned}$$
(1.2)

where \(x_0,\,x_1,\,\ldots ,\,x_{k-1}\) are not all equal, \(0=p_0\le p_1\le \cdots \le p_{k-1}\le k-1\), \(p_j\le j\) for \(j=1,2,\ldots ,k-1\), \(p_i\ne p_j\) if \(x_i=x_j.\) The field of \(x\) in Eq. (1.1) is \(\min \{x_0, x_1, \ldots , x_{k-1}\} \le x\le \max \{x_0, x_1, \ldots , x_{k-1}\}\). If there are \(l\) different points in \(x_0,\,x_1,\,\ldots ,\,x_{k-1}\) then we treat an \(l\)-point BVP. By \(p_0 = 0\) we presume that the boundary value problem is in the Dirichlet form. \(Nu\) is an analytic nonlinear operator, and \(g(x)\) is the system input, which is a given continuous function. We consider the nonlinear BVPs subject to multi-point boundary conditions for at most \(k=8\) and suppose that their solutions exist uniquely [2]. Presented method in this paper can be generalized similarly for appropriate higher order differential equations and partial differential equations [28, 29].

We continue in Sect. 2 by presenting the properties of Bernstein polynomials. In Sect. 3, we describe function approximation by using the Bernstein polynomial basis and an upper bound of the approximation error is deduced. We introduce shortly operational matrices of integration, differentiation, dual and product of Bernstein polynomial in Sect. 4. Numerical scheme for the solution of (1.1)–(1.2) is elaborated in Sect. 5. In Sect. 6, we report our numerical findings and make comparisons between the presented method and some other methods. Section 7 consists of a brief conclusion.

2 Properties of Bernstein polynomials

The Bernstein polynomials of \(m\)th degree are defined on the interval \([a,b]\) as  [2729]

$$\begin{aligned} B_{i,m}(x)={m\atopwithdelims ()i}\frac{(x-a)^i(b-x)^{m-i}}{(b-a)^m},\quad 0\le i \le m \end{aligned}$$

where

$$\begin{aligned} {m\atopwithdelims ()i}=\frac{m!}{i!(m-i)!} . \end{aligned}$$

These Bernstein polynomials form a basis on [a,b]. In Bernstein polynomials of \(m\)th degree, there are \(m + 1\) \(m\)th degree polynomials which this causes to increase the efficiency and performance of the new method in comparison with methods which use of other polynomials. For convenience, we set \(B_{i,m}(x) = 0\), if \(i <0\) or \(i > m\). A recursive definition can also be used to generate the Bernstein polynomials over \([a,b]\) such that the \(i\)th \(m\)th-degree Bernstein polynomials can be written

$$\begin{aligned} B_{i,m}(x) = \frac{(b - x)}{b-a}B_{i,m-1}(x)+ \frac{x-a}{b-a} B_{i-1,m-1}(x). \end{aligned}$$

It can easily be shown that the Bernstein polynomials are positive, linear independent and the sum of all the Bernstein polynomials is unity for all real \(x\in [a,b],\) i.e., \(\sum _{i=0}^mB_{i,m}(x)=1\) (it is said that the Bernstein polynomials have the partition unity property). It is easy to show that any given polynomial of degree \(m\) can be expanded in terms of these basis functions. It is well known [4, 12] that the Bernstein–Vandermonde matrix \(A\) is a strictly totally positive matrix when the points satisfy \(0 < t_0 < t_1 < \ldots <t_m < 1\) which \(A=[a_{i+1,j+1}]\) and \(a_{i+1,j+1}=B_{j,m}(t_i)\) for \(i,j=0,\cdots , m\). It is noteworthy that matrix \(A\) is used in this method for solving the system of algebraic equations by collocation technique.

3 Approximation of functions

Suppose that \(H=L^2[a,b]\) where \(a,b \in \mathbb {R}\), let \(\{B_{0,m},B_{1,m}, \ldots ,B_{m,m}\} \subset H\) is the set of Bernstein polynomials of \(m\)th degree and

$$\begin{aligned} Y=Span\{B_{0,m},B_{1,m},\ldots ,B_{m,m}\} \end{aligned}$$

and \(f \) is an arbitrary element in \(H\). Since \(Y\) is a finite dimensional vector space, \(f\) has a unique best approximation out of \(Y\), say \(y_0\in Y\), that is

$$\begin{aligned} \exists y_0\in Y;\ \forall y\in Y \ ||f-y_0||_2\le ||f-y||_2, \end{aligned}$$

where \(||f||_2=\sqrt{\langle f,f \rangle }\) and \(\langle f,g \rangle =\int _{a}^{b}f_{(t)}g_{(t)}dt \ \).

In [27], it is shown that the unique coefficient vector \(c^T=[c_0,c_1, \ldots , c_m]\) exists such as

$$\begin{aligned} f\simeq y_0=\sum _{i=0}^m c_iB_{i,m}=c^T\phi , \end{aligned}$$

where \(\phi ^T=[B_{0,m},B_{1,m}, \ldots ,B_{m,m}]\) and \(c^T\) can be obtained

$$\begin{aligned} c^T=\left( \int _{a}^{b} f(x)\phi (x)^Tdx\right) Q^{-1}, \end{aligned}$$

which \(Q\) is said dual matrix of \(\phi \) and is defined as

$$\begin{aligned} Q=\langle \phi \ ,\ \phi \rangle = \int _{a}^{b} \phi (x)\phi (x)^Tdx. \end{aligned}$$

Theorem 1

Suppose that \(H\) be a Hilbert space and \(Y\) be a closed subspace of \(H\) such that \(dim \quad Y <\infty \) and \(\{y_1, y_2, \ldots , y_n\}\) is any basis for \(Y\). Let \(x\) be an arbitrary element in \(H\) and \(y_0\) be the unique best approximation to \(x\) out of \(Y\). Then

$$\begin{aligned} ||x-y_0||_2^2=\frac{G(x, y_1, y_2, \ldots ,y_n)}{G(y_1, y_2, \ldots , y_n)}, \end{aligned}$$

where

$$\begin{aligned} G(x,y_1, y_2, \ldots , y_n)= \left| \begin{array}{c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c} \langle x,x \rangle &{}\langle x,y_1 \rangle &{}\cdots &{}\langle x,y_n \rangle \\ \langle y_1,x \rangle &{}\langle y_1,y_1 \rangle &{}\cdots &{}\langle y_1,y_n \rangle \\ \vdots &{}\vdots &{}\quad &{}\vdots \\ \langle y_n,x \rangle &{}\langle y_n,y_1 \rangle &{}\cdots &{}\langle y_n,y_n \rangle \end{array} \right| . \end{aligned}$$

Proof

 [18]. The exact value of approximation error is presented by the Theorem 1 and in the following lemma we present an upper bound of approximation error.

Lemma 1

Suppose that the function \(g:[a ,b]\rightarrow \mathbb {R}\) be \(m+1\) times continuously differentiable, \(g\in C^{m+1}[a ,b],\) and \(Y=Span\{B_{0,m},B_{1,m}, \ldots ,B_{m,m}\}\). If \(c^T\phi \) be the best approximation \(g\) out of \(Y\) then the mean error bound is presented as follows:

$$\begin{aligned} \left| \left| g-c^T\phi \right| \right| _2\le \frac{M(b-a)^{\frac{2m+3}{2}}}{(m+1)!\sqrt{2m+3}} \ , \end{aligned}$$

where \(M=\max _{x\in [a ,b]} |g^{(m+1)}(x)|.\)

Proof

 [27]. Lemma 1 shows that the method of approximation converges to \(f\) when \(m\rightarrow \infty \).

4 Operational matrices of Bernstein polynomial

Operational matrices of the integration \(P\), differentiation \(D\), dual \(Q\) and product \(\widehat{C}\) are introduced as following which the details of obtaining of these matrices are given in [27]

$$\begin{aligned} \begin{matrix} \int _0^x \phi (t)dt\simeq P\phi (x), &{}\quad \frac{d}{dx}\phi (x)\simeq D\phi (x),\\ Q=\int _a^b \phi (x)\phi ^T(x) dx, \, &{} \quad c^T\phi (x)\phi (x)^T\simeq \phi (x)^T\widehat{C}. \\ \end{matrix} \end{aligned}$$

5 Solution of problem

In this section, we convert the main problem to an equivalent integro-differential equation which implies all conditions of main problem. Then, the unknown coefficients are identified by a numerical scheme which will be described in the following.

It should be noticed that:

  1. 1.

    Without loss of generality, we can assume that the given differential equation is defined on interval \([0,1]\), otherwise we transfer the given interval from \([a,b]\) to \([0,1]\) (e.g. see Example 3).

  2. 2.

    Since there are many different cases of differential equation with multi-point boundary conditions, therefore we perform our method on the following forth order differential equation (similar to Example 2). This method can be generalized analogously to other second, third, fourth and higher order differential equations.

Consider the following differential equation (similar to Example 2)

$$\begin{aligned}&u^{(4)}(x)=Nu(x)+g(x),\end{aligned}$$
(5.1)
$$\begin{aligned}&u(0)=A,\quad u^{\prime \prime }(x_1)=B,\quad u^{\prime \prime \prime }(x_2)=E,\quad u(1)=F, \quad 0\le x_2< x_1 \le 1 \end{aligned}$$
(5.2)

which \(A, B, F, E\) are scalar values and \(Nu\) is an analytic nonlinear operator, and \(g(x)\) is the system input, which is a known continuous function. Using integration, we have

$$\begin{aligned}&u^{(3)}(x)=u^{(3)}(0)+\int _0^x u^{(4)}(s)ds,\end{aligned}$$
(5.3)
$$\begin{aligned}&u^{(2)}(x)=u^{(2)}(0)+xu^{(3)}(0)+\int _0^x\int _0^r u^{(4)}(s)dsdr, \end{aligned}$$
(5.4)
$$\begin{aligned}&u'(x)=u'(0)+xu^{(2)}(0)+\frac{x^2}{2}u^{(3)}(0)+\int _0^x\int _0^z\int _0^r u^{(4)}(s)dsdrdz,\nonumber \\&u(x)=A+xu'(0)+\frac{x^2}{2}u^{(2)}(0)+\frac{x^3}{6}u^{(3)}(0)+\int _0^x\int _0^n\int _0^z\int _0^r u^{(4)}(s)dsdrdzdn, \end{aligned}$$
(5.5)

which \(u'(0), u^{(2)}(0)\) and \(u^{(3)}(0)\) are unknown and are determined by (5.2). From (5.2), (5.3), (5.4) and (5.5), we achieve

$$\begin{aligned}&u^{(3)}(0)=E-\int _0^{x_2} u^{(4)}(s)ds, \\&u^{(2)}(0)=B-\left[ x_1u^{(3)}(0)+\int _0^{x_1}\int _0^r u^{(4)}(s)dsdr\right] , \end{aligned}$$

and

$$\begin{aligned} u'(0)=F-\left[ A+\frac{u^{(2)}(0)}{2}+\frac{u^{(3)}(0)}{6}+\int _0^1\int _0^n\int _0^z\int _0^r u^{(4)}(s)dsdrdzdn \right] . \end{aligned}$$

Now, an equivalent integro-differential equation which implies all conditions of main problem is obtained by substituting achieved values \(u'(0), u^{(2)}(0)\) and \(u^{(3)}(0)\) in (5.5), i.e.

$$\begin{aligned} u(x)&= A+x\left( F-\left[ A+\frac{u^{(2)}(0)}{2} +\frac{u^{(3)}(0)}{6}+\int _0^1\int _0^n\int _0^z\int _0^r u^{(4)}(s)dsdrdzdn \right] \right) \nonumber \\&\quad +\frac{x^2}{2}\left( B-\left[ x_1u^{(3)}(0)+\int _0^{x_1}\int _0^r u^{(4)}(s)dsdr\right] \right) \nonumber \\&\quad +\frac{x^3}{6}\left( E-\int _0^{x_2} u^{(4)}(s)ds \right) +\int _0^x\int _0^n\int _0^z\int _0^r u^{(4)}(s)dsdrdzdn. \end{aligned}$$
(5.6)

If we expand the function \(u^{(4)}(x)\) in terms of Bernstein polynomial as

$$\begin{aligned} u^{(4)}(x)\simeq c^T \phi (x) \end{aligned}$$
(5.7)

and utilize the operational matrix, then we will have

$$\begin{aligned}&u^{(3)}(0)=E-c^T \int _0^{x_2} \phi (s)ds=y_4,\\&u^{(2)}(0)=B-\left[ x_1 y_4+c^T p \int _0^{x_1}\phi (s)ds\right] =y_3,\\&u'(0)=F-\left[ A+\frac{y_3}{2}+\frac{y_4}{6}+c^T p^3\int _0^1\phi (s)ds \right] =y_2. \end{aligned}$$

Replacing them in (5.6) gives

$$\begin{aligned} u(x)=A+xy_2+\frac{x^2}{2}y_3+\frac{x^3}{6}y_4+c^T p^4\phi (x)=y_1(x). \end{aligned}$$
(5.8)

Since the approximate solution (5.8) must satisfy in (5.1), we define the error remainder function \(y(x)\) as

$$\begin{aligned} y(x)= u^{(4)}(x)-Nu(x)-g(x) \end{aligned}$$

and substitute the (5.7) and (5.8) in \(y(x)\)

$$\begin{aligned} y(x)= c^T \phi (x)-Ny_1(x)-g(x) \end{aligned}$$

and then specify the unknown coefficient \(c\) using collocation.

This method can readily generalized to appropriate two-dimensional partial differential equations (see Example 4) and higher order ordinary differential equations by multi-points boundary conditions.

6 Illustrative examples

To demonstrate the validity, application and efficiency of the described method, the obtained results for several examples are presented in this section. In all examples the package of Mathematica (8.0) has been used to solve the test problems.

Example 1

This example is adapted from [21] and studied by modified Adomian decomposition method [10] and also in [5, 6]. Consider the two-point BVP for the second-order nonlinear differential equation with an exponential nonlinearity

$$\begin{aligned}&u''(x)=e^{u(x)}, \quad 0 \le x \le 1,\\&u(0)=0, \quad u(1)=0, \end{aligned}$$

which has the exact solution

$$\begin{aligned} u^*(x)=2\ln \left( k\sec {\frac{k(2x-1)}{4}}\right) -\ln (2)\,, \end{aligned}$$

where \(k\) satisfies \(k\sec \left( \frac{k}{4}\right) =\sqrt{2},\) hence, with \(16\) significant figures \(k = 1.336055694906108\). As mentioned in [21], the problem is mildly nonlinear and is easy to solve. In fact, if an algorithm does not work well on this problem, the algorithm should be suspect. Using proposed method, we present the error values \(u(x)\) in some points and \(||u_{m}-u^*||_{\infty }\) for \(m=3,\,6,\,9\) in Table 1 to highlight the rapid rate of convergence and plot the error function for \(m=9\) in Fig. 1.

Fig. 1
figure 1

Error function in Example 1

Table 1 Error values of \(u(x)\) of method in Example 1

In contrast to the new approach, we note that the maximum approximation error of modified Adomian decomposition method related to \(E_3(x)\) in [10] is a multiple of \(10^{-3}\) whereas the maximum approximation error of the presented method is a multiple of \(10^{-8}\) when both methods yield a polynomial of degree 6. Also, the minimal approximation errors of recursion scheme (the multilevel augmentation method) in [5] are a multiple of \(10^{-4}\) and \(10^{-8}\) for norms \(||.||_1\) and \(||.||_0\), respectively, and the maximum approximation error of the presented method is a multiple of \(10^{-10}\) with \(m=9\) by \(||.||_{\infty }\). Furthermore, the maximum approximation absolute errors of the presented methods in [21] and [6] are a multiple and \(10^{-11}\) and of \(10^{-8}\), respectively.

We see that the value of \(m\) (degree of Bernstein polynomial) can affect the rate of convergence of method. Thus we can use this phenomenon to design more efficient schemes by increasing the value of \(m\). Our method does not depend on any parameter while the method in [10] includes a parameter and the scheme in [5] contains three undetermined coefficients.

Example 2

Consider the four-point BVP for the fourth-order nonlinear differential equation with a product nonlinearity [10, 22]

$$\begin{aligned}&u^{(4)}(x)+u(x)u^{\prime }(x)-4x^7-24=0, \quad 0\le x \le 1\\&u(0)=0, \quad u^{\prime \prime \prime }(0.25)=6, \quad u^{\prime \prime }(0.5)=3, \quad u(1)=1, \end{aligned}$$

with the exact solution \(u(x)=x^4\). In Fig. 2, we plot the error of \(u(x)\) for \(m=6\) and display the error values \(u(t)\) for \(m=3,\,6\) in some points in Table 2.

Table 2 Error values of \(u(x)\) for \(m=3,\,6\) in Example 2

In contrast to the new method, we note that, in [10] maximum approximation error of modified Adomian decomposition method related to \(E_1(x)\) and \(E_2(x)\) (which yields polynomials of degree 25 and 39, respectively,) are a multiple of \(10^{-4}\) and \(10^{-7}\), respectively, but maximum approximation error of the presented method for \(m=6\) (which yields a polynomial of degree 6) is a multiple of \(10^{-16}\) which it shows the high preciseness and good performance of method. We also note that the convergence of the new method does not depend on any parameter while the scheme in [22] contains three undetermined coefficients and the scheme in [10] includes an undetermined parameter.

Fig. 2
figure 2

Error figure of \(u(x)\) for \(m=6\) in Example 2

Example 3

Consider the BVP for the fourth-order nonlinear differential equation with an exponential nonlinearity [10, 23]

$$\begin{aligned}&u^{(4)}(x)=-6\,e^{-4u(x)}, \quad 0\le x \le 4-e,\\&u(0)=1, \quad u^{\prime \prime }(0)=-\frac{1}{e^2},\quad u(4-e)=\ln (4), \quad u^{\prime \prime }(4-e)=-\frac{1}{16} , \end{aligned}$$

which has the exact solution \(u(x)=\ln (e + x)\).

We first let \(x=(4-e)t \, \) to transfer the differential equation from the interval \([0, (4-e) ]\) to \( \, [0,1]\), so the original differential equation is altered to

$$\begin{aligned}&v^{(4)}(t)=-6(4-e)^4\,e^{-4v(t)}, \quad 0\le t \le 1\\&v(0)=1, \quad v''(0)=-\frac{(4-e)^2}{e^2},\quad v(1)=\ln (4), \quad v''(1)=-\frac{(4-e)^2}{16} , \end{aligned}$$

with the exact solution \(v(t)=\ln ((4-e)t+e)\) which \(v(t)=u((4-e)t)\). In Fig. 3, we plot the error of \(v(t)\) for \(m=9\) and exhibit the error values \(v(t)\) for \(m=3,\,6,\,9\) in some points in Table 3.

In contrast with the new scheme, we notice that in [10] maximum approximation error of modified Adomian decomposition method related to \(E_2(x)\), \(E_3(x)\) and \(E_4(x)\) (which yields polynomials of degree \(8,\,12,\,16\), respectively,) are a multiple of \(10^{-3}\), \(10^{-3}\) and \(10^{-4}\), but maximum approximation error of the presented method for \(m=6\) and \(m=9\) (which yields polynomials of degree 6 and 9) are a multiple of \(10^{-8}\) and \(10^{-11}\). Numerical results in Table 3 demonstrate a remarkable accuracy for such low orders of approximation by the presented method because the error function quickly approaches zero by increasing the value of \(m\). We also notice that the scheme in [23] contains two undetermined coefficients while our method does not depend on any parameter.

Fig. 3
figure 3

Error figure of \(v(t)\) for \(m=9\) in Example 3

Table 3 Error values of \(v(t)\) for \(m=3,\,6,\,9\) in Example 3

Example 4

Consider the nonlinear second-order homogeneous partial differential equation [10, 26]

$$\begin{aligned} \theta _{xx}(x,t)+\frac{\varepsilon }{1+\varepsilon \theta (x,t)}(\theta _{x}(x,t))^2-K^2\frac{\theta (x,t)}{1+\varepsilon \theta (x,t)}-\frac{\theta _t(x,t)}{1+\varepsilon \theta (x,t)}=0, \end{aligned}$$

where \(K\) depends on the physical properties and design parameters, and \(\theta (x,t)\) has the domain of definition \(x\in [0, 1]\), \(t\in [0,\infty )\) and subject to a mixed set of homogeneous Neumann and inhomogeneous Dirichlet boundary conditions which includes a sinusoidally varying boundary value,

$$\begin{aligned} \theta _x(0,t)=0, \quad \theta (1,t)=1+S\cos (\beta t). \end{aligned}$$

The physical variables and parameters are \(\theta , x, t, \varepsilon , K, S\) and \(\beta \), which represent the dimensionless temperature, distance, time, thermal conductivity parameter, fin parameter, amplitude of oscillation and frequency of oscillation, respectively. The interested reader can refer to [25, 26] for further details in regard to the derivation and design limitations of this engineering model.

Exact solution \(\theta ^* {(x,t)}\) of this problem is unknown. In order to investigate the approximate solution \(\theta _{n,m}(x,t)\) and examine the convergence of method to the exact solution, we consider the error remainder function

$$\begin{aligned} E (\theta _{n,m}(x,t))&= \frac{\partial ^2 }{\partial x^2}\theta _{n,m}(x,t)+\frac{\varepsilon }{1+\varepsilon \theta _{n,m}(x,t)}\left( \frac{\partial }{\partial x}\theta _{n,m}(x,t)\right) ^2\nonumber \\&\quad -\,K^2\frac{\theta _{n,m}(x,t)}{1+\varepsilon \theta _{n,m}(x,t)}-\frac{\frac{\partial }{\partial t}\theta _{n,m}(x,t)}{1+\varepsilon \theta _{n,m}(x,t)}, \end{aligned}$$

which \(\theta _{n,m}(x,t)= \phi _n^T(x)C\phi _m (t)\) where \(\phi _m\) and \(C\) are Bernstein polynomials of order \(m\) and a \((n+1)\times (m+1)\) matrix, respectively.

For \(S = 0.1, \, \beta = 1, \, K = 0.5, \, \varepsilon = 0.2\), we plot the error surfaces \(E \theta _{n,m}(x,t)\) for \(0\le x \le 1, 0\le t \le 4\pi \) and \(n=m=3\) in Fig. 4.

In contrast to the new method, we note that in [10] maximum approximation error of modified Adomian decomposition method is a multiple of \(10^{-2}\), while maximum approximation error of the presented method for \(m=n=3\) is a multiple of \(10^{-4}\) which shows the high accuracy of method. In Figs. 5, 6 and 7, we plot the the error surfaces \(E (\theta _{3,3}(x,t))\) on \(0\le x \le 1, \ 0\le t \le 4\pi \) for \(S = 0.1, \ \beta = 1, \ K = 0.5\) and different values \(\varepsilon =0.3, 0, -0.3\), respectively.

Fig. 4
figure 4

Error remainder function \(E (\theta _{3,3}(x,t))\) for \(\varepsilon =0.2\) in Example 4

Fig. 5
figure 5

Error remainder function \(E (\theta _{3,3}(x,t))\) for \(\varepsilon =0.3\) in Example 4

Fig. 6
figure 6

Error remainder function \(E (\theta _{3,3}(x,t))\) for \(\varepsilon =0\) in Example 4

Fig. 7
figure 7

Error remainder function \(E (\theta _{3,3}(x,t))\) for \(\varepsilon =-0.3\) in Example 4

Example 5

Consider the nonlinear third-order differential equation [9, 16]

$$\begin{aligned} u^{\prime \prime \prime }(x)+(2+u(x))(1-u^{\prime }(x))^2+(u^{\prime \prime \prime }(x))^3=0, \quad 0<x<1 \end{aligned}$$

with boundary conditions

$$\begin{aligned} u(0)=0, \quad u^{\prime \prime }(0)=0, \quad -2u^{\prime }(1)-(u^{\prime \prime }(1))^2=0. \end{aligned}$$

The existence and uniqueness of the solution for this problem are shown in [8] for \(x \in [0, 1]\). Applying the presented method with \(m=3, 6, 9\), we plot in Fig. 8 the error remainder function

$$\begin{aligned} E_m(x)=u_m^{\prime \prime \prime }(x)+(2+u_m(x))(1-u_m^{\prime }(x))^2+(u_m^{\prime \prime \prime }(x))^3 \end{aligned}$$

for \(m=9\) on [0,1] and list some values of \(E_m(x)\) in Table 4. In contrast to the new scheme, we notice that in [9] the maximum approximation error of the Adomian decomposition method is a multiple of \(10^{-2}\), whereas the maximum approximation error of the presented method for \(m=6\) and \(m=9\) (which yields polynomials of degree 6 and 9) are a multiple of \(10^{-4}\) and \(10^{-6}\).

Fig. 8
figure 8

Error remainder function \(E_9(x)\) in Example 5

Table 4 Some values of error remainder function \(E_m(x)\) in Example 5

Example 6

Consider the nonlinear differential equation for a cantilever nano-electro mechanical system (NEMS)  [11, 20]

$$\begin{aligned}&u^{(4)}(x)+\frac{\alpha _K}{u(x)^K}+\frac{\beta }{u(x)^2}+\frac{\gamma }{u(x)}=0, \quad 0<x<1, \quad K=3,4,\\&u(0)=1, \quad u^{\prime }(0)=0, \quad u^{\prime \prime }(1)=0, \quad u^{\prime \prime \prime }(1)=0. \end{aligned}$$

We take \(K = 3, \) for the range of separation where the van der Waals force predominates, and \(\alpha _K= 0.2, \ \beta = 0.5, \ \gamma = 0.25\) to compute the approximate solution. Applying the presented method with \(m=3, \ 6, \ 9\), we list some values of the error remainder function

$$\begin{aligned} E_m(x)=u_m^{(4)}(x)+\frac{\alpha _K}{u_m(x)^K}+\frac{\beta }{u_m(x)^2}+\frac{\gamma }{u_m(x)}, \end{aligned}$$

in Table 5. In contrast to our new approach, in Table 1 from [11] it is expressed that the maximal error remainder parameter for \(m=15\) is 0.0000188629, whereas the error remainder function \(E_m(x)\) for \(m=9\) is a multiple of \(10^{-7}\) from Table 5. New method does not depend on any parameter too.

Table 5 Some values of error remainder function \(E_m(x)\) in Example 6

Example 7

Consider the nonlinear differential equation for a double cantilever nano-electro mechanical system (NEMS)  [11, 20]

$$\begin{aligned}&u^{(4)}(x)+\frac{\alpha _K}{u(x)^K}+\frac{\beta }{u(x)^2}+\frac{\gamma }{u(x)}=0, \quad 0<x<1, \quad K=3,4,\\&u(0)=1, \quad u'(0)=0, \quad u(1)=1, \quad u'(1)=0. \end{aligned}$$

We take \(K = 4, \) for the range of separation where the Casimir force predominates, and \( \alpha _K= 1, \, \beta = 1.5, \, \gamma = 0.5\) to compute the approximate solution. Applying the presented method with \(m=3, \ 6, \ 9\), we list in Table 6 some values of the error remainder function

$$\begin{aligned} E_m(x)=u_m^{(4)}(x)+\frac{\alpha _K}{u_m(x)^K}+\frac{\beta }{u_m(x)^2}+\frac{\gamma }{u_m(x)}. \end{aligned}$$

In comparison with the new method, in Table 2 from [11] it is expressed that the maximal error remainder parameter for \(m=3\) which yields a polynomial of degree 12, is 0.0400777, whereas from Table 6 the error remainder function \(E_m(x)\) for \(m=9\) (which yields a polynomial of degree 9) is a multiple of \(10^{-7}\). A clear advantage of this technique over the Adomian decomposition method is that no calculation of Adomians polynomials is needed.

Table 6 Some values of error remainder function \(E_m(x)\) in Example 7

Example 8

In [1, 3], it is shown that the unsteady one-dimensional gas flow in a porous medium is modeled by a nonlinear ordinary differential equation as follows

$$\begin{aligned}&y^{\prime \prime }(x)+\frac{2x}{\sqrt{1-\alpha y(x)}}\,y^{\prime }(x)=0, \quad x>0 , \quad 0<\alpha <1 ,\\&y(0)=1 \ , \quad \lim _{x\rightarrow \infty }y(x)=0. \end{aligned}$$

A substantial amount of numerical and analytical work has been invested so far on this model [19, 24]. This problem was also handled by Kidder [17]. Also, finite-difference Keller-box method and shooting method were employed to solve this problem [1]. In order to approximate the solution of this problem, we first transfer main problem from interval \(0\le x < \infty \ \) to \( \ 0< t \le 1\) by transformation function \(t=e^{-x}\), thus our problem convert to

$$\begin{aligned} \begin{array}{c} \displaystyle t^2u''(t)+ tu'(t) \left( 1+ \frac{2\ln t}{{\sqrt{1-\alpha u(t)}}} \right) =0, \quad 0< t<1, \quad 0<\alpha <1 ,\\ \displaystyle u(1)=1 \ , \quad \lim _{t\rightarrow 0}u(t)=0. \end{array} \end{aligned}$$
(6.1)

where \(u(t)=y(-\ln t)\). We apply the presented method for problem 6.1 and propose the some residual values of Eq. 6.1 with \(\alpha = 0.2, \ 0.5\) in Tables 7 and 9, respectively.

To compare our method with numerical findings presented in [1], values of \(u(0)\), \(u(1)\) and \(y^{\prime }(0)\) for \(\alpha = 0.2, \ 0.5\) are exhibited in Tables 8 and 10, respectively, which \(y^{\prime }(x)=\frac{dy(x)}{dx}=-e^{-x}\frac{du(t)}{dt}|_{t=e^{-x}}\). Numerical results show that the high preciseness of our method and this method can be considered a good scale for comparison with other methods existing in [1].

Table 7 Residual values of Eq. 6.1 with \(\alpha = 0.2 \) for Example 8
Table 8 Values of \(u(0)\), \(u(1)\) and \(y'(0)\) with \(\alpha = 0.2 \) for Example 8
Table 9 Residual values of Eq. 6.1 with \(\alpha = 0.5 \) for Example 8
Table 10 Values of \(u(0)\), \(u(1)\) and \(y'(0)\) with \(\alpha = 0.5 \) for Example 8

Example 9

Consider the following high order nonlinear differential equation with multi-point boundary conditions on \([-1,1]\)

Analytic solution of the above differential system is \(y^*(x) = (1-x^2)e^x\). Using transformation function \(x=2t-1\), the problem is altered from interval \(x\in [-1, 1]\) to \(t\in [0, 1]\) as follows

$$\begin{aligned}&\frac{u^{(8)}(t)}{2^8}-\frac{u^{(2)}(t)u^{(3)}(t)}{2^5}\\&\quad = -4e^{2t-2}(2+t)\left( e(5+t)+2te^{2t}(-1+2t+2t^2) \right) , \quad 0\le t \le 1 \\&u(-1) + u(1) = 0, \\&u^{(1)}(0) + u^{(1)}(1) = 4 e^{-1}-4e, \\&u^{(2)}(0) + u^{(2)}(1) = 8 e^{-1}-24e, \\&u^{(3)}(0) + u^{(3)}(1) = -96e, \\&u^{(4)}(0) + u^{(4)}(1) = -64 e^{-1}- 320e, \\&u^{(5)}(0) + u^{(5)}(1) = -320 e^{-1}- 960e, \\&u^{(6)}(0) + u^{(6)}(1) = -1152 e^{-1}- 2688e, \\&u^{(7)}(0) + u^{(7)}(1) = -3584 e^{-1}- 7168e, \end{aligned}$$

where \(u(t)=y(2t-1)\) and \(\frac{d^ky(x)}{dx^k}=\frac{1}{2^k}\frac{d^ku(t)}{dt^k}\). In Table 11, some values of absolute error of \(u(t)\) and \(||u_{m}-u^*||_{\infty }\) of method are presented. Results show that the method is accurate and rapidly converges to the exact solution by increasing order of Bernstein polynomials.

Table 11 Absolute error values of \(u(t)\) for Example 9

Example 10

In this numerical test, the proposed method is applied for the following sixth order nonlinear equation [7]

$$\begin{aligned} y^{(6)}(x)=e^{-x}y^2(x), \qquad x\in [0, 1], \end{aligned}$$

subject to the initial conditions \(y^{(j )}(0)=1\) for j = 0, 1, 2, 3, 4, 5, whose exact solution is \(y^*(x)=e^{x}\). This example was numerically solved by Birkhoff-type interpolation method in [7]. In order to investigate the performance of our method and compare with [7], numerical results for \(m=3,\,6,\, 8\) are presented in Table 12 which the results support the efficiency and accuracy of our method.

Table 12 Absolute error values of \(u(t)\) for Example 10

Example 11

Let us to consider the nonlinear stiff equation [7]

$$\begin{aligned} \left\{ \begin{array}{l@{\quad }l} y_1'(x)=-(2+\varepsilon ^{-1})y_1(x)+\varepsilon ^{-1}y_2(x)^2, &{}y_1(0)=1,\\ y_2'(x)=y_1(x)-y_2(x)-y_2(x)^2,&{} y_2(0)=1, \end{array} \right. \end{aligned}$$

which \(\varepsilon =10^3\). The exact solutions are

$$\begin{aligned} y_1^*(x)=e^{-2x},\qquad y_2^*(x)=e^{-x}. \end{aligned}$$

In Tables 13 and 14, the numerical results with \(m=3,\,6,\, 9,\,12\) of using the present method are showed for \(y_1\) and \(y_2\), respectively. In comparison with Birkhoff-type interpolation method in [7], our method gives solutions with higher precision. This high accuracy of results guaranties the good performance of the method.

Table 13 Absolute error values of \(y_1(t)\) for Example 11
Table 14 Absolute error values of \(y_2(t)\) for Example 11

Example 12

Consider the nonlinear singular initial value problem (IVP) [15]

which

$$\begin{aligned} f(x)&= x\left[ 10(3-4x)x\sin {x}+\cos {\sqrt{x}}\left( 6(2+x^3-x^4)+\sin {x} \left( \ 6x(1-2x)\right. \right. \right. \\&\quad \left. \left. \left. +\sin {\sqrt{2+x^3-x^4}}\right) \right) \right] , \end{aligned}$$

and the exact solution is \(u^*(x)=x^3-x^4+2\).

In [15], combination of homotopy perturbation method and reproducing kernel Hilbert space method was employed for solving this nonlinear singular initial value problem. Presented method is applied for \(m=3,\, 4\) and the error values in some points are proposed in Table 15 and the relative error function \(\left( \left| \frac{u_m(x)-u^*(x)}{u^*(x)}\right| \right) \) for \(m=4\) is plotted in Fig. 9. Approximate solution using Bernstein polynomials of order \(m=4\) is

$$\begin{aligned} u_4(x)=x^3 - x^4+2-3.46945 \times 10^{-17} x + 9.36751 \times 10^{-17} x^2. \end{aligned}$$

In contrast to the new method, we note that in [15] the minimum approximation relative error is a multiple of \(10^{-7}\), while the maximum approximation relative error of the present method with \(m=4\) is a multiple of \(10^{-16}\) which it shows the good performance of method in comparison with other methods.

Fig. 9
figure 9

Relative error function for \(m=4\) in Example 12

Table 15 Error values of \(u(x)\) for \(m=3,\,4\) in Example 12

Example 13

Consider the nonlinear stiff equation [13]

$$\begin{aligned} \left\{ \begin{array}{ll} y_1''(x)=y_1(x)y'_2(x)-x, &{} \quad y_1(0)=1, \quad y_2(0)=0 \\ y_2''(x)=y^2_2(x)-y_1(x)y_2(x)+xe^x , &{} \quad y'_1(0)=2,y'_2(0)=1 \end{array} \right. \end{aligned}$$

whose exact solutions are \(y_1^*(x)=x+e^{x},\qquad y_2^*(x)=x.\)

In [13], this problem was solved using a method which is based on the Banach fixed point theorem. Achieved minimum absolute error in [13] for \(y_1, \, y_2\) are a multiple of \(10^{-7}\) and \(10^{-11}\), respectively, with \(n=33, m=5\) (which \(n,\, m\) indicate the numbers of nodes and of iterations). In Tables 16 and 17, the numerical results with \(m=3,\,6,\, 9\) of using the present method are exhibited for \(y_1\) and \(y_2\), respectively. From numerical findings, maximum absolute error \(y_1, \, y_2\) are a multiple of \(10^{-12}\) and \(10^{-14}\), respectively, with \(m=9\) (which \(m\) indicates Bernstein polynomial order).

Table 16 Absolute error values of \(y_1(t)\) for Example 13
Table 17 Absolute error values of \(y_2(t)\) for Example 13

Example 14

Consider the following nonlinear fourth-order boundary value problem [14]

$$\begin{aligned}&u^{(4)}(x)-e^x u''(x)+u(x)+\sin (u(x))=1+\sin (1+\sinh (x))-(e^x-2)\sinh (x)\\&u(0)=1,\quad u'(0)=1,\quad u(1)=1+\sinh (1),\quad u'(1)=\cosh (1), \end{aligned}$$

whose exact solution is \(u^*(x)=1+\sinh (x)\). This BVP has been solved in [14] by the reproducing kernel Hilbert space method which its maximum absolute error is a multiple of \(10^{-7}\). Numerical results in Table 18 show that approximate solution obtained is in good agreement with the exact solution and only a few order of Bernstein polynomial can be used to obtain a solution with a high degree of accuracy. Therefore, the present method can be applied as an accurate and reliable technique for the nonlinear BVPs.

Table 18 Absolute error values for Example 14

7 Conclusion

In this paper the operational matrices of integration, differentiation, product and dual of Bernstein polynomials basis are utilized to reduce the nonlinear boundary value problems to the solution of algebraic equations. In Bernstein polynomials of \(m\)th degree, there are \(m + 1\) \(m\)th degree polynomials which this causes to increase the efficiency and performance of the new method in comparison with methods which use of other polynomials. Comparisons between spectral method based on operational matrices of Bernstein polynomials using collocation method and modified Adomian decomposition method, Birkhoff-type interpolation method, reproducing kernel Hilbert space method, fixed point method, finite-difference Keller-box method, multilevel augmentation method and shooting method for solving the nonlinear ordinary and partial differential equations with multi-point boundary conditions are made. These comparisons enhance the use of the new method if we wish to obtain an accurate approximate solution that converges faster to the exact solution. Moreover, new presented method is also effective for solving appropriate higher order differential equations even for singular differential equations.

We have applied the proposed method to solve the exponential second-order nonlinear differential equation, fourth-order nonlinear differential equation with a product nonlinearity, fourth-order nonlinear differential equation with an exponential nonlinearity, second-order homogeneous partial differential equation, nonlinear third-order differential equation, differential equation related to a cantilever nano-electro mechanical system, differential equation related to a double cantilever nano-electro mechanical system, differential equation related to the unsteady one-dimensional gas flow in a porous medium, eighth order nonlinear differential equation, sixth order nonlinear differential equation, nonlinear stiff differential equation, singular initial value problem, nonlinear stiff differential equation, nonlinear fourth-order boundary value problem in a straightforward procedure, respectively. The obtained numerical tests demonstrate the practicality and efficiency of our new method and show that the method produces acceptable results. Independence of the new method on any parameter can be considered as a strength point of the this method. Our expository examples have demonstrated that only a low-order of Bernstein polynomial does provide an excellent approximation even for the cases of nonlinear and nonlinear singular BVPs. A clear advantage of this technique over the Adomian decomposition method is that no calculation of Adomians polynomials is needed. This method can be considered a good scale for comparison with other existing methods.