In this homework assignment, you will use your orbit program to simulate a highly elliptical orbits, and then a binary star.
you will use your orbit program to simulate a highly elliptical orbits, and then a binary star.
About how many timesteps are required to simulate this orbit reasonably accurately? Compare this to the value for a circular orbit that you determined
last week. What makes cometary orbits so much harder to simulate accurately?
together to find the accelera-tions.
x1, y1, vx1 , vy1 for the firststar
x2, y2, vx2 , vy2 for the secondstar
(a)Evolve the position variables (all four of them!) forward bydt/2
(b)Evolve the velocity variables (all four of them!) forward by dt (this is the hardpart)
(c)Evolve the position variables forward by dt/2again
Your cut-and-paste skills will come in handy here, as you will be typing multiple copies of very similar code. But be careful of editing errors when doing this!
Run your simulation, and monitor conservation of total energy to ensure that it is behaving properly. You now can’t compute energy per unit mass, since you have two masses; the total energy will be
Play around with what you can create – make things move in three dimensions, etc. Note that if two bodies get too close together, they will experience a very large force that is probably too big for your timestep to accurately simulate. Can you make a stable sun-planet-moon system?
The total momentum of a system of two stars is
This gives a center-of-mass velocity of
By calculating this value and subtracting it from each of your objects’ initial velocities, you ensure that the total center-of-mass velocity (and thus the total momentum) is zero, and your simulation won’t drift. This can be done with code like the following:
double vxc,vyc; //center-of-mass velocities vxc = (m1*vx1 + m2*vx2) / (m1+m2);
vyc = (m1*vy1 + m2*vy2) / (m1+m2); vx1 = vx1 – vxc;
vy1 = vy1 – vyc; vx2 = vx2 – vxc; vy2 = vy2 – vyc