- #1

- 48

- 0

Thanks to everyone who offered to take a look at my problem sheet and my relevant code. I have scanned in the 3 relevant pages of my problem sheet and they can be seen at:

www.hoofbeat.tv/tempcomp.htm[/URL] (the files are too large to upload onto here)

Below is a copy of my original code (we've tried soooo many versions for the acceleration formula :uhh: ). NB. Incase you're not familiar with programming in Windows, the code "system (PAUSE)" is required when using a windows programmer to stop the new window closing once the program has been run.

=========

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

/*A program designed to plot the trajectory of a rocket on a mission to land on the moon*/

int main(int argc, char *argv[])

{

const float pi=3.1415; /*This defines the value of pi*/

const float u=0.0066; /*This defines the intial velocity of rocket and is equivalent to v0*/

const float angle=((89.9*pi)/180.0); /*This defines the angle of projection*/

const float xe=0, ye=0; /*These are the Earth's coords: (0, 0) - ie. where it's centre lies*/

const float xm=0, ym=225.7; /*These are the Moon's coords: (0, 225.7)*/

const float Mm=1.0, Me=83.3; /*These are the masses of the Moon & Earth Respectively*/

const float Rm=1.0, Re=3.7; /*These are the radii of the Moon & Earth Respectively*/

const float G=(9.63*pow(10, -7)); /*This is the Gravitational constant)*/

int dt=10; /*This is the step size delta.t*/

float xr=0, yr=3.7; /*These are the coords of the Rocket)*/

float vx, vy; /*These are the current velocities in both x & y directions*/

float ax=0, ay=0; /*These are the accelerations in both x & y directions*/

float rrx, rry; /*These are the components of the vector from Earth to Rocket*/

float rmx, rmy; /*These are the components of the vector from earth to Moon*/

/*Do NOT confuse with Re & Rm which are radii*/

vx = u*cos(angle);

vy = u*sin(angle);

int t=0;

/*Using a while loop*/

while(pow((pow(xm-xr,2)) + (pow(ym-yr,2)),1/2)>=Rm)

/*When the distance to the centre of the moon < radius of the moon,*/

/*then the rocket has landed and the calculation can be stopped*/

{

t=t+dt; /*Time increases by 10 each time*/

rmx = xm - xe;

rmy = ym - ye;

rrx = xr - xe;

rry = yr - ye;

ax = (((-G*Me)*xr)/(pow(((rrx*rrx)+(rry*rry)),(3/2)))) - ((G*Mm*(xr-xm))/(pow((pow(((rrx-rmx)),2)+(pow(((rry-rmy)),2))),(3/2)))); /*Acceleration in x-direction*/

ay = (((-G*Me)*yr)/(pow(((rrx*rrx)+(rry*rry)),(3/2)))) - ((G*Mm*(yr-ym))/(pow((pow(((rrx-rmx)),2)+(pow(((rry-rmy)),2))),(3/2)))); /*Acceleration in y-direction*/

vx=vx+(dt*ax); /*Step 4 of Euler's method*/

vy=vy+(dt*ay); /*Step 4 of Euler's method*/

xr=xr+(dt*vx); /*Step 5 of Euler's method*/

yr=yr+(dt*vy); /*Step 5 of Euler's method*/

printf("Acceleration x: %f\n", ax);

printf("Acceleration y: %f\n", ay);

printf("Time: %d\n", t);

printf("X velocity: %f\n", vx);

printf("Y velocity: %f\n", vy);

printf("X coord: %f\n", xr);

printf("Y coord: %f\n", yr);

system("PAUSE");

}

system("PAUSE"); /*This code is specific to a Windows system*/

return 0;

}

======================

Thanks once again

www.hoofbeat.tv/tempcomp.htm[/URL] (the files are too large to upload onto here)

Below is a copy of my original code (we've tried soooo many versions for the acceleration formula :uhh: ). NB. Incase you're not familiar with programming in Windows, the code "system (PAUSE)" is required when using a windows programmer to stop the new window closing once the program has been run.

=========

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

/*A program designed to plot the trajectory of a rocket on a mission to land on the moon*/

int main(int argc, char *argv[])

{

const float pi=3.1415; /*This defines the value of pi*/

const float u=0.0066; /*This defines the intial velocity of rocket and is equivalent to v0*/

const float angle=((89.9*pi)/180.0); /*This defines the angle of projection*/

const float xe=0, ye=0; /*These are the Earth's coords: (0, 0) - ie. where it's centre lies*/

const float xm=0, ym=225.7; /*These are the Moon's coords: (0, 225.7)*/

const float Mm=1.0, Me=83.3; /*These are the masses of the Moon & Earth Respectively*/

const float Rm=1.0, Re=3.7; /*These are the radii of the Moon & Earth Respectively*/

const float G=(9.63*pow(10, -7)); /*This is the Gravitational constant)*/

int dt=10; /*This is the step size delta.t*/

float xr=0, yr=3.7; /*These are the coords of the Rocket)*/

float vx, vy; /*These are the current velocities in both x & y directions*/

float ax=0, ay=0; /*These are the accelerations in both x & y directions*/

float rrx, rry; /*These are the components of the vector from Earth to Rocket*/

float rmx, rmy; /*These are the components of the vector from earth to Moon*/

/*Do NOT confuse with Re & Rm which are radii*/

vx = u*cos(angle);

vy = u*sin(angle);

int t=0;

/*Using a while loop*/

while(pow((pow(xm-xr,2)) + (pow(ym-yr,2)),1/2)>=Rm)

/*When the distance to the centre of the moon < radius of the moon,*/

/*then the rocket has landed and the calculation can be stopped*/

{

t=t+dt; /*Time increases by 10 each time*/

rmx = xm - xe;

rmy = ym - ye;

rrx = xr - xe;

rry = yr - ye;

ax = (((-G*Me)*xr)/(pow(((rrx*rrx)+(rry*rry)),(3/2)))) - ((G*Mm*(xr-xm))/(pow((pow(((rrx-rmx)),2)+(pow(((rry-rmy)),2))),(3/2)))); /*Acceleration in x-direction*/

ay = (((-G*Me)*yr)/(pow(((rrx*rrx)+(rry*rry)),(3/2)))) - ((G*Mm*(yr-ym))/(pow((pow(((rrx-rmx)),2)+(pow(((rry-rmy)),2))),(3/2)))); /*Acceleration in y-direction*/

vx=vx+(dt*ax); /*Step 4 of Euler's method*/

vy=vy+(dt*ay); /*Step 4 of Euler's method*/

xr=xr+(dt*vx); /*Step 5 of Euler's method*/

yr=yr+(dt*vy); /*Step 5 of Euler's method*/

printf("Acceleration x: %f\n", ax);

printf("Acceleration y: %f\n", ay);

printf("Time: %d\n", t);

printf("X velocity: %f\n", vx);

printf("Y velocity: %f\n", vy);

printf("X coord: %f\n", xr);

printf("Y coord: %f\n", yr);

system("PAUSE");

}

system("PAUSE"); /*This code is specific to a Windows system*/

return 0;

}

======================

Thanks once again

Last edited by a moderator: