# 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?) – Mo_ 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):

• Some singularity in the conversion causes it to be invalid in the domain you are solving
• There is more than one solution to the problem, and the conversion simply leads you to pick off a different one (Note if your ODE system has uniqueness, this isn't possible)

When applying a numerical ODE solver to a system you need to have both stability and accuracy. On top of this, you would like it to run in a reasonably short amount of time.

Both stability and accuracy are achieved by choosing a time step that is small enough for single-step methods. Some multi-step methods can not achieve stability since their nature introduces additional solutions that may not go to zero. If you have two formulations of the same problem, that have the same solution, any ODE solver that is both stable and sufficiently accurate will give you the same result.

On the other hand, some formulations may have different stability and accuracy characteristics, requiring the same solver to require different time steps for different formulations of the same problem. To find out these characteristics, you will have to analyze your problem in both formulations for your solver to know which will theoretically perform better. Most solvers are analyzed on standard ode's and as such, these analysis results won't giev insight to your question.