**4. Results and discussion**

In this section, we discuss and present the results obtained using the proposed algorithm. We used the six examples in the previous section. The results were generated using MATLAB 2013. To validate the accuracy, computational time and general performance of the method, we computed relative errors and computational time of each of the numerical examples. The level of accuracy of the algorithm at a particular level is determined by the relative error *Rk* defined by

$$R\_k = \frac{\left| \mathbf{y}\_s(\mathbf{x}\_k) - \mathbf{y}\_a(\mathbf{x}\_k) \right|}{\left| \mathbf{y}\_s(\mathbf{x}\_k) \right|}, \quad 0 \le k \le N,\tag{40}$$

where *N* is the number of grid points, *ya*(*xk* ) is the approximate solution and *ye*(*xk* ) is the exact solution at the grid point *xk*. The graphs were all generated using *N* = 4. For each numerical experiment, we present the relative error and the corresponding approximate solution for *N* = 4 and *N* = 6 in a tabular form. The central processing unit computational time is displayed. Graphs showing an excellent agreement between the analytical and approximate solutions are presented for each numerical experiment. These graphs validate the accuracy of the method. Error graphs showing the distribution of the relative errors are also presented. These error graphs are in excellent agreement with the results presented in the tables for all the numerical experiments used in this chapter.


**Table 1.** Analytical, approximate solutions and relative errors for Example 1.

**Table 1** shows the exact, approximate solution and the relative error for Eq. (30). For *N* = 4, the multi-domain spectral relaxation method gives a relative error of approximately 10−12 and for *N* = 6, the relative error is on average 10−13. Increasing the number of grid points results in a more accurate solution. The results obtained from the multi-domain spectral relaxation method are remarkable since few grid points give accurate results in a large domain. Using a few grid points ensures that the numerical method converges within few seconds.

**Figure 1.** Error graph.

1/2 <sup>2</sup>

In this section, we discuss and present the results obtained using the proposed algorithm. We used the six examples in the previous section. The results were generated using MATLAB 2013. To validate the accuracy, computational time and general performance of the method, we computed relative errors and computational time of each of the numerical examples. The level of accuracy of the algorithm at a particular level is determined by the relative error *Rk* defined

() () <sup>=</sup> ,0 , ( )

where *N* is the number of grid points, *ya*(*xk* ) is the approximate solution and *ye*(*xk* ) is the exact solution at the grid point *xk*. The graphs were all generated using *N* = 4. For each numerical experiment, we present the relative error and the corresponding approximate solution for *N* = 4 and *N* = 6 in a tabular form. The central processing unit computational time is displayed. Graphs showing an excellent agreement between the analytical and approximate solutions are presented for each numerical experiment. These graphs validate the accuracy of the method. Error graphs showing the distribution of the relative errors are also presented. These error graphs are in excellent agreement with the results presented in

**N = 4 N = 6** *x* **Exact Approximate Relative error Approximate Relative error** 0.2 1.060313 1.060313 1.884728e−14 1.060313 4.251109e−014 0.4 1.140018 1.140018 3.505912e−14 1.140018 6.505415e−014 0.6 1.371416 1.371416 7.852585e−14 1.371416 1.066980e−013 0.8 1.787189 1.787189 1.413886e−13 1.787189 1.474757e−013 1.0 2.522988 2.522988 2.355112e−13 2.522988 1.864022e−013 1.2 3.858367 3.858367 3.776361e−13 3.858367 2.234047e−013 1.4 6.391979 6.391979 5.987445e−13 6.391979 2.591455e−013 1.6 11.471251 11.471251 9.227679e−13 11.471251 2.937560e−013 1.8 22.301278 22.301278 1.396995e−12 22.301278 3.316738e−013 2.0 46.966942 46.966942 2.066546e−12 46.966942 3.633883e−013


*yx yx <sup>R</sup> k N*

*ek ak*

*e k*

*y x*

*k*

