1 Introduction

In recent years, the studies of singular initial value problems in the ordinary differential equations have attracted the attention of many mathematicians and astrophysics. One of the equations describing this type is the Lane–Emden-type equation, which describes the equilibrium density distribution in self-gravitating sphere of polytrophic isothermal gas, and has a singularity at the origin and is of fundamental importance in the field of stellar structure, radiative cooling and modelling of clusters of galaxies.

Let \(P(r)\) denote the total pressure at a distance \(r\) from the center of spherical gas cloud. The total pressure is due to the usual gas pressure and a contribution from radiation:

$$\begin{aligned} P=\frac{1}{3}\zeta T^4+\frac{RT}{\upsilon } \end{aligned}$$
(1)

where \(\xi \), \(T\), \(R\) and \(\upsilon \) are, respectively, the radiation constant, the absolute temperature, the gas constant, and the specific volume (Parand and Pirkhedri 2010). Let \(M(r)\) be the mass within a sphere of radius \(r\) and \(G\) the constant of gravitation. The equilibrium equations for the configuration are

$$\begin{aligned} \frac{{\mathrm{d}}P}{{\mathrm{d}}r}&= -\frac{GM(r)}{r^2}\end{aligned}$$
(2)
$$\begin{aligned} \frac{{\mathrm{d}}M}{{\mathrm{d}}r}&= 4\pi \rho r^2 \end{aligned}$$
(3)

where \(\rho \) is the density, at a distance \(r\) from the center of a spherical star.

Eliminating \(M\) yields:

$$\begin{aligned} \frac{1}{r^2}\frac{\mathrm{d}}{{\mathrm{d}}r} \left( {\frac{r^2}{\rho }\frac{{\mathrm{d}}P}{{\mathrm{d}}r}}\right) =-4\pi G\rho \end{aligned}$$
(4)

Pressure and density \(\rho =v^{-1}\) vary with \(r\) and \(P=K\rho ^{1+\frac{1}{m}}\) where \(K\) and \(m\) are constant. We can insert this relation into Eq. (2) for the hydrostatic equilibrium condition and from this rewrite the equation as:

$$\begin{aligned} \left( {\frac{K(m+1)}{4\pi G}\lambda ^{\frac{1}{m}-1}}\right) \frac{1}{r^2}\frac{\mathrm{d}}{{\mathrm{d}}r}\left( {r^2\frac{{\mathrm{d}}y}{{\mathrm{d}}r}}\right) =-y^m \end{aligned}$$
(5)

where \(\lambda \) representing the central density of the star and \(y\) is dimensionless quantity that are both related to \(\rho \) through the following relation:

$$\begin{aligned} \rho =\lambda y^m \end{aligned}$$
(6)

and

$$\begin{aligned}&r=ax\\&a=\left( {\frac{K(m+1)}{4\pi G}\lambda ^{\frac{1}{m}-1}}\right) ^{\frac{1}{2}} \end{aligned}$$

Inserting these relations into our previous relations we obtained the Lane–Emden equation (Parand and Pirkhedri 2010; Dehghan and Shakeri 2008)

$$\begin{aligned} \frac{1}{x^2}\frac{\mathrm{d}}{{\mathrm{d}}x}\left( {x^2\frac{{\mathrm{d}}y}{{\mathrm{d}}x}}\right) =-y^m \end{aligned}$$
(7)

and simplifying the previous equation we have

$$\begin{aligned} y^{^{\prime \prime }}+\frac{2}{x}y^{^{\prime }}+y^m=0,\quad x>0 \end{aligned}$$
(8)

with the boundary conditions:

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

In this paper, we consider the most general the Lane–Emden type equations as:

$$\begin{aligned} P_2 (t)y^{^{\prime \prime }}(t)+P_1 (t)y^{^{\prime }}(t)+f(t,y)=g(t)\, \end{aligned}$$
(10)

with initial conditions

$$\begin{aligned} y(0)=\alpha _0 ,\,\,y^{^{\prime }}(0)=\alpha _1 \, \end{aligned}$$
(11)

