C code, restricted three body

In summary: The vector r+r_p is the vector from m(+) to m(-). Same for the other term.In summary, the conversation is about a student's difficulty with understanding the calculations for a physics project involving programming. They are trying to use two equations to find the acceleration and position of a third mass, but are getting unexpected results. The code and equations are provided for others to review and provide guidance. However, it is pointed out that the student has misunderstood one of the equations, which is causing the incorrect results.
  • #1
Pixter
30
0

Homework Statement

http://www2.warwick.ac.uk/fac/sci/physics/teach/module_home/px270/projects/c4s_projects07.pdf

it's the first example

Homework Equations


see above

The Attempt at a Solution



right i shouldn't have any probs with the programming but i need to understand the calcs that are put on the site..

as i understand I'm suppose to the first eqn to find a,, then usign the second eqn to find rn+1.. this is done in components so for x and y..

but i tried it for a third mass that is at x=0 and y=positive integer(both the stationary massses are of equal magnitude).. what should happen is that it should be attracted and just go towards negative integers but I get acceleration in x direction.. ((note the printf function are just there for me to see some stuff))..

could someone maybe see where I've gone wrong and maybe give me som pointers:

here is the code:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>main(int argc, char* argv[])
{
float x[101], y[101], mneg, mnegm, mpos, rpnx, rpny, rppx, rppy, ax[101], ay[101], xzero, yzero, vxzero, vyzero, dt;
int n;
FILE *output;

output = fopen("data.dat", "w");

sscanf(argv[1], "%f", &mneg);
sscanf(argv[2], "%f", &mpos);
sscanf(argv[3], "%f", &xzero);
sscanf(argv[4], "%f", &yzero);
sscanf(argv[5], "%f", &vxzero);
sscanf(argv[6], "%f", &vyzero);
dt = 0.005;
x[0] = xzero;
y[0] = yzero;
x[1] = xzero + vxzero*dt;
y[1] =yzero + vyzero*dt;
rpnx= -1;
rpny= 0;
rppx= 1;
rppy= 0;
printf("%f %f\n", x[1], y[1]);

for(n=1; n < 100; ++n)
{
ax[n]=-mneg*((x[n]+rpnx)/(sqrt(pow((x[n]+rpnx),6))))-mpos*((x[n]-rppx)/(sqrt(pow((x[n]-rppx),6))));
ay[n]=-mneg*((y[n]+rpny)/(sqrt(pow((y[n]+rpny),6))))-mpos*((y[n]-rppy)/(sqrt(pow((y[n]-rppy),6))));

x[n+1]=((ax[n])*pow(dt,2))-(x[n-1])+2*(x[n]);
y[n+1]=((ay[n])*pow(dt,2))-(y[n-1])+2*(y[n]);
fprintf(output, "%f %f\n", x[n+1],y[n+1]);

}
printf("%f %f", ax[1], ay[1]);

fclose(output);
}edit: note that the first mass is inputted as a "negative mass" for the equation to work..
also a wird problem if setting inital velocities to zero then the third mass doesn't move at ll which it should
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Nothing appears when I open the web page...
 
  • #3
The attachment worked for me though it was a bit slow to open.

You seem to have misunderstood equation (1) in the attachment. The |r+r_p|^3 and |r-r_p|^3 terms are not vectors. |r+r_p| is the scalar length of the vector r+r_p.
 
Last edited:

1. What is the "restricted three body" problem in C code?

The restricted three body problem is a mathematical problem in physics that involves three point masses orbiting around each other under the influence of gravity, assuming that one of the masses is significantly smaller than the other two and does not significantly affect their motion. In C code, it is a computational challenge to accurately model and simulate the complex dynamics of this system.

2. How is the "restricted three body" problem solved in C code?

The restricted three body problem can be solved using a variety of numerical techniques in C code, such as the Runge-Kutta method or the Symplectic integrator. These methods involve breaking down the problem into smaller time steps and using iterative processes to approximate the motion of the masses.

3. What are some real-world applications of the "restricted three body" problem in C code?

The restricted three body problem has many applications in astrophysics, such as studying the motion of celestial bodies in our solar system, predicting the trajectories of comets and asteroids, and understanding the dynamics of binary star systems. It is also used in spacecraft trajectory planning and in the design of satellite orbits.

4. What are some challenges in implementing the "restricted three body" problem in C code?

One of the main challenges in implementing the restricted three body problem in C code is ensuring accuracy and stability in the numerical calculations. Due to the chaotic nature of the system, small errors in the initial conditions or the numerical methods used can lead to vastly different outcomes. This requires careful tuning of parameters and frequent checking of results.

5. Are there any open-source C code libraries available for solving the "restricted three body" problem?

Yes, there are several open-source C code libraries available for solving the restricted three body problem, such as the REBOUND library and the N-body Shop. These libraries provide pre-written code for numerical integration and visualization of the three body system, allowing for easier implementation and testing of different scenarios.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
885
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
19
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
937
  • Engineering and Comp Sci Homework Help
Replies
3
Views
878
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
Back
Top