Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programs Question. Whoever can solve this, then you can call yourself a boss!

ID: 3775106 • Letter: C

Question

C Programs Question. Whoever can solve this, then you can call yourself a boss!

Launching a spacecraft to the Moon orbit: Landing a spacecraft can be very difficult on Moon, since Moon have no atmosphere to help the spacecraft to slowdown. Usually, approaching the Moon orbits is the first step. Here, our job is using numerical analysis to help design the launching setting. Pictures are not directly relate to this homework, just showing the concept and its complexity We assume after the launching, the spaceship has no thrust at all (which is more like a cannon ball that only affected by both gravity of the Earth and the Moon). To further simplify the question, we assume the Earth and the Moon are immobile on a 2-D domain, which located at (0,0) and (4 108,0) respectively (A very bad assumption in fact). The radius of the Earth and the Moon are 6,371,000 m and 1,737,100 m. Please use Euler’s method to solve the trajectory and estimate the initial velocity that allows the spaceship to go on the moon orbit instead of crashing on it. You can chose our launching location on earth and its initial velocity and angle. Any theory you find can be used to help you refine your launching setting.

1. Try at least 20 trials and plot your best 5.

2. Plot the output of same initial condition with different integration time interval, and demonstrate the choosing of your time interval is valid.

Explanation / Answer

program

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
void moonMotion(int radius, int midx, int midy, int x[60], int y[60])
{
int i, j = 0;
for (i = 360; i > 0; i = i - 6)
{
x[j] = midx - (radius * cos((i * 3.14) / 180));
y[j++] = midy - (radius * sin((i * 3.14) / 180));
}
return;
}
int main()
{
int gdriver = DETECT, gmode, err;
int midx, midy, earth, orbit, moon;
int i = 0, x[60], y[60];
initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
err = graphresult();
if (err != grOk)
{
printf("Graphics Error: %s",grapherrormsg(err));
return 0;
}
earth = 50, orbit = 100, moon = 25;
midx = getmaxx() / 2;
midy = getmaxy() / 2;
moonMotion(orbit, midx, midy, x, y);
while(!kbhit())
{
setcolor(BLUE);
setfillstyle(SOLID_FILL, BLUE);
pieslice(midx, midy, 0, 360, earth);
setcolor(WHITE);
setlinestyle(DASHED_LINE, 1, 1);
circle(midx, midy, orbit);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, YELLOW);
setlinestyle(SOLID_LINE, 1, 1);
pieslice(x[i], y[i], 0, 360, moon);
delay(200);
cleardevice();
i = (i + 1) % 60;
}
closegraph();
return 0;
}