Need Source Code In c For 2-Bodies Gravitational Problem

Click For Summary

Discussion Overview

The discussion revolves around the challenges faced by participants in coding a simulation for the two-body gravitational problem in C. Participants share their experiences, seek source code for comparison, and discuss methods for debugging and understanding the physics involved.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • Zaheer expresses difficulty in achieving correct orbital behavior in his N-bodies gravitational program, specifically noting that the two-body simulation does not produce a complete circular orbit.
  • One participant suggests searching for existing resources, mentioning a book that includes a chapter on the two-body problem in BASIC, implying that it could be useful for Zaheer.
  • Another participant advises starting with simpler problems and emphasizes the importance of understanding the physics behind circular orbits to identify coding errors.
  • There is a suggestion that reviewing other people's code could be instructive, but concerns are raised about the educational value of simply copying code without understanding it.
  • Zaheer mentions using the Leap Frog method and Runge-Kutta 4th order method in his coding attempts, noting discrepancies in the expected behavior of the Earth in his simulations.
  • Some participants argue that examining and debugging one's own code may be more beneficial than relying on external code, while others believe that accessing existing code could provide insights into potential mistakes.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to resolving Zaheer's coding issues, with some advocating for debugging his own code and others suggesting that reviewing existing code could be helpful. No consensus is reached on the most effective method for learning or correcting the problem.

Contextual Notes

Participants highlight the complexity of the problem, including the reliance on differential equations and the potential for calculation mistakes in the coding process. Specific assumptions about the physics of orbits and the methods used in coding are not fully explored.

Zaheer Ahmed
Messages
15
Reaction score
0
Need Source Code In "c" For 2-Bodies Gravitational Problem

Hello,

My name is Zaheer. I am working on N-bodies gravitational problem, i made n-bodies program in "c" but the behaviour of the bodies is not correct as it is not making a complete circle, insted it is making a semi circle and coming back to the original position, if anyone of you worked on this problem and can provide source codes for me for 2-bodies problem so that i can compare my program with the one that will be provided it will be a great help for me, i will be thankful to you. Regards Zaheer
 
Astronomy news on Phys.org
Sounds like a job for Google. I tried a search, and even found a post from you! The book An Introduction to Computer Simulation Methods has a whole chapter dedictated to coding the 2-body problem, using BASIC. Check it out if you get desperate and can read BASIC well enough to convert the code.
 
sounds like a (-) problem...search for stuff by "chris hecker"
 
I could repeat my previous advice - work on a simpler problem first, it's all differential equations - but I'm not sure how much good that would do.

A better understanding of the physics of a circular orbit might help, too - if you understand why a circular orbit is circular, you should be able to figure out where the code is going wrong. But I'm not sure how to "bottle up" such an understanding.

Finding some code somewhere wouldn't really teach Z.A. anything - debugging the code he wrote would be far more productive, if he can manage to accomplish the task.

Looking over other people's code might be instructive, but just lifting it wholesale won't be very educational.
 
copied code would teach him stuff it he wanted to reprogramm it to test where he went wrong. I went through an entire 3D engine ...and i know the jist of how to organize it...and I thank Eberly, Irrlicht and the Ogre Engines
 
Using the book I mentioned above, I coded a VB 2-body orbit function. It was super simple; the main loop has only 3 lines of code to calculate the position. There's got to be a lot of code out there to get ideas from.
 
I wrote my own codes, they work correctly for 3 or more than 3 bodies but for 2bodies

Hello,

Thanks for your valuable reply, i wrote my own codes using Leap Frog method and Rung-Kutta 4th order method, Considering my program,when i am working with two bodies (Sun-Earth) the behavior of Earth is not the same as expected, insted of making one complete rotation around the Sun in 53 weeks it is making more than two rotations. Whereas when i am working with three bodies, as well as with solar system, the behavior of Earth is as expected, Earth is making one complete rotation in 53 weeks, this shows that some where i am doing calculation mistake, my codes are available in the physics forms, as i already send one post by the name Zaheer A. If anyone want to refer please go though that. Thanks for your valuable time. Zaheer A
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 86 ·
3
Replies
86
Views
9K
  • · Replies 40 ·
2
Replies
40
Views
3K
  • · Replies 84 ·
3
Replies
84
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
3
Views
7K
  • · Replies 17 ·
Replies
17
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K