where \(\alpha _0 \) and \(\alpha _1 \) are constant, \(P_2 (t)=1,\,\,P_1 (t)=\frac{\alpha }{t}\), \(f(t,y)\) is a continuous real valued function and \(g(t)\in C[0,1]\). In Biles et al. (2002), the authors proved local existence of solutions and under additional assumptions, uniqueness of the solutions for the initial value problem Eq. (10). Since, Lane–Emden type equations have significant applications in many fields of scientific and technical world, a variety of forms of \(f(t,y)\) and \(g(t)\) have been investigated by many researchers. A discussion of the formulation of these models and the physical structure of the solutions can be found in the literature. For example, for \(f(t,y)=y^m\), \(g(t)=0\), Eq. (10) is the standard Lane–Emden equation that was used to model the thermal behaviour of a spherical cloud of gas acting under the mutual attraction of its molecules and subject to the classical laws of thermodynamics (Agarwala and O’Reganb 2007; Shawagfeh 1993; Davis 1962) and for \(f(t,y)=e^y\), \(g(t)=0\), Eq. (10) is the isothermal gas sphere equation, where the temperature remains constant (Agarwala and O’Reganb 2007; Shawagfeh 1993).

Several methods for the solution of Lane–Emden equations have been presented, which are sinc-collocation method (Parand and Pirkhedri 2010), the variational iteration method (Dehghan and Shakeri 2008), Hermite functions collocation method (Parand et al. 2010), the modified Homotopy analysis method (Singh et al. 2009), the variational iteration method (Yıldırım and Öziş 2009), the Adomian decomposition method (Hasan and Zhu 2009), Legendre operational matrix method (Pandey et al. 2012) and other methods (Kumar and Singh 2010; Varani and Aminataei 2010; Benko et al. 2009; Aslanov 2008; Yıldırım and Öziş 2007; Wazwaz 2001; Pandey and Kumar 2012).

Nowadays, collocation method is very useful for solving differential equations, difference equations, delay-difference equations, pantograph equations, integro-differential-difference equations and nonlinear problems such as Abel equation (Sezer 1996; Gulsu and Sezer 2005; Gülsu et al. 2010, 2011a, b, c; Daşçıoğlu and Yaslan 2011; Öztürk et al. 2011; Öztürk and Gülsu 2010). This method is based on matrix relation and matrix equation. Given the Lane–Emden equation transforms the matrix equation. Using collocation points, we obtain the system of algebraic equations. Then, solving this system, we obtain the coefficients of truncated Hermite series.

The aim of this study is to get solution as truncated Hermite series defined by

$$\begin{aligned} y_N (t)=\sum \limits _{n=0}^N {a_n H_n (t)} \end{aligned}$$
(12)

where \(H_n (t)\) denotes the Hermite polynomials, \(a_n \;(0\le n\le N)\) are unknown Hermite coefficients and \(N\) is chosen any positive integer.

2 Fundamental Relations

Let us consider the Eq. (10) and find the matrix forms of the equation. We first consider the solutions \(y_N (x)\) and its derivatives \(y_N^{(k)} (x)\) defined by a truncated Hermit series. Then, we can write the truncated Hermit series in the matrix form

$$\begin{aligned} y_N (t)=\mathbf H (t)\mathbf A \quad \text{ and }\quad y_N^{(k)} (t)=\mathbf H ^{(k)}(t)\mathbf A \quad \,k=0,1,2 \end{aligned}$$
(13)

where

$$\begin{aligned} \mathbf H (t)&= [{H_0 (t)} \, {H_1 (t)} \, \ldots \, {H_N (t)}]\\ \mathbf A&= [{a_0 } \, {a_1 } \, \ldots \, {a_N }]^\mathrm{T}. \end{aligned}$$

Then, we know that the relation between \(t^n\) and \(H_n (t)\) is

$$\begin{aligned} t^{2n}=\frac{(2n)!}{2^{2n}}\sum \limits _{i=0}^n {\frac{H_{2i} (t)}{(2i)!(n-i)!}} \end{aligned}$$
(14)

and

$$\begin{aligned} t^{2n+1}=\frac{(2n+1)!}{2^{2n+1}}\sum \limits _{i=0}^r {\frac{H_{2i+1} (t)}{(2i+1)!(n-i)!}} ,\,n=0,1,2\ldots \end{aligned}$$
(15)

By using Eqs. (1415) and taking \(n=0,1,\ldots ,N\) we find the corresponding matrix relation as follows:

