|
|
Assignment 5 |
|
For this week, we'll be doing a simple gravitational attraction problem starting with the structures that were shown in class. Because of the nature of the program and the difficulty, the assignment will be due in two weeks. First, some background.
Forces are vectors, just like position, and velocity. This means that they have components in the x, y, and z directions. Many forces can be added just like any other vector and for many forces, gravity included, the total force on a particle is just the sum of the forces between every pair of particles.
For example: If there are 3 particles, p1, p2, and p3, then the force on p1 at any instant in time is the the force between p1 and p2 plus the force between p1 and p3.
For gravity, the force between two particles is given by the following formula (masses are in kilograms and positions are in meters):
F(p1,p2) = -G * ( m1 * m2 ) / d^2
d = sqrt ( (x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2 )
G = 6.67E-11 N m^2 kg^-2
Newton made a fantastic discovery a few hundred years ago along the lines of:
F = maWhat this means is that the acceleration experienced by a particle can be computed by dividing the force on by the particle by its mass. Having then computed the acceleration, the velocity after some period of time dt can be calculated via:
v = a * dtAnd the position can be calculated using:
x = v * dtRemember that acceleration, position, and velocity are vectors so these calculations have to be done in each dimension.
Using the particle structure that we've defined in the class, add three more vectors for velocity, acceleration, and force.
Create a list of three particles. The masses of the three particles should be set to 1E6 kg. The positions should be set to (0, 0, 0), (1, 1, 0), and (0.5, 0.866, 0). The initial velocities should be set to zero and use dt = 0.01.
Set up a loop that goes over 10 iterations. At each iteration perform the following steps:
zero out the force and acceleration for each particle.
Compute the force on each particle due to the gravitational attraction from the other two particles. Store the total value into the force member. Remember that this is a vector quantity and therefore has three components.
Compute the new position of each particle by using x = xo + v * dt in each direction (x, y, and z).
Compute the acceleration in each direction on each particle using the newly calculated force.
Update the new velocity of each particle by using v = vo + a * dt. (again, in three directions)
Print out the position, velocity, and acceleration of each particle, one line per particle.