the tables for all the numerical experiments used in this chapter.

CPU Time (sec) 0.659414 0.629082 0.659414

**Table 1.** Analytical, approximate solutions and relative errors for Example 1.

 æ ö ç ÷ + è ø

(39)

( )= 1 . <sup>3</sup> *<sup>x</sup> y x*

**4. Results and discussion**

152 Numerical Simulation - From Brain Imaging to Turbulent Flows

by

**Figure 1** shows the relative error displayed in **Table 1** for *N* = 4. The results in **Figure 1** are in excellent agreement with those in **Table 1**. **Figure 2** shows the analytical and approximate solutions. Since the approximate solution is superimposed on the exact solutions, this implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . **Table 1** and **Figures 1** and **2** validate the accuracy and computational efficiency of the multi-domain pseudospectral relaxation method for Eq. (30).

**Figure 2.** Comparison of analytical and approximate solutions for Example 1.

The results obtained from approximating the solution to Eq. (31) using the multi-domain pseudospectral relaxation method are shown in **Table 1** and **Figures 3** and **4**. In **Table 2**, we

display the exact solution, approximate solution and the relative error of Eq. (31) in Example 2. For *N* = 4, the multi-domain spectral relaxation method gives a relative error of approxi‐ mately 10−11. For *N* = 4 the relative error is approximately 10−13. We observe that increasing the number of grid points decreases the relative error. The multi-domain pseudospectral relaxa‐ tion method uses a few grid points to achieve accurate results in the domain *x* ∈ 0,20 . A maximum of *N* = 6 grid points ensured that the numerical method converged to an error of 10−13 within a fraction of a second.

**Figure 3.** Error graph.

**Figure 4.** Comparison of analytical and approximate solutions for Example 2.

**Figure 3** shows the relative error displayed in **Table 2** for *N* = 4. The results in **Figure 3** are in excellent agreement with those in **Table 2**. **Figure 4** shows the analytical and approximate solutions of Eq. (31). The approximate solution superimposed on the exact solutions shows that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,20 . The match between the exact and approximate solutions in **Table 2** and **Figures 3** and **4** validates the accuracy and computational efficiency of the multi-domain pseudospectral relaxation method for Eq. (31).

A Multi-Domain Spectral Collocation Approach for Solving Lane-Emden Type Equations http://dx.doi.org/10.5772/63016 155


**Table 2.** Analytical, approximate solutions and relative errors for Example 2.

display the exact solution, approximate solution and the relative error of Eq. (31) in Example 2. For *N* = 4, the multi-domain spectral relaxation method gives a relative error of approxi‐ mately 10−11. For *N* = 4 the relative error is approximately 10−13. We observe that increasing the number of grid points decreases the relative error. The multi-domain pseudospectral relaxa‐ tion method uses a few grid points to achieve accurate results in the domain *x* ∈ 0,20 . A maximum of *N* = 6 grid points ensured that the numerical method converged to an error of

10−13 within a fraction of a second.

154 Numerical Simulation - From Brain Imaging to Turbulent Flows

**Figure 3.** Error graph.

**Figure 4.** Comparison of analytical and approximate solutions for Example 2.

pseudospectral relaxation method for Eq. (31).

**Figure 3** shows the relative error displayed in **Table 2** for *N* = 4. The results in **Figure 3** are in excellent agreement with those in **Table 2**. **Figure 4** shows the analytical and approximate solutions of Eq. (31). The approximate solution superimposed on the exact solutions shows that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,20 . The match between the exact and approximate solutions in **Table 2** and **Figures 3** and **4** validates the accuracy and computational efficiency of the multi-domain The results obtained from approximating the solution to Eq. (32) are given in **Table 3** and **Figures 5** and **6**. **Table 3** shows the exact solution, the approximate solution and the relative error of Eq. (32). For *N* = 4, the multi-domain spectral relaxation method gives a relative error of approximately 10−12, while for *N* = 6, the relative error is approximately 10−13. We observe that increasing the number of grid points decreases the relative error and hence increases the accuracy of the method. This pseudospectral method uses a few grid points to achieve accurate results in the domain *x* ∈ 0,2 . *N* = 6 grid points ensured that the numerical method converged to an error of 10−13 within few seconds.