$$\begin{aligned} \mathbf X ^\mathrm{T}(t)=\mathbf MH ^\mathrm{T}(t)\quad \text{ and }\quad \mathbf X (t)=\mathbf H (t)\mathbf M ^\mathrm{T} \end{aligned}$$
(16)

where

$$\begin{aligned} \mathbf X (t)=[1 \quad t \quad \ldots \quad {t^N}] \end{aligned}$$

and for even \(N\)

$$\begin{aligned} \mathbf M =\left[ {{\begin{array}{ccccc} {\frac{1!}{2^00!0!}} &{} 0 &{} 0 &{} \ldots &{} \\ 0 &{} {\frac{1!}{2!1!1!}} &{} 0 &{} \ldots &{} 0 \\ {\frac{2!}{2^2!0!1!}} &{} 0 &{} {\frac{2!}{2^22!1!}} &{} \ldots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \vdots \\ {\frac{N!}{2^N0!\big (\frac{N}{2}\big )!}} &{} 0 &{} {\frac{N!}{2^N2!\big (\frac{N}{2}-1\big )!}} &{} \ldots &{} {\frac{N!}{2^NN!0!}} \\ \end{array} }} \right] \end{aligned}$$

for odd \(N\)

$$\begin{aligned} \mathbf M =\left[ {{\begin{array}{ccccc} {\frac{0!}{2^00!0!}} &{} 0 &{} 0 &{} \ldots &{} 0 \\ 0 &{} {\frac{1!}{2^11!1!}} &{} 0 &{} \ldots &{} 0 \\ {\frac{2!}{2^20!1!}} &{} 0 &{} {\frac{2!}{2^22!1!}} &{} \ldots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \vdots \\ 0 &{} {\frac{N!}{2^N1!\big ( {\frac{N-1}{2}-1}\big )!}} &{} 0 &{} \ldots &{} {\frac{N!}{2^NN!0!}} \\ \end{array} }} \right] \end{aligned}$$

Then, by taking into account (16), we obtain

$$\begin{aligned} \mathbf H (t)=\mathbf X (t)\mathbf M ^\mathrm{T})^{-1} \end{aligned}$$
(17)

and

$$\begin{aligned} \mathbf H ^{(k)}(t)=\mathbf X ^{(k)}(t)(\mathbf M ^\mathrm{T})^{-1}\quad \,k=0,1,2 \end{aligned}$$
(18)

To obtain the matrix \(\mathbf X ^{(k)}(t)\) in terms of the matrix \(\mathbf X (t)\), we can use the following relation (Sezer 1996; Gulsu and Sezer 2005; Gülsu et al. 2010, 2011a, b, c; Daşçıoğlu and Yaslan 2011; Öztürk et al. 2011; Öztürk and Gülsu 2010)

$$\begin{aligned} \mathbf X ^1(t)\!\!&=\mathbf X (t)\mathbf B ^1\nonumber \\&\vdots \\ \mathbf X ^2(t)\!\!&=\mathbf X ^1(t)\mathbf B =\mathbf X (t)\mathbf B ^2\nonumber \end{aligned}$$
(19)

where

$$\begin{aligned} \mathbf B =\left[ \begin{array}{ccccc} 0 &{}\quad 1 &{}\quad 0 &{}\quad \ldots &{} \quad 0 \\ 0 &{} \quad 0 &{}\quad 2 &{}\quad \ldots &{}\quad 0\\ 0 &{}\quad 0 &{}\quad 0 &{}\quad \ldots &{}\quad 0 \\ 0 &{}\quad \vdots &{}\quad 0 &{}\quad \ddots &{}\quad N \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad \ldots &{}\quad 0 \\ \end{array}\right] \end{aligned}$$

Therefore, the matrix representation of the solution and its derivatives can be given by

$$\begin{aligned} y_N^{(k)} (t)=\mathbf X (t)\mathbf B ^k(\mathbf M ^\mathrm{T})^{-1}\mathbf A ,\quad k=0,1,2 \end{aligned}$$
(20)

3 Method of solution

In Eq. (10), we assume that \(f(t,y)=P_0 (t)\) that is \(f(t,y)\) is linear. For \(t=0\), \(P_1 (t)=\frac{\alpha }{t}\) has a singular point. Since \(t+\varepsilon \rightarrow t\) as \(\varepsilon \rightarrow 0\) then \(\mathop {\lim }_{\varepsilon \rightarrow 0} P_1 ^*(t+\varepsilon )=P_1 (t)\), where \(P_1 ^*(t+\varepsilon )=P_1 (t+\varepsilon )\).

