Python: Simulation of the Solar System and Total energy

In summary, the conversation is about a project to create a simulation of the solar system in Python and calculate the total energy of the system. There is a concern about Mercury's potential energy oscillating, but it is clarified that the potential energy should not oscillate if the orbit is circular. The conversation also includes discussions about the code and potential issues with Jupiter's potential energy. The deadline for the project is mentioned to be in 5 hours.
  • #1
Jozefina Gramatikova
64
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: 948
  • upload_2018-12-15_20-28-3.png
    upload_2018-12-15_20-28-3.png
    10.7 KB · Views: 910
  • upload_2018-12-15_20-30-19.png
    upload_2018-12-15_20-30-19.png
    563 bytes · Views: 929
  • upload_2018-12-15_20-34-30.png
    upload_2018-12-15_20-34-30.png
    13.3 KB · Views: 997
  • 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,154
  • 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,066
  • 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,024
  • Like
Likes Sajid86
Technology news on Phys.org
  • #2
You sure modr is wrt the sun ? It looks as if you overwrite body.Ep for every pass in the loop ?
 
  • #3
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?
 
  • #4
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.
 
  • #5
BvU said:
With respect to

Do you want me to write the formula out of the loop?
 
  • #6
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 scottdave
  • #7
Can I please ask you to write the line for the Potential energy the way you think it should look like. Thanks
 
  • #8
That's your job. All I did was point out something that I noticed. Do you sgree it looks suspiious ?
 
  • #9
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 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: 764
  • #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: 783
  • #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: 633
  • 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: 608
  • #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: 561
  • 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: 553
  • 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: 624
  • #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 ?
 

1. What is Python?

Python is a high-level, interpreted programming language that is widely used for various applications such as web development, data analysis, and scientific computing. It is known for its simple syntax and powerful libraries, making it a popular choice among scientists and programmers.

2. How can Python be used for simulating the solar system?

Python can be used for simulating the solar system by utilizing its libraries such as NumPy, Matplotlib, and Astropy. These libraries provide tools for performing calculations, creating visualizations, and handling astronomical data, making it easier to create accurate and realistic simulations.

3. What is the purpose of simulating the solar system?

The purpose of simulating the solar system is to better understand the dynamics and interactions of the celestial bodies within it. By using simulations, scientists can study the past, present, and potential future of the solar system, as well as make predictions about its behavior.

4. What is total energy in relation to the solar system simulation?

Total energy in a solar system simulation refers to the sum of all the energy present in the system, including kinetic and potential energy. In the context of the simulation, it is important to monitor the total energy to ensure that the simulation is accurate and realistic.

5. Can Python simulations of the solar system be used for educational purposes?

Yes, Python simulations of the solar system can be used for educational purposes. They can help students visualize and understand complex astronomical concepts, such as orbital mechanics and planetary motion, in a more interactive and engaging way. They can also be used to demonstrate the effects of different variables on the solar system, allowing students to explore and learn at their own pace.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
Replies
12
Views
2K
  • Sci-Fi Writing and World Building
Replies
21
Views
1K
  • Programming and Computer Science
Replies
18
Views
5K
  • Programming and Computer Science
Replies
5
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
452
  • Astronomy and Astrophysics
Replies
15
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
11
Views
1K
Back
Top