/* Binary Orbital Mechanics According to Kepler's laws of planetary motion, as well as Newton's laws of universal gravitation, celestial bodies in space will orbit in elliptical paths along a common center of mass called the barycenter. For a system with only 2 stars (a binary star system), the stars will appear to move in circles around the barycenter. The orbital elements of each star can be calculated using the following equations: sqrt(m_b^2 * G) V_a = ----------------------- sqrt((m_a + m_b) * d) sqrt(m_a^2 * G) V_b = ----------------------- sqrt((m_a + m_b) * d) d * m_b R_a = ----------- m_a + m_b d * m_a R_b = ----------- m_a + m_b Where: d is the distance between the 2 stars (in meters), m_a and m_b are the masses of stars A and B, respectively (in kilograms), V_a and V_b are the orbital velocities of stars A and B, respectively, (in meters/second) R_a and R_b are the distances from each star to the barycenter (in meters), and G is the Universal Gravitational Constant (which is 6.674e-11 (m^3 / kg*s^2)) You must write a complete C program that reads in the masses of the 2 stars (in kilograms), as well as the distance between them (in meters). You must then calculate the orbital elements V_a, V_b, R_a, and R_b, and print these out to the screen. Since the numbers involved will be quite large, you first must convert the star velocities from m/s to km/s and the barycenter distances from m to km. Also, since stars are VERY massive objects, with masses well into the 10^30 kg range, you may want to use scientific notation form. It works the same as any other double value, but instead of entering the number in normal form, you enter it in scientific notation (ex. double num = 1e30; #define myvalue 8.8e-2). To ensure the highest degree of accuracy, make sure to use doubles, NOT floats. Print all of your results to 2 decimal places, i.e. %.2f in printf. =========SAMPLE RUN========= Enter the mass of star A in kg: 1.63e30 Enter the mass of star B in kg: 8.72e29 Enter the distance between the two stars in m: 1.55e10 Star A orbits the barycenter at a velocity of 36.17 km/s, and a distance of 5402078.34 km. Star B orbits the barycenter at a velocity of 67.62 km/s, and a distance of 10097921.66 km. =====END OF SAMPLE RUN====== */ #include #include #include #define GRAV_CONSTANT 6.674e-11 int main(){ double d, m_a, m_b; //INPUTS double V_a, V_b, R_a, R_b; //OUTPUTS //Read in the inputs printf("Enter the mass of star A in kg: "); scanf("%lf", &m_a); printf("Enter the mass of star B in kg: "); scanf("%lf", &m_b); printf("Enter the distance between the two stars in m: "); scanf("%lf", &d); //Calculate velocities V_a = sqrt(m_b*m_b * GRAV_CONSTANT) / sqrt((m_a + m_b) * d); V_b = sqrt(m_a*m_a * GRAV_CONSTANT) / sqrt((m_a + m_b) * d); //Convert to km/s V_a /= 1000; V_b /= 1000; //Calculate radii R_a = (d * m_b) / (m_a + m_b); R_b = (d * m_a) / (m_a + m_b); //Convert to km R_a /= 1000; R_b /= 1000; //Print out the outputs printf("\nStar A orbits the barycenter at a velocity of %.2f km/s,\nand a distance of %.2f km.\n", V_a, R_a); printf("\nStar B orbits the barycenter at a velocity of %.2f km/s,\nand a distance of %.2f km.\n", V_b, R_b); system("pause"); return 0; }