We using collocation points \(t_i \) defined by

$$\begin{aligned} t_i =\frac{i}{N},\quad i=0,1,\ldots ,N \end{aligned}$$
(21)

and we get the matrix equations

$$\begin{aligned} ({P_2 (t_i )\mathbf X (t_i )\mathbf B ^2(\text{ M }^\mathrm{T})^{-1}+P_1 ^*(t_i +\varepsilon )\mathbf X (t_i )\mathbf B (\text{ M }^\mathrm{T})^{-1}+P_0 (t_i )\mathbf X (t_i )(\mathbf M ^\mathrm{T})^{-1}})\mathbf A _\varepsilon =g(t_i )\qquad \end{aligned}$$
(22)

So, the fundamental matrix equation is gained

$$\begin{aligned} ({\mathbf{P }_2 \mathbf{XB }^2(\mathbf{M }^\mathrm{T})^{-1}+\mathbf{P }_1 ^*\mathbf{XB }(\mathbf{M }^\mathrm{T})^{-1}+\mathbf{P }_0 \mathbf{X }(\mathbf{M }^\mathrm{T})^{-1}})\mathbf{A }_\varepsilon =\mathbf G \end{aligned}$$
(23)

where

$$\begin{aligned} \begin{array}{l} \mathbf P _0 =\left[ {{\begin{array}{ccccc} {P_0 (t_0 )} &{} 0 &{} 0 &{} \cdots &{} 0 \\ 0 &{} {P_0 (t_1 )} &{} 0 &{} \cdots &{} 0 \\ 0 &{} 0 &{} {P_0 (t_2 )} &{} \cdots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \vdots \\ 0 &{} 0 &{} 0 &{} \cdots &{} {P_0 (t_N )} \\ \end{array} }} \right] \quad \mathbf P _1 =\left[ {{\begin{array}{ccccc} {P_1 (t_0 +\varepsilon )} &{} 0 &{} 0 &{} \cdots &{} 0 \\ 0 &{} {P_1 (t_1 +\varepsilon )} &{} 0 &{} \cdots &{} 0 \\ 0 &{} 0 &{} {P_1 (t_2 +\varepsilon )} &{} \cdots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \vdots \\ 0 &{} 0 &{} 0 &{} \cdots &{} {P_1 (t_N +\varepsilon )} \\ \end{array} }} \right] \\ \mathbf P _2 =\left[ {{\begin{array}{ccccc} {P_2 (x_0 )} &{} 0 &{} 0 &{} \cdots &{} 0 \\ 0 &{} {P_2 (x_1 )} &{} 0 &{} \cdots &{} 0 \\ 0 &{} 0 &{} {P_2 (x_2 )} &{} \cdots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \vdots \\ 0 &{} 0 &{} 0 &{} \cdots &{} {P_2 (x_N )} \\ \end{array} }} \right] \,\,\,\quad \mathbf X =\left[ {{\begin{array}{ccccc} 1 &{} {x_0 } &{} {x_0 ^2} &{} \cdots &{} {x_0 ^N} \\ 1 &{} {x_1 } &{} {x_1 ^2} &{} \cdots &{} {x_1 ^N} \\ 1 &{} {x_2 } &{} {x_2 ^2} &{} \cdots &{} {x_2 ^N} \\ \vdots &{} \vdots &{} \vdots &{} \ddots &{} \vdots \\ 1 &{} {x_N } &{} {x_N ^2} &{} \cdots &{} {x_N ^N} \\ \end{array} }} \right] \,\,\quad \mathbf G =\left[ {{\begin{array}{c} {g(x_0 )} \\ {g(x_1 )} \\ {g(x_2 )} \\ \vdots \\ {g(x_N )} \\ \end{array} }} \right] \\ \end{array} \end{aligned}$$

Hence, the fundamental matrix Eq. (22) corresponding to Eq. (10) can be written in the form

$$\begin{aligned} \mathbf W _\varepsilon \mathbf A _\varepsilon =\mathbf G \,\text{ or }\,\,[\mathbf W _\varepsilon \mathbf{;G }],\quad \mathbf W _\varepsilon =[w_{i,j} ],\,i,j=0,1,\ldots ,N \end{aligned}$$
(24)