**Table 3.** Analytical, approximate solutions and relative errors for Example 3.

**Figure 5.** Error graph.

**Figure 6.** A comparison of analytical and approximate solutions in Example 3.

The relative error shown in **Table 3** is displayed in **Figure 5**. The results in **Figure 5** are in excellent agreement with those in **Table 3**. **Figure 6** shows the analytical and approximate solutions of Eq. (32). The approximate solution being superimposed on the exact solutions implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . The match between the exact and approximate solutions in **Table 3** and **Figures 5** and **6** validates the accuracy and computational efficiency of the multidomain pseudospectral relaxation method for Eq. (32).

The results obtained from approximating the solution to Eq. (33) are given in **Table 4** and **Figures 7** and **8**. **Table 4** shows the exact solution, the approximate solution and the relative error of Eq. (33). For *N* = 4, the multi-domain spectral relaxation method gives a relative error of approximately 10−13. For *N* = 6, the relative error is also approximately 10−13. Increasing the number of grid points decreases the relative error. Thus, a maximum of *N* = 6 grid points ensures convergence of the method. *N* = 6 grid points ensured that the numerical method converged to an error of 10−13 in a fraction of seconds.

A Multi-Domain Spectral Collocation Approach for Solving Lane-Emden Type Equations http://dx.doi.org/10.5772/63016 157


**Table 4.** Analytical, approximate solutions and relative errors for Example 4.

**Figure 7.** Error graph.

**Figure 5.** Error graph.

156 Numerical Simulation - From Brain Imaging to Turbulent Flows

**Figure 6.** A comparison of analytical and approximate solutions in Example 3.

domain pseudospectral relaxation method for Eq. (32).

converged to an error of 10−13 in a fraction of seconds.

The relative error shown in **Table 3** is displayed in **Figure 5**. The results in **Figure 5** are in excellent agreement with those in **Table 3**. **Figure 6** shows the analytical and approximate solutions of Eq. (32). The approximate solution being superimposed on the exact solutions implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . The match between the exact and approximate solutions in **Table 3** and **Figures 5** and **6** validates the accuracy and computational efficiency of the multi-

The results obtained from approximating the solution to Eq. (33) are given in **Table 4** and **Figures 7** and **8**. **Table 4** shows the exact solution, the approximate solution and the relative error of Eq. (33). For *N* = 4, the multi-domain spectral relaxation method gives a relative error of approximately 10−13. For *N* = 6, the relative error is also approximately 10−13. Increasing the number of grid points decreases the relative error. Thus, a maximum of *N* = 6 grid points ensures convergence of the method. *N* = 6 grid points ensured that the numerical method

**Figure 8.** A comparison of analytical and approximate solutions in Example 4.

**Figure 7** shows the relative error displayed in **Table 4** for *N* = 4. The results in **Figure 7** are in excellent agreement with those in **Table 4**. **Figure 8** shows the analytical and approximate solutions. Since the approximate solution is superimposed on the exact solutions, this implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . **Table 4** and **Figures 7** and **8** validate the accuracy and computational efficiency of the multi-domain pseudospectral relaxation method for Eq. (33).

The results obtained from approximating the solution to Eq. (34) are given in **Table 5** and **Figures 9** and **10**. **Table 5** shows the exact solution, the approximate solution and the relative error of Eq. (34). The multi-domain pseudospectral relaxation method gives a relative error of approximately 10−14. For *N* = 6, the relative error is approximately 10−14. Increasing the number of grid points decreases the relative error and thus implying that the numerical method converged to the exact solution. The pseudospectral collocation method uses a few grid points to achieve accurate results in the domain *x* ∈ 0,2 . The numerical method converged to an error of 10−14 in a fraction of a second.


