Hi!

I have done a small galaxysimulator, but things go horribly wrong quite fast in the simulations. I will try to describe first how it works and then the problem I get.

What it does is that it puts a number of stars in a cubic space at random positions inside that volume. Then it lets the stars interact and move according to te gravitational rules. (I will talk more about this later.)

First the stars fall in together, some stars here and there get thrown out quite fast. Stars start to rotate in random paterns around eachother and at first it looks something like a globular cluster. But when the stars have moved past the center of mass the first time and are heading out again, they have such velocity most of them just get thrown out and the galaxy gets ripped apart.

The simulator have no "speed of light" at this point, so gravity is instant.

What I want to know is if I may have done something wrong in my calculations maybe?

Each step in the simulator is one time step, so when velocity v=v0+at that means that in my simulation I calculate the new velocity each step and theirfor I get v=v0+a.

Since my simulator uses 3 coordinate system i calculate the distance in 3 coordinates at first.

distance(x, y, z) = Star1.position(x,y,z)-Star1.position(x,y,z)

To get the acctual distance i use distNorm = sqrt(x^2+y^2+z^2)

When I have done that I get the acceleration in each direction by taking acc(x,y,z) = (G*M*distance(x,y,z))/(distNorm^3)

Then I have done that I take v(x,y,z) + acc(x,y,z) to calculate the new velocity.

Anyone that can tell me if I have done some misscalculations or just thought wrong somewhere?

Or could it be that there are so fiew stars so that it isnt possible for them to hold on to eachother?

Any comments are welcome.

Thanks!

// Cyoor