where

$$\begin{aligned} \mathbf W _\varepsilon =\mathbf P _2 \mathbf X \mathbf B ^2(\mathbf M ^\mathrm{T})^{-1}+\mathbf P _1 ^*\mathbf X \mathbf B (\mathbf M ^\mathrm{T})^{-1}+\mathbf P _0 \mathbf X (\mathbf M ^\mathrm{T})^{-1} \end{aligned}$$

On the other hand, the matrix form for conditions can be written as

$$\begin{aligned} y(0)&= \mathbf X (0)(\mathbf M ^\mathrm{T})^{-1}\mathbf A _\varepsilon \equiv [{u_{00} }\, \,\, {u_{01} } \,\,\, \cdots \,\,\, {u_{0N}}]=[\alpha _0 ]\nonumber \\ y^{(1)}(0)&= \mathbf X (0)\mathbf B (\mathbf D ^\mathrm{T})^{-1}\mathbf A _\varepsilon \equiv [{u_{10} } \quad {u_{11} } \quad \cdots \quad {u_{1N} }]=[\alpha _1 ] \end{aligned}$$
(25)

To obtain the solution of Eq. (10) under conditions (11), by replacing the row matrices (24) by the last 2 rows of the matrix (23), we have the new augmented matrix

$$\begin{aligned} \left[ {\tilde{\mathbf{W }}_{\varepsilon } \mathbf ; \tilde{\mathbf{F }}} \right] =\left[ {{\begin{array}{ccccccc} {w_{00} } &{}\quad {w_{01} } &{}\quad \cdots &{}\quad {w_{0N} } &{}\quad ; &{}\quad {g(t_0 )} \\ {w_{10} } &{}\quad {w_{11} } &{}\quad \cdots &{}\quad {w_{1N} } &{}\quad ; &{} {g(t_1 )} \\ \vdots &{}\quad \vdots &{}\quad \ddots &{}\quad \vdots &{}\quad \vdots &{}\quad \vdots \\ {w_{N-20} } &{}\quad {w_{N-21} } &{}\quad \cdots &{}\quad {w_{N-2N} } &{}\quad \vdots &{}\quad {g(t_{N-2} )} \\ {u_{00} } &{}\quad {u_{01} } &{}\quad \cdots &{}\quad {u_{0N} } &{}\quad ; &{}\quad {\alpha _0 } \\ {u_{10} } &{}\quad {u_{11} } &{}\quad \cdots &{}\quad {u_{1N} } &{}\quad ; &{}\quad {\alpha _1 } \\ \end{array} }} \right] \end{aligned}$$
(26)

The Eq. (25) is a system of \((N+1)\) linear algebraic equations with \((N+1)\) unknown Hermit coefficients. If \(rank\tilde{\mathbf{W }}=rank[\tilde{\mathbf{W }}; \tilde{\mathbf{F }}]=N+1\), then we can write

$$\begin{aligned} \mathbf A _\varepsilon =(\tilde{\mathbf{W }}_\varepsilon )^{-1}\tilde{\mathbf{F }} \end{aligned}$$

Thus the matrix \(\mathbf A _\varepsilon \) is uniquely determined. Also the Eq. (10) with conditions (11) has a unique solution. This solution is given by truncated Hermit series

$$\begin{aligned} y_{N,\varepsilon } (t)=T_N^*(t)A_\varepsilon \quad \text{ and } \text{ so }\,\quad y_N (t)=\mathop {\lim }\limits _{\varepsilon \rightarrow 0} y_{N,\varepsilon } (t). \end{aligned}$$

Let assume that \(f(t,y)=y^m(t)\) that is \(f(t,y)\) is nonlinear. Now, we construct the matrix form of the nonlinear term.

$$\begin{aligned} \mathbf Y ^m=\mathbf Y ^{m-1} \overline{\mathbf{Y }} \end{aligned}$$
(27)

where

