Tip:
Highlight text to annotate it
X
Since you have so many different tasks to complete in this problem, let's go through them one by one.
First things first the moon position function.
Now we ask to start the moon off at moon initial angle.
So we define moon angle or the angle of the moon at a given time
as moon initial angle plus 2π times the time that has past divided by the total period of the moon.
So this is basically the fraction of its orbit that the moon has gone through so far.
We then created a 2-dimensional array for the moon's position
but looks like the horizontal position in this drawing is equal to
the distance between the earth and the moon or moon distance
times the cosine of moon angle and the vertical position is the same except use a sine instead.
So next comes the function of the acceleration of the spacecraft.
Now let's talk about gravity for a second--we know that the gravitational force
that one body feels as a result of another body is dictated by Newton's law of universal gravitation.
We know that our spaceship is going to be pulled towards the earth and also towards the moon.
So we need to take into account how the
acceleration would be affected by both of these objects.
Since we're interested in acceleration rather than force,
we can use Newton's second law along this law of gravitation
to come up with an expression for the total acceleration of the spaceship.
To figure this out, however, we need information about the relative position of our three objects.
So we started in the acceleration function by declaring a new variable called moon pause,
which is just equal to the moon's position at any given time.
Now we can define a vector from the moon to the spaceship, this green vector right here,
as just the position vector of the spacecraft minus moonpos.
Since moonpos is just the position vector of the moon.
Then we can define a new variable called acc or at least that's what I'm going to pronounce this word.
Using the equation of the acceleration due to gravity.
We really owe Isaac Newton a lot of credit in this problem
consider we're using two of his different laws.
So you can see modifying his law of gravitation using the second law give us an expression
for the vector sum of the total acceleration of the spacecraft.
Here everything with a subscript as it stands for spacecraft.
Now our next task was to make the velocity changes happen.
If the first shift in velocity has not happened yet but it's after the time
at which it was suppose to happen, then we decreased the velocity by 7.04 m/s
but keep the spaceship moving in the same direction
by dividing our quantity by the norm of the velocity vector and then multiplying it by this vector again.
We do pretty much the same thing for boost
but this time we replaced the time with the correct value 212,100 seconds.
In each case since you've changed the velocity in the way it's prescribed,
you can change the proper booleans to true.
Now finally we get expressions for velocity and position using Heun's method.
Right here we have a simple translation of his equations into Python.
You can see Euler values with the e's and Heun's values with the h's .
At the end of this, we set velocity and position equal to velocity h and position h.
So that each time we go through another iteration, they will shift to equal the new Heun's values.
Now in order to adjust the step size for each position of the spacecraft,
we need to know the difference between Heun's and Euler values for position and velocity.
You'll remember that we use this to calculate the error.
Then the new step size is set as prescribed here in this line of code.
Since we're up finishing up the step in which h, the current step size is valid,
we add this to the current time and now that the next time step is about to happen,
we set h equal to h new--updating its value.
So this explains why we use h in the equations for Heun's method
but are still able to lock the value cycle.
Since our program is now complete, we can run it using different values for boost.
We're getting zero as a value to start out with but let's try -10 first
so we can check out one extreme of the range that we gave you.
But a boost of -10 m/s, we can tell that the ship is pretty far away from touching the earth
and then when we extend the path out again, it travels past the moon's orbit.
We can clearly tell that this is not right.
We definitely want to make sure that the crew actually gets back to the earth
not just circles around again.
Let's try a different value.
Now since 100 is the largest value that we gave you to try, let's see what happens with that.
Well that certainly looks different from the last plot that we saw.
Though, this also doesn't look exactly right.
So up close we can tell that it looks like the ship is actually crashing into the earth
and that's definitely not what we want to happen either.
We wanted to just barely scan the surface.
Zooming out again, you can see that the tail of its trajectory
doesn't reach out to the radius of the moon's orbit like we said that it would.
So the correct value for boost is in between these two values at 10 m/s.
Here is the solution plot. This looks perfect.
You can see that the spaceship takes off, loops around the moon, comes back
and just cruise the surface of the earth, and then, if we let it go out again,
it will return to exactly the same radius that it left to initially.
This is a really complex problem so great job for getting it done.
The fact that we're done talking about spaceships and orbits, I get excited for Unit 3.
We're going to talk about how diseases spread to the populations.