@mmcdara So after going through all your files which explains every step in detail. So an overview of the approach as i understand taken in your file:
- The Emden equation was solved numerically using dsolve to get EmdenN.
- This was then used in the Lane-Emden equation ode2 to define the source term.
- An attempt was made to solve the Lane-Emden equation numerically using dsolve, but it failed due to a singularity at the initial point.
- To get around this, the initial point was shifted to ε > 0 using a parameter.
- However, there were still issues matching the numerical solution LaneEmdenN to the exact solution LaneEmdenE at ε and π.
- To improve the match, the initial conditions were tuned by defining a cost function Control that measures the error between LaneEmdenN and LaneEmdenE at π.
- Control was minimized over the initial conditions to find optimal values that provide a close match to LaneEmdenE.
- The minimized initial conditions were then used in dsolve to get an improved numerical solution LaneEmdenN_opt.
- LaneEmdenN_opt was shown to match LaneEmdenE to high precision, solving the original problem.
So in summary, the key steps were:
1) Shift initial point to avoid singularity
2) Tune initial conditions to match known solution behavior
3) Minimize error between numerical and exact solutions
This allows dsolve to get an accurate numerical solution without needing the exact analytic form. The same general approach could be applied to other singular ODEs.
So, I want to know in general if I dont have access to Exact solution i.e EmdenE and as a result to LaneEmdenE which are used in defining ic2E to get the high accuracy, in cases for example n=3, whats the best strategy?. Should i evaluate at ApproximateXi__1 where Xi__1 is Pi when n=1?. But have limited accuracy since ic2E is not be available. Putting it in a simple way imagine a blackbox function that takes n ,alpha, epsilon and outputs D(gamma)(xi__1) .
And at last I think these tricks needs to be applied when we have singular ODEs. So, in case where its not the case a straight forward approach will work that doesn't require epsilons.right?
I really appreciate the time and effort you have put in your answer. I learned several new things from your file. Thanks again!