$$\begin{aligned} \mathbf Y ^{m-1}(t)=\left[ {{\begin{array}{c} {y^{m-1}(t)} \\ {y^{m-1}(t)} \\ \vdots \\ {y^{m-1}(t)} \\ \end{array} }} \right] ,\quad \overline{\mathbf{Y }} (t)=\left[ {{\begin{array}{cccc} {y(t)} &{}\quad 0 &{}\quad \cdots &{}\quad 0 \\ 0 &{}\quad {y(t)} &{}\quad \cdots &{}\quad 0 \\ \vdots &{}\quad \vdots &{}\quad \ddots &{}\quad \vdots \\ 0 &{}\quad 0 &{}\quad \cdots &{}\quad {y(t)} \\ \end{array} }} \right] \end{aligned}$$

and using collocation points in Eqs. (20, 21)

$$\begin{aligned} \overline{\mathbf{Y }}=\overline{\mathbf{T }}\,\overline{\mathbf{A }} \end{aligned}$$
(28)

where

$$\begin{aligned} \overline{\mathbf{T }} =\left[ \begin{array}{cccc} {\mathbf{T }(t_i )} &{}\quad 0 &{}\quad \cdots &{}\quad 0 \\ 0 &{}\quad {\mathbf{T }(t_i )} &{}\quad \cdots &{}\quad 0 \\ \vdots &{}\quad \vdots &{}\quad \ddots &{}\quad \vdots \\ 0 &{}\quad 0 &{}\quad \cdots &{}\quad {\mathbf{T }(t_i )} \\ \end{array} \right] ,\quad \overline{\mathbf{A }} =\left[ {{\begin{array}{cccc} \mathbf A &{}\quad 0 &{}\quad \cdots &{}\quad 0 \\ 0 &{}\quad \mathbf A &{}\quad \cdots &{}\quad 0 \\ \vdots &{}\quad \vdots &{}\quad \ddots &{}\quad \vdots \\ 0 &{}\quad 0 &{}\quad \cdots &{}\quad \mathbf A \\ \end{array} }} \right] \end{aligned}$$

then, we construct the following matrix relation

$$\begin{aligned} y_N^m (t_i )=y_N^{m-1} (t_i )y(t_i )=y^{m-1}(t_i )y(t_i )=(\overline{\mathbf{T }}\,\overline{\mathbf{A }})^{m-1}\mathbf{XM }_0\mathbf A \end{aligned}$$
(29)

After we obtained the matrix form of nonlinear part, we apply the above procedure.

We can easily check the accuracy of the method. Since the truncated Hermit series (12) is an approximate solution of Eq. (10), when the solution \(y_N (t)\) and its derivatives are substituted in Eq. (10), the resulting equation must be satisfied approximately; that is (Sezer 1996; Gulsu and Sezer 2005; Gülsu et al. 2010, 2011a, b, c; Daşçıoğlu and Yaslan 2011; Öztürk et al. 2011; Öztürk and Gülsu 2010), for \(t=t_q \in [0,1],\;\;q=0,1,2,...\)

$$\begin{aligned} E(t_q )=\left| {P_2 (t_q )y^{\prime \prime }(t_q )+P_1 (t_q )y^{\prime }(t_q )+P(t_q )y-g(t_q )} \right| \cong 0 \end{aligned}$$
(30)

On the other hand, the error can be estimated by the function as

$$\begin{aligned} E_N (t)=P_2 (t)y^{\prime \prime }(t)+P_1 (t)y^{\prime }(t)+P(t)y-g(t) \end{aligned}$$
(31)

4 Illustrative Examples

In this section, several numerical examples are given to illustrate the accuracy and effectiveness properties of the method and all of them were performed on the computer using a program written in Maple 13. The absolute errors in Tables are the values of \(N_e =\left| {y(t)-y_N (t)} \right| \) at selected points.

Example 1

Let us first consider the following linear homogeneous Lane–Emden equation (Parand et al. 2010)

$$\begin{aligned} y^{\prime \prime }+\frac{8}{t}y^{\prime }+ty=t^5-t^4+44t^2-30t \end{aligned}$$
(32)

subject to initial conditions

$$\begin{aligned} y(0)=0,\,\,y^{\prime }(0)=0. \end{aligned}$$

Then, \(P_0 (t)=t\), \(P_1^*(t)=\frac{8}{t+\varepsilon }\), \(P_2 (t)=1\) and \(f(t)=t^5-t^4+44t^2-30t\).

Now, we can apply our technique described in Sect. 3 for \(N=4\) that is;

$$\begin{aligned} y_4 (t)=\sum \limits _{n=0}^4 {a_n H_n (t)} . \end{aligned}$$

