Why does Mercury's potential energy oscillate in circular orbit simulation?

24 replies · 6K views · last reply
Jozefina Gramatikova
Messages
62
Reaction score
9

Homework Statement


I have a project to make the Solar system on Python, which I have done, but they also require from us to calculate the total energy of the system. We don't have to make the orbits of the planets elliptical, they should be circular and I believe I made them like that. Since the orbits are circular I think the potential and kinetic energy of the planets shouldn't change. However, when I plotted both energies I noticed Mercury's potential energy oscillates. *Please tell me if Mercury's potential energy should oscillate having in mind that its orbit should be circular. Thanks*

Matplotlib plot titled Trajectory of planets, with x-position in metres against y-position in metres on axes scaled by 1e12; several small curved orbit traces cluster near the origin, and a legend lists trajectories for nine bodies.

Line plot titled Kinetic energy as a function of time, with a y-axis from 0 to 1.6e35 and x-axis Time up to 1.0e7, showing nearly flat horizontal lines for Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune in a legend.


Homework Equations


Two Euler-style update equations as plain text: v_(n+1) ≈ v_n + a_n Δt and x_(n+1) ≈ x_n + v_n Δt, with superscript-style stars marking the variables.
Equation for gravitational acceleration: vector g-dot equals negative GM over R squared times the unit radial vector r-hat.

Potential energy:
Gravitational potential energy formula written as V = -GMm/R on a yellow background.
where M is the mass of the Sun and m is the mass of the planet we want to calculate the potential energy of

The Attempt at a Solution


Line plot titled Potential energy as a function of time, with the y-axis labelled Potential energy in units of 1e42 from 0 to -6, and the x-axis Time in units of 1e7. Most planet lines are nearly flat, but the Mercury line dips and rises in a large oscillation, reaching a minimum near -5.7e42 around time 7.5e6.

This is a piece of my code where the problem might be (if there is a problem)
Screenshot of a Python function named updateaccel that loops over bodies, computes the separation vector r and its norm modr, adds gravitational acceleration and accumulates body.Ep as potential energy.
 
Attachments
  • Two Euler-style update equations as plain text: v_(n+1) ≈ v_n + a_n Δt and x_(n+1) ≈ x_n + v_n Δt, with superscript-style stars marking the variables.
    upload_2018-12-15_20-27-32.png
    990 bytes · Views: 1,124
  • Gravitational potential energy formula written as V = -GMm/R on a yellow background.
    upload_2018-12-15_20-28-3.png
    10.7 KB · Views: 1,072
  • Equation for gravitational acceleration: vector g-dot equals negative GM over R squared times the unit radial vector r-hat.
    upload_2018-12-15_20-30-19.png
    563 bytes · Views: 1,088
  • Screenshot of a Python function named updateaccel that loops over bodies, computes the separation vector r and its norm modr, adds gravitational acceleration and accumulates body.Ep as potential energy.
    upload_2018-12-15_20-34-30.png
    13.3 KB · Views: 1,179
  • Matplotlib plot titled Trajectory of planets, with x-position in metres against y-position in metres on axes scaled by 1e12; several small curved orbit traces cluster near the origin, and a legend lists trajectories for nine bodies.
    48388735_267718147436379_3590436185207472128_n.jpg?_nc_cat=103&_nc_ht=scontent-lhr3-1.jpg
    22.5 KB · Views: 1,341
  • Line plot titled Kinetic energy as a function of time, with a y-axis from 0 to 1.6e35 and x-axis Time up to 1.0e7, showing nearly flat horizontal lines for Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune in a legend.
    48363578_370605647078369_8129958863207137280_n.jpg?_nc_cat=104&_nc_ht=scontent-lhr3-1.jpg
    26.7 KB · Views: 1,168
  • Line plot titled Potential energy as a function of time, with the y-axis labelled Potential energy in units of 1e42 from 0 to -6, and the x-axis Time in units of 1e7. Most planet lines are nearly flat, but the Mercury line dips and rises in a large oscillation, reaching a minimum near -5.7e42 around time 7.5e6.
    48270460_319917821945064_7069244744462761984_n.png?_nc_cat=106&_nc_ht=scontent-lhr3-1.png
    10.4 KB · Views: 1,203
  • Like
