These exercises are not tied to a specific programming language. Example implementations are provided under the Code tab, but the Exercises can be implemented in whatever platform you wish to use (e.g., Excel, Python, MATLAB, etc.).
### Exercise 1
Write a simulation of Mars and Earth orbiting the Sun. You can neglect the interaction of Earth and Mars and only calculate the gravitational force by the Sun on each planet.
For the initial positions and velocities of the planets in your simulation, use [JPL's Horizons web interface](http://ssd.jpl.nasa.gov/horizons.cgi). Here are the instructions for using Horizons.
1. Change the Ephemeris Type to "Vector Table" and click the "Use Selection Above" button to submit the change.
2. Change other settings too until you get the settings shown below (with the particular time span you are interested in).

3. Click the button "Generate Ephemeris." Record the initial position vector and velocity vector in Cartesian coordinates for Mars. Note the units because you might use meters and seconds in your simulation.
4. Change the "Target Body" to Earth and repeat. Record the initial position vector and velocity vector in Cartesian coordinates for Earth. We will do a 2D simulation, so set the z-components of the position and velocity to zero.
Run your simulation and use it to determine the time (in days) between Mars oppositions, as shown below.

In Exercise 2, you will find the best time (i.e. best relative positions of Earth and Mars) to launch the rocket from Earth. Do you think the best time (best positions of Earth and Mars) is when they are in opposition as shown above? After Exercise 3, you will be able to judge your answer.
### Exercise 2
You will eventually add a rocket to the simulation you wrote in Exercise 1, and you will find the direction of launch and day of launch that takes the rocket to Mars. However, we must first decide on the initial speed and position we should give the rocket.
To find the initial speed, we will assume:
* at some distance (of our choosing) from Earth, the boosters have burned out and we will call this the initial position of the rocket. Let's choose an altitude equal to a geosynchronous orbit which is $4.6R_{E}$ (a distance $5.6R_{E}$ from the center of Earth).
* near Earth, during the launch, the rocket must reach a speed greater than the escape speed. Earth's escape speed is 11 km/s. To leave Earth and not return, the rocket will have to reach a speed of at least 11 km/s sometime after takeoff.
* our rocket had a speed of 11.5 km/s when it was near Earth's surface and its final booster burned out; this was at such a high altitude that air resistance is negligible.
Using these assumptions and the Energy Principle, find the speed of the rocket when it is at an altitude of $4.6R_{E}$. What other assumptions did you make?
### Exercise 3
Depending on the particular orbit, it can take from 130 to 330 days to reach Mars. For NASA's Mars missions, the average travel time is approximately 225 days, or about eight months. This is a long time, so you should definitely pack snacks and movies. The Mayflower took just over two months to cross the Atlantic. The journey to Mars is about four times longer than the Pilgrims' journey from Europe to North America.
We will not model the rocket as its boosters are firing. Instead, we will set the initial velocity of the rocket as 5 km/s at a distance of 5.6 earth radii ($5.6R_E$) from the center of Earth. (This is an altitude of $4.6R_E$ from Earth.) Then we will try various launch days and launch directions for the rocket at this distance from Earth.
In writing your simulation, use the following assumptions:
1. The initial position of the rocket is $5.6R_E$ from the center of Earth. You can place the rocket at any point around Earth because the distance from Earth is small compared to the entire orbit of the rocket. Where on Earth it is launched should have a small effect.
1. The speed of the rocket at an altitude of 4.6 Earth radii is 5 km/s. You can set the direction to be any direction you choose. Let this be the rocket's initial velocity. This speed is chosen because it ensures that the rocket was able to escape from Earth and is sufficiently far from Earth at the beginning of the simulation.
2. The thrusters are off during the entire flight. The net force on the rocket is the gravitational force by the Sun, Earth, and Mars.
Find a direction for the initial velocity of the rocket and find a day to launch (using the initial positions of the planets in Exercise 1) such that the rocket travels to Mars. Your program will have to compute orbits for the rocket, Earth, and Mars. You will have to try many different combinations of launch day and launch direction. Use trial and error, but learn from each trial to improve your guesses.
Also, think about what it means to "arrive at Mars." Does it have to collide with Mars or merely get close enough that rocket boosters could conceivably change the orbit of the rocket?
### Exercise 4
Try different initial velocities and different days for the launch. Can you find more than one velocity and day that will give an orbit that will work?