Fundamental matrix relation of this equation is

$$\begin{aligned} \bigg ( {\mathbf{P }_2 \mathbf{XB }^2(\mathbf{M }^\mathrm{T})^{-1}+\mathbf{P }_1^*\mathbf{XB }^1(\mathbf{M }^\mathrm{T})^{-1}+\mathbf{P }_0 \mathbf{X }(\mathbf{M }^\mathrm{T})^{-1}}\bigg )\mathbf{A }=\mathbf{F } \end{aligned}$$
(33)

where

$$\begin{aligned} {\begin{array}{l} {\mathbf{F }=\left[ {{\begin{array}{c} 0 \\ {-4.752929} \\ {-4.031250} \\ {2.170898} \\ {14} \\ \end{array} }} \right] }\quad {\mathbf{P }_0 =\left[ {{\begin{array}{ccccc} 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad {0.25} &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad {0.50} &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad {0.75} &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad 1 \\ \end{array} }} \right] }\\ {\mathbf{P }_2 =\left[ {{\begin{array}{ccccc} 1 &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad 1 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 1 &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad 1 &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad 1 \\ \end{array} }} \right] \,\,\tilde{\mathbf{F }}=\left[ {{\begin{array}{l} 0 \\ {-4.752929} \\ {-4.031250} \\ 0 \\ 0 \\ \end{array} }} \right] } \\ {\mathbf{X }=\left[ {{\begin{array}{ccccc} 1 &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 1 &{}\quad {1/4} &{}\quad {1/16} &{}\quad {1/64} &{}\quad {1/256} \\ 1 &{}\quad {1/2} &{}\quad {1/4} &{}\quad {1/8} &{}\quad {1/16} \\ 1 &{}\quad {3/4} &{}\quad {9/16} &{}\quad {27/64} &{}\quad {81/256} \\ 1 &{}\quad 1 &{}\quad 1 &{}\quad 1 &{}\quad 1 \\ \end{array} }} \right] \quad \mathbf{P }_1^*=\left[ {{\begin{array}{ccccc} {\frac{8}{\varepsilon }} &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 0 &{} {\frac{8}{0.25+\varepsilon }} &{} 0 &{} 0 &{} 0 \\ 0 &{}\quad 0 &{}\quad {\frac{8}{0.50+\varepsilon }} &{}\quad 0 &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad {\frac{8}{0.75+\varepsilon }} &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad {\frac{8}{1+\varepsilon }} \\ \end{array} }} \right] } \\ \end{array} } \end{aligned}$$

Also, we have the matrix representation of conditions as,

$$\begin{aligned} y(0)&= \left[ 1 \quad 0 \quad {-2} \quad 0 \quad {12}\right] \mathbf A =\left[ 0 \right] \\ y^{\prime }(0)&= \left[ 0 \quad 2 \quad 0 \quad {-12} \quad 0\right] \mathbf A =\left[ 0 \right] \end{aligned}$$

We solve the new augmented matrix with conditions of Eq. (26), we obtain the approximate solution

$$\begin{aligned} y_4 (t)=t^4-t^3 \end{aligned}$$

which is the exact solution of Eq. (32).

Example 2

Consider the following linear Lane–Emden equation which is the isothermal gas spheres equation (Dehghan and Shakeri 2008; Agarwala and O’Reganb 2007; Parand et al. 2010; Wazwaz 2001; Pandey and Kumar 2012)

$$\begin{aligned} y^{\prime \prime }+\frac{2}{t}y^{\prime }-(4t^2+6)y=0 \end{aligned}$$

with \(y(0)=1\) and \(y^{\prime }(0)=0\). The exact solution of this problem is \(y(t)=\exp (t^2)\). The solution of the is obtained for\(N=10,15,20\). For numerical results, see Table 1. Moreover, we compare the numerical results with Parant (Parand et al. 2010), Wazwaz (Wazwaz 2001) and Pandey (Pandey et al. 2012; Pandey and Kumar 2012) in Table 2.

Table 1 Error analysis of Example 2 for the \(t\) value
Table 2 Compare of some methods for Example 2

Example 3