Likes   Reactions: Sajid86
You sure modr is wrt the sun ? It looks as if you overwrite body.Ep for every pass in the loop ?
 
BvU said:
You sure modr is wrt the sun ? It looks as if you overwrite body.Ep for every pass in the loop ?
what do you mean by wrt?
 
With respect to

Your loop is over all bodies in self.bodies. Every time body.Ep is calculated - overwriting the previous result. So the last one gets the cake.
 
BvU said:
With respect to

Do you want me to write the formula out of the loop?
 
Up to you. In response to your original question:
Jozefina Gramatikova said:
Please tell me if Mercury's potential energy should oscillate having in mind that its orbit should be circular
It should not (the potential energy wrt the sun). But I doubt Mercury.Ep is that energy.
 
  • Like
Likes   Reactions: scottdave
Can I please ask you to write the line for the Potential energy the way you think it should look like. Thanks
 
That's your job. All I did was point out something that I noticed. Do you sgree it looks suspiious ?
 
I'm not particularly fluent in Python, but it appears to me that inside the outer loop each instance of ##body## will be a unique object from the set ##self.bodies##. It also appears that the Jozefina is summing all of the potential energies that exist between a given body and all the others. I'd expect that to vary when other bodies are closer or farther from a given body.

@Jozefina Gramatikova , one thing you might want to check is whether the "oscillations" change if you vary the time step size in the simulation. Mercury will be the fastest moving object and will be most susceptible to errors creeping in from the integration process. These "errors" might show up as gradually changing orbits (spirals) or energy coming or going seemingly from nowhere.
 
  • Like
Likes   Reactions: scottdave
I don't think I am summing all of the potential energies. I reset body.Ep to zero every time the outer for loop starts
 
Overlooked the +=

o:)

Suspicion is still at the same location
 
Can you tell me how am I summing the potential energies? I reset body.Ep to zero every time the outer for loop starts
 
@gneill tells you in #9
Ep should only use r wrt the sun, not do a sum
 
You can sum the gravitational PE's for all the bodies to obtain a net gravitational PE for the entire system. This is similar to finding the total electrical PE of a number of charges. Think of it as gravitational binding energy of the system.

When looking at a given body in orbit it is useful to look at its gravitational PE and its KE with respect the primary (Sun). The sum should be just about constant over time if the influences of other bodies in the system are negligible.
 
Line plot titled Potential energy as a function of time, with time from 0 to 1e8 on the x-axis and potential energy in units of 1e38 on the y-axis; eight planet curves from Mercury to Neptune are listed in a legend, the inner planets and Uranus and Neptune near zero, Saturn near -0.5, and Jupiter sloping down from about -3.1 to -3.4.

I made some changes. Does this look fine? I am a bit worried about Jupiter.
 
Attachments
  • Line plot titled Potential energy as a function of time, with time from 0 to 1e8 on the x-axis and potential energy in units of 1e38 on the y-axis; eight planet curves from Mercury to Neptune are listed in a legend, the inner planets and Uranus and Neptune near zero, Saturn near -0.5, and Jupiter sloping down from about -3.1 to -3.4.
    48411493_376628099771590_1400884981810593792_n.png?_nc_cat=110&_nc_ht=scontent-lhr3-1.png
    6.8 KB · Views: 931
I'd be worried about Jupiter too. But I'd look in the code :rolleyes:
 
Screenshot of Python code in a dark-themed editor defining get_norm(self, x) and updateaccel(self), which loops over bodies and computes gravitational acceleration and potential energy from pairwise position differences.
 
