Need Source Code In c For 2-Bodies Gravitational Problem

AI Thread Summary
Zaheer is seeking source code in C for the two-body gravitational problem to compare with his own implementation, which is not producing correct circular orbits. He has used the Leap Frog and Runge-Kutta 4th order methods but finds that while his three-body simulations work correctly, the two-body simulation results in more than two rotations instead of one complete orbit. Forum participants suggest that debugging his existing code may be more beneficial than copying others' work, emphasizing the importance of understanding the physics behind circular orbits. They also recommend looking into resources like "An Introduction to Computer Simulation Methods" for guidance. Overall, Zaheer is encouraged to refine his approach rather than rely solely on external code.
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
 
Back
Top