**Table 5.** Analytical, approximate solutions and relative errors for Example 5.

**Figure 9** shows the relative error displayed in **Table 5** for *N* = 4. The results in **Figure 9** are in excellent agreement with those in **Table 5**. **Figure 10** shows the analytical and approximate solutions. Since the approximate solution is superimposed on the exact solutions, this implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . **Table 5** and **Figures 9** and **10** validate the accuracy and computational efficiency of the multi-domain pseudospectral relaxation method for Eq. (34).

**Figure 9.** Error graph.

**Figure 7** shows the relative error displayed in **Table 4** for *N* = 4. The results in **Figure 7** are in excellent agreement with those in **Table 4**. **Figure 8** shows the analytical and approximate solutions. Since the approximate solution is superimposed on the exact solutions, this implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . **Table 4** and **Figures 7** and **8** validate the accuracy and computational

The results obtained from approximating the solution to Eq. (34) are given in **Table 5** and **Figures 9** and **10**. **Table 5** shows the exact solution, the approximate solution and the relative error of Eq. (34). The multi-domain pseudospectral relaxation method gives a relative error of approximately 10−14. For *N* = 6, the relative error is approximately 10−14. Increasing the number of grid points decreases the relative error and thus implying that the numerical method converged to the exact solution. The pseudospectral collocation method uses a few grid points to achieve accurate results in the domain *x* ∈ 0,2 . The numerical method converged to an error

**N = 4 N = 6** *x* **Exact Approximate Relative error Approximate Relative error** 0.2 0.026244 0.026244 4.759186e−015 0.026244 1.692155e−014 0.4 0.131044 0.131044 1.397903e−014 0.131044 3.473577e−014 0.6 0.315844 0.315844 2.495721e−014 0.315844 5.518706e−014 0.8 0.580644 0.580644 3.537301e−014 0.580644 6.864276e−014 1.0 0.925444 0.925444 4.138845e−014 0.925444 8.445643e−014 1.2 1.350244 1.350244 3.880967e−014 1.350244 9.981979e−014 1.4 1.855044 1.855044 4.093663e−014 1.855044 1.098825e−013 1.6 2.439844 2.439844 3.749517e−014 2.439844 8.700337e−014 1.8 3.104644 3.104644 2.445989e−014 3.104644 4.706026e−014 2.0 3.849444 3.849444 4.614580e−016 3.849444 6.575777e−015

efficiency of the multi-domain pseudospectral relaxation method for Eq. (33).

CPU Time (sec) 0.705910 0.638383 0.705910

efficiency of the multi-domain pseudospectral relaxation method for Eq. (34).

**Figure 9** shows the relative error displayed in **Table 5** for *N* = 4. The results in **Figure 9** are in excellent agreement with those in **Table 5**. **Figure 10** shows the analytical and approximate solutions. Since the approximate solution is superimposed on the exact solutions, this implies that the multi-domain pseudospectral relaxation method converged to the exact solution over the domain *x* ∈ 0,2 . **Table 5** and **Figures 9** and **10** validate the accuracy and computational

**Table 5.** Analytical, approximate solutions and relative errors for Example 5.

of 10−14 in a fraction of a second.

158 Numerical Simulation - From Brain Imaging to Turbulent Flows

**Figure 10.** A comparison of analytical and approximate solutions in Example 5.

The results obtained from approximating the solution to Eq. (38) are given in **Table 6** and **Figures 11**, **12** and **13**. **Table 6** shows values obtained for the exact and approximate solution together with the respective relative error values of Eq. (38). For *N* = 4 the multi-domain pseudospectral collocation method gives a relative error of approximately 10<sup>−</sup>11 and 10−13 for *N* = 6. An increase in the number of grid points results in a decrease in the relative error. This implies that the numerical method converges to the exact solution of Eq. (38). The multidomain pseudospectral relaxation method used a few grid points to achieve accurate results in the domain *x* ∈ 0,20 . *N* = 6 grid points ensured that the numerical method converged to an error of 10−13 within a few seconds as shown in **Table 6**.


