This question follows another one that I have already asked.

My intention was to use a classical Runge-Kutta 45 method to solve ODEs of my system. However, I have seen recommendations for using symplectic integrators, because they do a better job at conserving the total energy of the system. Again, my system is : $$ \ddot x = - \frac A{||x||^3} * x $$

So my question is :
How do I know if a symplectic integrator is a better choice for my system. And either way, what are the downsides of using symplectic integrators over, say, RK45 ?

  • $\begingroup$ This question isn't really on-topic here; it's more of a programming question, and I encourage you instead to write your code, compile it, debug it, and run it. Anyway, to answer your question: yes, you can calculate intermediate expressions in the right-hand side function (here, my_system). You probably want to declare A, mag_x, and mag_x_cub inside the function rather than outside to limit their scope. I also got the impression from your original question that $A$ was supposed to be a matrix instead of a scalar. $\endgroup$ – Geoff Oxberry Nov 19 '14 at 3:54
  • $\begingroup$ This question appears to be off-topic because it is more about programming syntax than computational science and numerical methods. $\endgroup$ – Geoff Oxberry Nov 19 '14 at 3:55
  • $\begingroup$ @GeoffOxberry - A is a scalar constant indeed. I apologize if the question is off-topic. It truly is more a programming question than purely theoretical. But since the subject ( numerical analysis ) is so specific, I thought no other site is better suited than this one. $\endgroup$ – James C Nov 19 '14 at 3:57
  • 2
    $\begingroup$ @GeoffOxberry - I have edited my question in attempt to make it suitable for this SE site. $\endgroup$ – James C Nov 19 '14 at 4:09
  • 1
    $\begingroup$ Your system is Hamiltonian (looks like Kepler's central force problem). You might start by measuring the change in energy of your system over your integration period. Then don't just use the default tolerances. This will at least give you a baseline and possibly avoid "premature optimization" if the results are good enough for your application. $\endgroup$ – horchler Nov 19 '14 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.