# Best form for a system of ODEs to solve with Runge_kutta

Recently when I was solving a system of ODEs using runge-Kutta method , I got much different results when I transformed the variables from spherical coordinates ($r$ and $\theta$ ) to cylindrical coordinates($\rho$ and $z$) and solved it again.

(no need to mention that

$cos(\theta)=\frac{z}{\sqrt{z^2+\rho^2}}$

$r=\sqrt{z^2+\rho^2}$ )

Only the results obtained using second system (in cylindrical_ which only contained polynomials of variables and didn't have fractions of variables_) were in agreement with published results.

Now, I wonder if there is a simple rule to determine the best form of a system to solve using numerical algorithms such as runge_kutta.(for example , something like :division of variables is better to be avoided) (or maybe this disagreement was a mistake somewhere in my calculations? (i.e. such a difference in results is impossible))

I would identify two main concerns when choosing a basis:

1. "smooth" physical trajectories should be smooth in the basis (e.g., well-approximated by a polynomial)

2. the basis should be well-conditioned

When using either spherical or cylindrical coordinates, a path going over the pole will experience a jump of $\pi$ in the angle $\phi$. If such trajectories are possible in your simulation, I would recommend using a normal cartesian basis $(x,y,z)$. This is also nice for uniqueness. I assume you don't naively project stages back into $\phi \in [0,2\pi)$, otherwise you would have problems for equatorial orbitals.

A constant-velocity trajectory passing through the origin in the $z$ direction is linear in the cylindrical basis, but is discontinuous (jumping from $\theta=\pi$ to $\theta=0$) in the spherical basis. Perhaps your simulation has trajectories similar to this?

• Yes. I noticed before that there are jumps in $\theta$ , but didn't noticed their magnitudes .Now I checked it and saw that these jumps are exactly equal to $\pi$. Is this responsible for the error? ( $\theta$ must be continuous?) – Mostafa Apr 25 '13 at 21:01
• Yes. Runge-Kutta methods build a piecewise polynomial approximation of the trajectory. If your trajectory is discontinuous, that approximation will be at most first order accurate, and may also have oscillations (see Runge's phenomenon). – Jed Brown Apr 25 '13 at 21:33

If you start with one mathematical system, and through coordinate conversion convert it to another system, then solve it, you will get the same result. If you aren't there are three possibilities (that I can think of):