Consider the following nonlinear Lane–Emden equation which is the temperature variation of a spherical gas cloud under the mutual attraction of its molecules and subject to the laws of classical thermodynamics. It also describes the variation of density as a function of the radial distance for a polytrope. The polytropic theory of stars essentially follows out of thermodynamic considerations, that deal with the issue of energy transport, through the transfer of material between different levels of the star (Dehghan and Shakeri 2008; Davis 1962; Parand et al. 2010).

$$\begin{aligned} y^{\prime \prime }+\frac{2}{t}y^{\prime }+y^m=0 \end{aligned}$$
(34)

with \(y(0)=1\,\,y^{\prime }(0)=0\). This equation is linear for \(m=0,1\) and nonlinear otherwise. Exact solutions exist only for \(m=0,1,5\).

Case I: For \(m=0\), Eq. (34) has exact solution \(y(t)=1-\frac{t^2}{6}\). Applying the method developed in Sect. 3 for \(N=2\), we obtain the exact solution.

Case II: For \(m=1\), Eq. (34) has exact solution \(y(t)=\frac{\sin (t)}{t}\)

We solve the equation approximately, we have the approximate solutions in Table 3. Moreover, we display the approximate solutions and exact solution in Fig. 1 and errors is given in Fig. 2.

Fig. 1
figure 1

Approximate solution functions of the Example 3 for Case II

Fig. 2
figure 2

Error function of Example 3 for Case II

Fig. 3
figure 3

Plot of \(y_N (x)\) for \(N=4,5,6\) and exact solution for Case III

Table 3 Numerical result for Example 3

Case III: For \(m=5\), Eq. (34) has exact solution \(y(t)=(1+\frac{t^2}{3})^{-1/2}\). Applying the method developed in Sect. 3 with Eq. (29), we solve the nonlinear Lane–Emden equation for some \(N\). Figure 3 compare the approximate solutions and exact solution and Fig. 4 shows errors functions of the approximate solutions for various \(N\).

Fig. 4
figure 4

Plot of absolute errors at \(N=4,5,6\) for Case III

Example 4

Consider the following nonlinear Lane–Emden equation which is the isothermal gas spheres equation (Dehghan and Shakeri 2008; Davis 1962; Parand et al. 2010; Wazwaz 2001)

$$\begin{aligned} y^{\prime \prime }+\frac{2}{t}y^{\prime }+e^y=0 \end{aligned}$$

with\(y(0)=0,\,\,y^{\prime }(0)=0\). In this problem \(f(x,y)=e^y\). Using Taylor series we can write \(f(x,y)\) as

$$\begin{aligned} f(x,y)=1+y+\frac{y^2}{2}+\frac{y^3}{6}+\frac{y^4}{24}+\frac{y^5}{120}+\ldots \end{aligned}$$

We give the numerical results in Table 4 and it is obtained the numerical results by Parand et al. (2010) and Wazwaz (2001) in Table 5. We plot the approximate solutions in Fig. 5 and errors functions in Fig. 6. Moreover, the numerical results of Parand et al. (2010) and Wazwaz (2001) is plotted in Fig. 7. The numerical results is the same line in Figs. 5 and 7.

Fig. 5
figure 5

Approximate solution functions of the Example 4 for various \(N\)

Fig. 6
figure 6

Error function of Example 4 for various \(N\)

Fig. 7
figure 7

Approximate solution of the Example 4 by Parand and Wazwaz

Table 4 Error analysis of Example 4 for the \(t\) value
Table 5 Numerical values of some methods for Example 4

5 Conclusion

A method for the solution of the Lane–Emden equation has been proposed and investigated. The method was illustrated by accurately solving Lane–Emden equations. Also, efficiency of this method has been shown in the examples. In recent years, the studies of Lane–Emden equation have attracted the attention of many mathematicians and physicists. The Hermit collocation methods are used to solve the Lane–Emden equation numerically. Illustrative examples are included to demonstrate the validity and applicability of the technique and performed on the computer using a program written in Maple 13. To get the best approximating solution of the equation, we take more forms from the Hermit expansion of functions; that is, the truncation limit \(N\) must be chosen large enough. In addition, an interesting feature of this method is to find the analytical solutions if the equation has an exact solution that is a polynomial functions. Illustrative examples with the satisfactory results are used to demonstrate the application of this method. Suggested approximations make this method very attractive and contributed to the good agreement between approximate and exact values in the numerical example.