Python: Simulation of the Solar System and Total energy

Click For Summary

Discussion Overview

The discussion revolves around a Python project simulating the Solar System, focusing on the calculation of total energy, potential energy, and kinetic energy of the planets. Participants explore issues related to the implementation of circular orbits and the observed oscillations in Mercury's potential energy.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant questions whether Mercury's potential energy should oscillate given that its orbit is circular.
  • Another participant suggests that the potential energy calculation may be incorrect due to overwriting values in a loop.
  • Concerns are raised about the potential energy being calculated with respect to the Sun and whether it should be summed over multiple bodies.
  • A participant proposes that the oscillations in potential energy could be due to numerical errors in the simulation, particularly affecting faster-moving bodies like Mercury.
  • There are discussions about the total energy of the system oscillating and whether this is expected behavior.
  • One participant expresses confusion about the potential energy of Jupiter and its expected stability in the simulation.
  • Another participant emphasizes the importance of checking the gravitational potential energy with respect to the primary body (the Sun) rather than summing energies from all bodies.
  • Participants discuss the implications of having circular orbits while also accounting for the Sun's movement in the simulation.

Areas of Agreement / Disagreement

Participants express differing views on the correctness of the potential energy calculations and whether oscillations in energy are expected. There is no consensus on the specific issues within the code or the behavior of the energies in the simulation.

Contextual Notes

Participants note potential limitations in the simulation, including the handling of numerical integration and the treatment of gravitational interactions among multiple bodies. There are unresolved questions about the specific implementation details in the code.

Who May Find This Useful

This discussion may be useful for individuals interested in computational physics, coding simulations of celestial mechanics, or those working on similar homework projects involving energy calculations in orbital dynamics.

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*

48388735_267718147436379_3590436185207472128_n.jpg?_nc_cat=103&_nc_ht=scontent-lhr3-1.jpg

48363578_370605647078369_8129958863207137280_n.jpg?_nc_cat=104&_nc_ht=scontent-lhr3-1.jpg


Homework Equations


upload_2018-12-15_20-27-32.png
upload_2018-12-15_20-30-19.png

Potential energy:
upload_2018-12-15_20-28-3.png
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


48270460_319917821945064_7069244744462761984_n.png?_nc_cat=106&_nc_ht=scontent-lhr3-1.png

This is a piece of my code where the problem might be (if there is a problem)
upload_2018-12-15_20-34-30.png
 

Attachments

  • upload_2018-12-15_20-27-32.png
    upload_2018-12-15_20-27-32.png
    990 bytes · Views: 1,087
  • upload_2018-12-15_20-28-3.png
    upload_2018-12-15_20-28-3.png
    10.7 KB · Views: 1,011
  • upload_2018-12-15_20-30-19.png
    upload_2018-12-15_20-30-19.png
    563 bytes · Views: 1,063
  • upload_2018-12-15_20-34-30.png
    upload_2018-12-15_20-34-30.png
    13.3 KB · Views: 1,124
  • 48388735_267718147436379_3590436185207472128_n.jpg?_nc_cat=103&_nc_ht=scontent-lhr3-1.jpg
    48388735_267718147436379_3590436185207472128_n.jpg?_nc_cat=103&_nc_ht=scontent-lhr3-1.jpg
    22.5 KB · Views: 1,317
  • 48363578_370605647078369_8129958863207137280_n.jpg?_nc_cat=104&_nc_ht=scontent-lhr3-1.jpg
    48363578_370605647078369_8129958863207137280_n.jpg?_nc_cat=104&_nc_ht=scontent-lhr3-1.jpg
    26.7 KB · Views: 1,142
  • 48270460_319917821945064_7069244744462761984_n.png?_nc_cat=106&_nc_ht=scontent-lhr3-1.png
    48270460_319917821945064_7069244744462761984_n.png?_nc_cat=106&_nc_ht=scontent-lhr3-1.png
    10.4 KB · Views: 1,150
  • Like
Likes   Reactions: Sajid86
Technology news on Phys.org
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
  • #10
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
 
  • #11
Overlooked the +=

o:)

Suspicion is still at the same location
 
  • #12
Can you tell me how am I summing the potential energies? I reset body.Ep to zero every time the outer for loop starts
 
  • #13
@gneill tells you in #9
Ep should only use r wrt the sun, not do a sum
 
  • #14
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.
 
  • #15
48411493_376628099771590_1400884981810593792_n.png?_nc_cat=110&_nc_ht=scontent-lhr3-1.png

I made some changes. Does this look fine? I am a bit worried about Jupiter.
 

Attachments

  • 48411493_376628099771590_1400884981810593792_n.png?_nc_cat=110&_nc_ht=scontent-lhr3-1.png
    48411493_376628099771590_1400884981810593792_n.png?_nc_cat=110&_nc_ht=scontent-lhr3-1.png
    6.8 KB · Views: 896
  • #16
I'd be worried about Jupiter too. But I'd look in the code :rolleyes:
 
  • #17
upload_2018-12-16_12-20-47.png
 

Attachments

  • upload_2018-12-16_12-20-47.png
    upload_2018-12-16_12-20-47.png
    13.8 KB · Views: 912
  • #18
So what changes over time ? Does |Jupiter.position| decrease ? And the others stay the same ?
 
  • #19
they should all stay the same. I don't know what's wrong with Jupiter
 
  • #20
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 ?
 
  • #21
upload_2018-12-17_9-25-21.png

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

48356339_370653243511024_2388802398479974400_n.jpg?_nc_cat=105&_nc_ht=scontent.flhr4-1.jpg

Do you think this is wrong?
 

Attachments

  • upload_2018-12-17_9-25-21.png
    upload_2018-12-17_9-25-21.png
    6.7 KB · Views: 733
  • 48356339_370653243511024_2388802398479974400_n.jpg?_nc_cat=105&_nc_ht=scontent.flhr4-1.jpg
    48356339_370653243511024_2388802398479974400_n.jpg?_nc_cat=105&_nc_ht=scontent.flhr4-1.jpg
    18.8 KB · Views: 695
  • #22
Yes :rolleyes:
 
  • #23
48366254_513455825807651_4198931191606280192_n.png?_nc_cat=104&_nc_ht=scontent.flhr4-1.png

I do this ^ for every planet
48386250_830755340590428_3355988381673717760_n.png?_nc_cat=108&_nc_ht=scontent.flhr4-1.png

48360418_1992828497475096_2308521217675493376_n.png?_nc_cat=102&_nc_ht=scontent.flhr4-2.png

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

  • 48366254_513455825807651_4198931191606280192_n.png?_nc_cat=104&_nc_ht=scontent.flhr4-1.png
    48366254_513455825807651_4198931191606280192_n.png?_nc_cat=104&_nc_ht=scontent.flhr4-1.png
    10 KB · Views: 658
  • 48386250_830755340590428_3355988381673717760_n.png?_nc_cat=108&_nc_ht=scontent.flhr4-1.png
    48386250_830755340590428_3355988381673717760_n.png?_nc_cat=108&_nc_ht=scontent.flhr4-1.png
    5.8 KB · Views: 670
  • 48360418_1992828497475096_2308521217675493376_n.png?_nc_cat=102&_nc_ht=scontent.flhr4-2.png
    48360418_1992828497475096_2308521217675493376_n.png?_nc_cat=102&_nc_ht=scontent.flhr4-2.png
    15.1 KB · Views: 743
  • #24
PLS TELL ME THE DEADLINE IS 5 HOURS FROM NOW. I AM DEAD
 
  • #25
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 ?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
541
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K