choppu said:
So i need to integrate the equations two times?
You will definitely need to integrate N*6 scalar states, where N is the number of bodies. If you want to look at this as integrating twice, then the answer is "yes".
However, a second-order differential equation can always be reduced to a first-order differential equation. For example, Newton's second law is a second order differential equation. Ignoring the vectorial nature of things for a bit, Newton's second law for a constant-mass object subject to some external force is
\ddot x(t) = \frac{F(t)}{m}
To convert this to a first-order differential equation, construct a state vector
u that comprises the object's position
x and velocity
v:
\vec u \equiv \bmatrix x \\ v \endbmatrix
The derivative of this vector is
\frac{d}{dt}\vec u(t) = \bmatrix u_2(t) \\ F(t)/m \endbmatrix
where
u2 is just the second element (the velocity element) of the vector
u.
Bottom line: Augmenting the state with the velocity changed the initial second order differential equation to a first order differential equation.
1[/color] This technique also works for vectors as well as scalars. Instead of adding 1 element to the state, you simply add
n elements to the state -- the time derivatives of each of the
n elements of the vector. This is exactly what you are going to need to do if you want to use a Runge-Kutta method to propagate the state of the system.
To answer the question posed in your last post: If you envision the position & velocity vectors for all N bodies in your simulation as forming one big vector with N*6 elements, you will only have to integrate once.
2[/color]There is a problem with this augmented state approach. Suppose you use this approach and you use Euler's method to perform the integration. Your simulated solar system won't hang together for long. This basic use of Euler's method fails to conserve energy. There is a simple solution variously called symplectic Euler, Euler–Cromer, semi-implicit Euler (and others). Calculate all of the accelerations (see the second footnote). Then for each body, integrate the velocity vector using the calculated acceleration for that body and then integrate the position vector using the integrated velocity.
3[/color] This simple change makes a huge difference. Energy is conserved and orbits are bounded (more-or-less).
4[/color]
==============
1[/color] This technique works for any order differential equation. For example, see
http://en.wikipedia.org/wiki/Ordinary_differential_equation#Reduction_to_a_first_order_system.
2[/color] One advantage of this "big honkin state vector" approach is that it ensures that the accelerations are time synchronous. If you integrate each body separately you will need to ensure that you calculate all of the accelerations before you propagate any of the positions.
3[/color] Using the Euler method to integrate the augmented state essentially does this in reverse order: It integrates the position vectors using the current velocity vectors and then integrates the velocity vectors (but using the accelerations calculated from the position vectors prior to the update).
4[/color] If you want to know more about these kinds of techniques, google the terms "symplectic integrator" and "geometric integrator". Just as basic Euler method is a starting point for numerical integration in general, the symplectic Euler method is a starting point for integration methods that conserve some quantity of interest (e.g., energy) in some dynamic system.