Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
To review the discussion in class: For an orbit in the x-y plane, you have four dynamical variables x, y, vx, and vy. The four differential equations that govern them arewhere M is the mass of the Sun.
(a)Doesyour planet stay at a fixed distance from the origin?
(b)Doesyour planet complete an orbit in one year?
(c)Does your planet’s orbit conserveenergy?
Remember, you will see some deviation from these ideals because of “finite timestep error”. That’s okay, as long as those errors get small as dt → 0.
I’ll let you test these things in any way you want.
The total energy per unit mass (“specific orbital energy”) is given by the sum of the potential and kinetic energy
1It turns out there is some history here. In regions of very strong gravity, Einstein’s general relativity modifies the force from gravity in a similar way. The orbit of Mercury is close enough to the Sun that GR causes its orbit to precess about one percent of one degree every century; this was known to astronomers and unexplained at the time of Einstein. Einstein was aware of this, and concluded his paper introducing GR by pointing out that his correction to the law of gravity explains exactly the anomaly in the precession of Mercury’s orbit.
215 problem! If you’re not sure how to go about this, discuss with other students, but tell me how this goes on your report.)
–Thephysics (“planet disappears”): print out everything your algorithm is doing, and examine the very first step in (You can see output one page at a time with ./myprogram | less.
–Elliptical orbits: is your total energy positive ornegative?
Animation:
–You can make your planet leave behind a “trail” so you can visualize its orbit with the ct3 animation command. Its syntax is ct3 〈trail index〉〈x〉〈y〉〈z〉〈radius〉,where:
∗ 〈trail index〉 controls which trail you are adding to in this case you only want to leave behind one trail, so just set this to 0
∗ 〈(x,y,z)〉 is the location to draw the object. Since you are simulating orbits in the xy-plane, just set z to zero.
∗ 〈r〉 is the radius of the ball to draw.
–Sincethe Sun doesn’t move, you can draw it at the origin with the c3
–If your simulation runs too fast, reduce the timestep; if it runs too slowly, you candraw only one animation frame every 10, 100, timesteps. To do this you might write something like:
int steps=0, stepsperframe=10; ... for (loop over time...) { steps++; // note that this means the same as "steps=steps+1" if (steps stepsperframe) { <do anim things> } <do physics update (Euler-Cromer-Aspel, leapfrog, etc.)> }printf(“T 0.9 -0.9\n”);
printf(“Energy (U + V = E): e + e = e\n”,potential,kinetic,potential+kinetic);
(Notice that this is a two-line anim command: the first line (T 0.9 -0.9) instructs the computer to print some text at a specified point in the window, in this case near the top left. The second line contains the text to be printed.) Remember, the more information you have about what your code is doing, the more physics you can learn from it, and the easier it will be to fix bugs.