**Table 6.** Analytical, approximate solutions and relative errors for Example 6.

**Figure 11** shows the plot for different values of *m*. The results are in good agreement with those obtained by [25, 26]. **Figure 12** displays the relative error graph of Eq. (38). The results in **Figure 12** are in excellent agreement with those obtained in **Table 6**. The comparison between the exact solution and approximate solution of Eq. (38) is shown in **Figure 13**. The superimposition of the approximate solution on the exact solution implies that the multi-domain pseudospec‐ tral relaxation method converged to the exact solution over the domain *x* ∈ 0,20 . **Table 6** and **Figures 11**, **12** and **13** give a validation of the accuracy and computational efficiency of the multi-domain pseudospectral relaxation method for Eq. (38).

**Figure 11.** Plot showing solutions to Eq. (35) for some values of *m*.

A Multi-Domain Spectral Collocation Approach for Solving Lane-Emden Type Equations http://dx.doi.org/10.5772/63016 161

**Figure 12.** Error graph.

**N = 4 N = 6** *x* **Exact Approximate Relative error Approximate Relative error** 0.650926 0.650926 1.991857e−011 0.650926 3.189482e−014 0.395693 0.395693 2.135316e−011 0.395693 3.745701e−014 0.276499 0.276499 6.204217e−012 0.276499 5.842239e−014 0.211100 0.211100 8.877991e−012 0.211100 1.519920e−013 0.170333 0.170333 2.323778e−011 0.170333 2.328536e−013 0.142624 0.142624 3.707619e−011 0.142624 3.096185e−013 0.122609 0.122609 5.055364e−011 0.122609 4.021536e−013 0.107492 0.107492 6.378059e−011 0.107492 4.983484e−013 0.095677 0.095607 7.683911e−011 0.095677 5.994828e−013 0.087057 0.087057 8.847457e−011 0.087057 6.926360e−013

CPU Time (sec) 1.199892 1.046417 1.199892

**Figure 11** shows the plot for different values of *m*. The results are in good agreement with those obtained by [25, 26]. **Figure 12** displays the relative error graph of Eq. (38). The results in **Figure 12** are in excellent agreement with those obtained in **Table 6**. The comparison between the exact solution and approximate solution of Eq. (38) is shown in **Figure 13**. The superimposition of the approximate solution on the exact solution implies that the multi-domain pseudospec‐ tral relaxation method converged to the exact solution over the domain *x* ∈ 0,20 . **Table 6** and **Figures 11**, **12** and **13** give a validation of the accuracy and computational efficiency of the

**Table 6.** Analytical, approximate solutions and relative errors for Example 6.

160 Numerical Simulation - From Brain Imaging to Turbulent Flows

multi-domain pseudospectral relaxation method for Eq. (38).

**Figure 11.** Plot showing solutions to Eq. (35) for some values of *m*.

**Figure 13.** A comparison of analytical and approximate solutions in Example 6.

### **5. Conclusion**

In this work, we presented a multi-domain spectral collocation method for solving Lane-Emden equations. This numerical method was used to solve six Lane-Emden equations. The results obtained were remarkable in the sense that using few grid points, we were able to achieve accurate results. We were able to compute the results using minimal computational time. The approximate solutions were in excellent agreement with the exact solutions in all the numerical experiments. We presented error graphs, approximate and exact solution graphs to show accuracy of the method. Tables showing relative errors were also generated to show accuracy and computational efficiency of the numerical method presented.

This approach is useful for solving other nonlinear, singular initial value problems. This approach is an alternative to the already existing list of numerical methods that can be used to solve such equations. This numerical approach can be extended to solve time-dependent Lane-Emden equations and other singular value type of equations.