Attachments
  • Screenshot of Python code in a dark-themed editor defining get_norm(self, x) and updateaccel(self), which loops over bodies and computes gravitational acceleration and potential energy from pairwise position differences.
    upload_2018-12-16_12-20-47.png
    13.8 KB · Views: 941
So what changes over time ? Does |Jupiter.position| decrease ? And the others stay the same ?
 
they should all stay the same. I don't know what's wrong with Jupiter
 
Numerically GMm/r is around 3e35 for Jupiter ; how come you are around 3e38 ?
Jozefina Gramatikova said:
they should all stay the same
Well, do they ? All except Jupiter ?
 
Line plot titled Potential energy as a function of time, with y-axis Potential energy (scale 1e35) from about -4.0 to 0 and x-axis Time up to 1e7; nine nearly flat coloured lines for Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune in a legend.

I think the potential energy is fixed. However, i think i have a problem with the total energy of the system as it oscillates.

Line graph titled 'Total energy of the system as a function of time', showing a red curve that falls from about -5.85e35 to a minimum near -6.10e35 at around 1.3e8 time units, then rises back to about -5.87e35 at 3.0e8.

Do you think this is wrong?
 
Attachments
  • Line plot titled Potential energy as a function of time, with y-axis Potential energy (scale 1e35) from about -4.0 to 0 and x-axis Time up to 1e7; nine nearly flat coloured lines for Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune in a legend.
    upload_2018-12-17_9-25-21.png
    6.7 KB · Views: 762
  • Line graph titled 'Total energy of the system as a function of time', showing a red curve that falls from about -5.85e35 to a minimum near -6.10e35 at around 1.3e8 time units, then rises back to about -5.87e35 at 3.0e8.
    48356339_370653243511024_2388802398479974400_n.jpg?_nc_cat=105&_nc_ht=scontent.flhr4-1.jpg
    18.8 KB · Views: 723
Screenshot of Python code showing Et_instant set to 0, then Et_instant updated by adding Ek_Sun[-1] and Ep_Sun[-1], and later by adding Ek_Mercury[-1] and Ep_Mercury[-1]; red underlines mark these lines.

I do this ^ for every planet
Python code snippet computing Neptune's kinetic energy from velocity and mass, adding kinetic and potential energy to Et_instant, and appending the total_energy list; a red line underlines total_energy.append(Et_instant).

Python matplotlib code snippet: figure 4 titled 'total energy as a function of time', plotting total_energy against t, with axis labels Time and Total energy, the block circled in red.

I gave you the sections of my code that are associated with the total energy. Could you please tell me what is wrong. Thanks
 
Attachments
  • Screenshot of Python code showing Et_instant set to 0, then Et_instant updated by adding Ek_Sun[-1] and Ep_Sun[-1], and later by adding Ek_Mercury[-1] and Ep_Mercury[-1]; red underlines mark these lines.
    48366254_513455825807651_4198931191606280192_n.png?_nc_cat=104&_nc_ht=scontent.flhr4-1.png
    10 KB · Views: 690
  • Python code snippet computing Neptune's kinetic energy from velocity and mass, adding kinetic and potential energy to Et_instant, and appending the total_energy list; a red line underlines total_energy.append(Et_instant).
    48386250_830755340590428_3355988381673717760_n.png?_nc_cat=108&_nc_ht=scontent.flhr4-1.png
    5.8 KB · Views: 700
  • Python matplotlib code snippet: figure 4 titled 'total energy as a function of time', plotting total_energy against t, with axis labels Time and Total energy, the block circled in red.
    48360418_1992828497475096_2308521217675493376_n.png?_nc_cat=102&_nc_ht=scontent.flhr4-2.png
    15.1 KB · Views: 776
PLS TELL ME THE DEADLINE IS 5 HOURS FROM NOW. I AM DEAD
 
Sorry, I have I job I do want to keep, so I can't be available full time.
Can't make much sense out of what you post; no idea where the snag is :nb)
I am surprised you have circular orbits and still have the sun itself moving too. What can possibly be its Ep ?