# C code, restricted three body

## Homework Statement

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

it's the first example

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, y, mneg, mnegm, mpos, rpnx, rpny, rppx, rppy, ax, ay, xzero, yzero, vxzero, vyzero, dt;
int n;
FILE *output;

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

sscanf(argv, "%f", &mneg);
sscanf(argv, "%f", &mpos);
sscanf(argv, "%f", &xzero);
sscanf(argv, "%f", &yzero);
sscanf(argv, "%f", &vxzero);
sscanf(argv, "%f", &vyzero);

dt = 0.005;
x = xzero;
y = yzero;
x = xzero + vxzero*dt;
y =yzero + vyzero*dt;
rpnx= -1;
rpny= 0;
rppx= 1;
rppy= 0;
printf("%f %f\n", x, y);

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, ay);

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:

Related Engineering and Comp Sci Homework Help News on Phys.org
Nothing appears when I open the web page...

AlephZero