These are draft notes from subtitles. Please help to improve them. Thank you!
Welcome to the first unit of our course on differential equations and simulation. In this unit and the next, we'll look into how to bring the crew of Apollo 13 back to earth. We start with writing programs that model the orbits of the moon and of the spacecraft around the earth. This unit contains quite a number of supplementary segments to bring everybody up to speed. If you know your way around derivatives and vectors and elementary Python programming, feel free to skip directly to the quizzes of those segments.
Now let's take a closer look at what happened with Apollo 13. The rocket is already in a parking orbit around earth. To take us to the moon, the rocket is fired again, this will result in such a trajectory. This phase here is called "translunar injection." This trajectory is a so-called free trajectory. It's going to return safely without the astronauts doing anything about it. So in case anything breaks, they are going to return, no matter what, just by gravity. The first thing that happens was planned, namely, to get rid of the rest of the rocket, which eventually crashed on the moon. The second thing was planned as well. A midcourse correction, MCC. The objective was to take the spacecraft to a trajectory that's closer around the moon, but there was a price to pay. This trajectory no longer was a free return trajectory, but eventually they'd not return to earth. So that is an unsafe trajectory. What everybody learns somehow was after that when one of the O2 tanks exploded. Now the spacecraft had to be taken back to earth as quickly as possible. The solution was to fire the rocket again. This maneuver was called DPS-1 for distant propulsion system. The rocket that has been fired actually was the rocket that was intended to safely land on the moon. This has to be fired in such a way that we are taken back to a free return trajectory and eventually return to earth. What's going to occupy us this next unit is how to compute the right amount of acceleration the spacecraft needs at this point in time.
When we simulate the trajectory of Apollo 13 around the moon, which of these are of vital importance, which are somewhat important, and which are not important at all? The mass of the spacecraft, the size of the moon, the motion of the moon around earth, the size of the earth, the motion of the earth around the sun, and what about 3D? Should we be doing this in a 3-dimensional fashion?
Astonishingly, the mass of the spacecraft is not important at all. Imagine that you have 2 spacecrafts going along the same trajectory. You could join these to form a spacecraft of twice the mass, and that would still follow the same trajectory. So the mass is of no importance-- the mass of the spacecraft, that is. The size of the moon. Well, we should not be hitting the moon, but otherwise the size of the moon is not of importance. The motion of the moon, however, is of vital importance. We have to take care that the rocket is fired into empty space and the moon eventually appears in the right place. The size of the earth is of vital importance to get close to the surface as we return. The motion of the earth around the sun isn't that vital. And should we be treating this as a 3-dimensional problem? Imagine the earth as a sphere and the moon as a sphere, and the trajectory takes us around earth, around the moon and back. This looks very 3 dimensional should we be dealing with xyz coordinates. Actually, however, this trajectory is mostly in a plane. If you look at that motion from above, we see planar motion, and it's almost okay to treat this trajectory in a 2D fashion.
This is a supplementary unit in case you've forgotten how sine and cosine and their friends work. You may directly skip to the quiz to check your knowledge. Sine and cosine and their friends are about right triangles. This is a right triangle, a triangle that has a right angle; a and b are the legs of the right triangle; c is the hypotenuse. And I'm interested in that angle, which I call beta. Once this angle is specified, the ratio of every 2 of these sides is fixed. For instance, b divided by c is fixed once beta is given. That's called the sine of beta. And a divided by c is given once beta is known. That's the cosine. If we have a different right triangle, with the same angle beta, you see, in this case, the leg b shrinks at the same ratio as the leg c shrinks. So this ratio b over c stays constant. Same for a divided by c; a shrinks, c shrinks at the same ratio, this ratio, a divided by c stays constant. It's a function of this angle beta alone. In daily life, you would specify beta with angular degrees: 45°, 90°, 180°. In mathematics and in most parts of computer science, you do not use angular degrees. You use radians. The idea is the following: You look at the unit circle, a circle of radius 1. If this is the angle I want to express, 90°. I'm not using the number 90°, but I'm giving the length of the part of the circumference that I am cutting off here. The total circumference would be 2π, a circle of radius 1, so this would be π divided by 2. And that's the angle in radian. 90° becomes π divided by 2; 3.14 and so on, divided by 2. A very ugly number. If I want to specify 45°, that's of course just half of that number; π divided by 4.
So 60°. What would that be in our new units? ½? Or is it 1 radian? Or is it 2 radian? Or is it 3 radian? 0.1 radian. How many degrees would that be: 6°, 7°, 12°, or 24°? And if we have this right triangle, which has an angle of 40 angular degrees here, a right angle here, a hypotenuse of 10 units, how long would this leg be? Would it be 5.0 units, 6.4 units, 6.5 units, 6.6 units?
60 angular degrees is about 1 radian. That's easy to remember once you get used to it. But remember, it's ABOUT 1 radian. It's not precisely 1 radian. 360° is 2π. 2π is 6.28 something. 60° is a 6th part of it, a 6th part of 6-point something is 1. And now we can work backwards. If 1 radian is 60°, then 0.1 radian should be 6°. And this requires the use of a calculator, I guess. The ratio of this leg to the hypotenuse is the sine of 40°, so what we are needing is the ratio of this leg to this hypotenuse is the sine of 40°. The number that we are looking for would fulfill the following: that number divided by 10 is the sine of 40°, which means multiply both sides by 10. We need the sine of 40° multiplied by 10, which is about 6.4.
Now we can come up with an equation for the motion of the moon around the earth. The earth should be sitting at the origin of our coordinate system. The moon should be starting on the x axis and should be moving in a counterclockwise direction. Of course, there's something with cosine and sine. Specify the details. What do we have in front of the cosine and sine? Is it 4 x 10⁸ m, is it 27 days, is it 2.5 x 10⁻⁹ m, or is it 2π x 27 days? What's on the inside of cosine and sine? 2π x t, or t, or π x t? Then times, or divided by? 27 days, or 4 x 10⁸ m?
The cosine outputs the ratio of 2 lengths which means that the unit of measurement that the cosine returns is 1. The cosine does not return meters or kilograms, it returns bare numbers. So whatever is in front of that cosine determines the measurement unit of the result. The result is not measured in days. We can immediately reject these. The result is measured in meters. It can only be this one or that one. The cosine and the sine range between -1 and +1. If you multiply by something x 10⁻⁹m, We would be dealing with very, very tiny lengths. That's not what we are into here. It has to be the first one. This is the radius of the orbit of the moon around the earth. Let me do these in reverse order. The radius of the orbit of the moon should not appear inside here. This has to do with the period of the moon's orbit. How long does it take the moon to make one full orbit around earth? 27 days. It must not be the meters. Which is also clear from the units. If we have meters in here, something has to cancel the meters. We have to have an angle in here. If we speak of radians, again, something without measurements units. There must not be any measurement unit in here. If it were meters, these meters would have to cancel somehow. How would I do that? Not with time, obviously. Seconds or days don't cancel with meters. Once we are here, it's clear that we have to use the division. Days divided by days. This gets rid of the measurement units. We can't mulitiply by days, otherwise we would be getting days squared. And the remaining choice, 2π x t. Not this one. Not this one. If we let t grow by 27 days, 1 complete period, the numerator increases by 2π x 27 days. And this ratio increases by 2π x 27 days, divided by 27 days, by 2π. As t advances by one period, this ratio advances by 2π, but that's precisely what we need for cosine and sine. The angle has to advance by 2π 360°. One full revolution.
This is a quick overview on the concept of velocity, which is more or less the same as the concept of derivative, which could be called rate of change in general terms. If you are already acquainted with it, you may want to skip to the quiz. Imagine this situation: that we have a high-speed train on the track that is labeled from -100 km to +100 km. So the track is 200 km long. And this is our timetable. The train starts here at -100 km, and drives at a pretty high speed for 1½ hours after the start. Then it stops at this position, 50 km. It continues somewhat slower for 1 hour, 'til it reaches that position at +100 km. Then it immediately returns to the position x = 0, 4 hours after it started. This is, if you will, a mathematical view of the train's time table. Let's rotate this by 90° to get something that's more typical for physics. So now I've taken this diagram and rotated it by 90° to come up with that diagram. The t axis now points to the right, and the x axis now points upward. We can create a second diagram from that that shows the velocity. So here the train advances at 100 km/h, here it's just 50 km/h. Here the train goes backward at 100 km/h. So maybe a good idea is to label this axis with +100 km/h and -100 km/h. So here we have a velocity of +100 km/h, here too, and then the train stops, which means we have a velocity of 0. And here the train starts again and makes 50 km/h which is just half as much as before. And here we are going backward with 100 km/h as its speed, so the velocity is -100 km/h. This is what the velocity looks like. So if you're going forward, it's positive, if you're going backward, its negative. So what we see here is the velocity of the train, depending on time. That's nothing but the rate of change of the position, which we call x, by how much x changes if a certain amount of time passes. The rate of change would be the ratio. For instance, this ratio: 100 km divided by 1 hour-- the velocity of 100 km/h. In this case, the ratio would be 50 km divided by 1 hour; 50 km/h. So what we are drawing here is the rate of change of the x position, nothing but the velocity, and this is the very same as the derivative. The derivative tells us the local rate of change. Here the derivative is 100 km/h, here it's 0, here it's 50 km/h, and here it's negative. As the time advances, the x position decreases. A negative derivative, negative velocity, negative rate of change. The standard way of writing that: v of t, the velocity depending on t. One way of writing it is dx of t by dt, or x prime of t, or, and this is what the physicists are using, x dot of t. I'm going to stick to that notation. Whenever physicists want to compute the rate of change, with respect to time, they put a dot on top of that variable.
Assume that this is the curve that describes the dependence of position on time. What would be the curve that describes the dependence of velocity x dot on time-- the red one, the green one, the purple one-- and this is getting a little more complex. Assume that this is again a curve that describes the dependence of position on time. What about the second derivative? If you repeat that same process again-- the derivative of the derivative, the rate of change of the rate of change-- that's nothing but acceleration. Acceleration is the rate of change of velocity. How quickly does velocity change? So what would the acceleration be on the red curve-- the green curve or the purple curve.
If this is the position, we see that position always increases with time. There is no way that the derivative can be negative, that the rate of change can be negative. Otherwise, the position would have to go down if that was the case, so we can rule out the red version. Now let's look at this step, almost a step. We need to ramp up the velocity and ramp down the velocity. Here, we accelerate, and here, we decelerate. Okay. And this is an almost precise replica of that one, so the same shape--it has to be the green one. It cannot be the purple one. Now for this curve, we accelerate positively The velocity grows. You see that we start with small velocity. The velocity gets larger as we go up to that point here. So acceleration has to be positive. The rate of change of velocity has to be positive, which rules out the green curve. We are left with deciding whether the red curve is the right one or the purple curve is the right one. Look at this part of the curve. The position is decreasing. If position is decreasing, velocity has to be negative. See, we start with a velocity of almost 0, and then the velocity becomes very negative. This is very steep. The rate of change is very high in a negative direction, which means that we need acceleration to the negative--strong negative acceleration. It has to be this red part. It can't be that green part. And here, acceleration is positive again-- --high and positive-- to turn that negative velocity into a velocity of 0. We got a positive peak in the acceleration. And eventually, the acceleration is 0, the velocity is 0, and the rate of change of the position is 0, so it's the red curve.
Now let's come up with some concrete equations for derivatives. For instance, if this equation describes the dependence of my position on time, the position should be (t + 1)3. Actually, we are ignoring physical units of measurement right now. What would the rate of change be? Let's magnify a portion of that curve. It's saying this is sometime t, and this is, a little later, t + h. Throughout this course, h will denote a small increment of time. Then the x value here is (t + 1)3, and the x value here is (t + h + 1)3. And the question now is what the rate of change is. What you're interested in is the ratio of the gain in x to the times step that we're making. This side obviously has a length of h, and this side has a length of (t + h + 1)3 - (t + 1)3. So let's write down the ratio-- (t + h + 1)3 - (t + 1)3/h. Now comes the question, if h is really small, what would this expression become? Would it become t + something that can be neglected for every tiny h? Would it become (t + 1)2 + something that we can neglect, 3t2 + something that can be neglected or 3(t + 1)2 + something we can neglect?
Let's spell out what this first means-- (t + h + 1)^3-- here comes the trick--I write it as ((t + 1) + h) * ((t + 1) + h) * ((t + 1) + h). I just reshuffled the different terms-- t + 1 + h, t + 1 + h and 3 factors of that sort.gives the 3rd power. What do i get? (t + 1) * (t + 1) * (t + 1) = (t + 1)3. Then I get terms of that sort-- h * (t + 1) * (t + 1), h * (t + 1) * (t + 1) is, of course, (t + 1)2. How many terms of that sort do I get? h * this one * this one is one of that sort. (t + 1) * h * (t + 1); second one, and (t + 1) * (t + 1) * h; a third one, 3 terms of that type plus everything else has h^2 in it-- h * h * (t + 1) or (t + 1) * h * h or even h * h * h, So, whatever happens to pnx as the h^2 * something. So what do we get? 1/h(--t + 1)^3, (t + 1)^3 cancels--1/h(3h(t + 1)^2 + h^2 *(something). And look what happens--we divide by h. h/h cancels, h^2/h becomes h, and in the end, we are left with 3(t + 1)^2, and this term is negligible, So the answer would be 3(t + 1)^2. Of course, you may already know that there's tons of rules how to compute derivatives In the end, they're just shortcuts of such computations.
Now let's apply derivatives to physics-- Newton's Second Law of Motion. We're looking at one-dimensional motion. Think of the train we saw before. Some force is exerted on object of mass m. What does happen? The velocity of this object changes. And Newton's Second Law describes that relationship. The mass times the acceleration is that force. If you keep the same object, the same mass and double the force, we double the acceleration-- the change of velocity. If we want to accelerate an object of twice the mass, we need twice the force. Mass is measured in kilograms internationally. Acceleration is the rate of change of velocity--v-dot-- the derivative of the velocity with respect to time, or as velocity is the derivative of position with respect to time, the derivative of the derivative of the position with respect to time. Velocity is meters per second internationally, and the change would be meters per second-- per second by how many meters per second, thus the velocity change per second-- That is m/s^2. Force is given in kg. * m/s^2, and there's a short name for that--Newtons-- because obviously, Newton was the one to find this.
Close to the surface of the earth, every object experiences an acceleration of 9.81 m/s2. This is independent of that mass of the object because assume that you have two objects of the same mass. Each one is accelerated at the same rate. So they stay on the same height as they fall, which means you can combine these two objects, add a little glue. and this larger object is going to fall, but the same acceleration. But now it has twice the mass. Based on this, you should be able to answer the following question. What's the gravitational force of a mass on 1 kg.-- 0.1 N, 1 N, 10 N or even 100 N?
We apply Newton's Law--F = M X A. The mass is 1 kg.; the acceleration is 9.81 m/s2. So in total, we have about 10 kg. X m/s2, which is 10 N. This gives you an idea about this unit of 1 N. The weight force of a mass of 100 g. is almost equal to 1 N.
So now we have equations that govern the rates of change of the position and the velocity. The rate of change of the position is the velocity, and the rate of change of the velocity is the acceleration, which is by Newton's law, force divided by mass, and in a typical setting, we also know the position at time 0 and the velocity at time 0. Now we are going to use the computer to learn what these equations are leading to, and the easiest way for doing so is called the Forward Euler Method. The most complex thing about that method may be the name of Euler. Euler was born in Basel, Switzerland, that is. Most people these days use the German pronunciation of his name--Euler--even though the Swiss pronunciation may be different from that, and in the U.S., you may also hear the pronunciation Euler. I try to stick to the pronunciation Euler, but forgive me if I, from time to time, fall back into saying Euler Euler's idea was to solve these equations by walking in small time steps. If we start at the initial position-- x(0) and the initial velocity--v(0), what would happen after a short timespan we call h? The position would approximately increase by h times the velocity. If the velocity is 2 meters per second, and we wait for 3 seconds, we will be changing the position by 6 meters, for instance. But, of course, we're using a much smaller time step. Similarly for the velocity, after some small time h, the velocity will be its original value plus the time step times the acceleration, which is F/M. So these equations will take us from time 0 to time h appxoimately. I'm cheating a little when I write equal signs here. In the same fashion, we can get from time h to time 2h doing another step. This is what this second step looks like. We know the position that we have reached at the end of the first step, and we continue with the new velocity, and that results in the new position-- similarly for the velocity. You iterate this process over and over again and find estimates for positions and velocities as you go.
Now apply the Forward Euler Methods to the following situation: We drill a big hole and let a mouse fall into that hole. The mouse starts at height 0 and at velocity 0. The height is going to be our X coordinate. That means that x(0) = 0. V(0) = 0, and a(t) = f/m = -9.81 m/s2-- minus because the velocity is going to become negative. Your job is to provide the appropriate code to compute the t and x and v values for all steps. We create these arrays with 51 entries so that the entry number 0 can be the initial value, and you compute 50 additional values for each array.
In our solution, we always compute the t and x and v value at the beginning of the next step, and you make use of the fact that the entry numbers u(t) and the entry numbers u(x) and the entry numbers u(v) are already equal to 0, which is what we want. If you run the program, you see that per second, the velocity decreases by 10 m/s. It starts out at 0 and keeps decreasing, which means the speed, the magnitude of the velocity keeps increasing. This falling object gets faster and faster, but in a negative direction, which is our x coordinate starts at 0 as intended. It decreases slowly and then faster and faster. You see gravitational acceleration in action.
One dimension in motion is not enough for us. We need 2 dimensions or even 3 dimensions. We need vectors. If you know about vectors directly, skip to the quiz. If you don't, stay with me. Vectors can be represented by arrows. Typically, we denote vectors by lowercase Latin characters with an arrow on top of them, and we can also express them in numbers. This arrow vector is 4 units to the right and 3 units up, which is why we can write (4 3) in this way. These are called components of the vector--x component, y component if the x axis points right, and the y axis points up, Let's look at a second vector. If you call this vector B, that would be (2, 1) x component 1, y component 2. Let's have a third vector that's called C, and C should be (1 - 3). C goes right by 1 unit and goes down by 3 units. And now we can do some basic arithmetics. We can add vectors, for instance. Let's add B and C. If we want to add B and C, we put them together. The tail of C goes to the tip of B or the other way around, and the resulting vector, which is B + C goes from the tail of B to the tip of C. So this is the sum of the vectors-- B + C--and if you look closely, you'll see this is 1, 2, 3 units to the right-- and this one is canceled with that one-- and 2 units down. So what we actually could've computed is the x component of B plus the x component of C--3-- and the y component of B plus the y component of C makes 2. That's the sum of vectors. You simply add the components, and geometrically, you chain these arrows. And there's a second operation we can do. We can multiply vectors with numbers. For instance, if I want to multiply this vector B by 3/2, I get an arrow in the same direction, but with 50% more length. I can do that in components, of course, as well. So what I get is (3/2 * 2 3/2 * 1), which is 3 and downstairs 1.5. Obviously, 3 units to the right, 1.5 units up. If you do this multiplication with negative numbers, we are going to invert the direction of the arrow. So if I compute, say, -1/2B, I get an arrow of the opposite direction and 1/2 the length. and components -1/2 * 2 = -1, -1/2 * 1 = -1/2. So this goes 1 unit to the left and 1/2 unit down. If you remember the NumPy pickle in Python, this vector addition and vector multiplication and the NumPy pickle in Python. this addition and this type of multiplication is already included. The third operation that we can apply to all vectors, is determining their lengths. I'm writing it like that with double bars. To determine the length, you can simply use the Pythagorean Theorem. One leg of this right triangle is 4 units long. The other leg is 3 units long, which means that the hypotenuse is 4^2 + 3^2√ units long, which means 16 + 9, 25√, 5 units.
What is the sum of these 2 vectors--which one of these 4? If we take twice this vector minus this vector, what do we get--which of these four?
To form the sum of these 2 vectors, take this vector and put its tail to the tip of this vector, and you'll see what's resulting--this vector. So the last one is the right choice. If I take twice this vector, I get this one. plus the negative of this one, which is this one, and eventually, you'll see the first choice is the right one.
We know that a mass of 1 kg. experiences a rate force of about 10 Newtons on the surface of the earth, but for space travel, we need to know more. What's going to happen if it double the distance between our mass and the center of the earth? For instance, what's going to happen if we double the distance between our mass at the center of the earth? Obviously, the force is shrinking, but by which factor? It turns out that as we double the distance, we have only one quarter of the force. If we tripled the distance, the force goes down to 1/9, which means that in our creation for the force of gravity, we have to have a distance squared in the denominator. If we use twice the mass, we should have twice the force, so the mass appears in the numerator. And if all masses are created equal, the mass of the earth should have the same role, so the mass of the earth, too, should appear in the numerator. From the units of measurement, you can see that this doesn't work out so far--kg.^2/m^2 That doesn't look like force-- this universal constant appearing in front-- the constant of gravity, which is 6.67 * 10^-11, N * m^2/kg.^2. These units are pretty much of human scale-- Newtons, meters, kilograms--and you see that gravity seems to be pretty small on the scales. The force exerted by 2 masses of 1 kg. each and a distance of 1 m. would amount to 6.67 * 10^-11 Newtons-- a pretty small force. This is why we need something as big as a planet to see gravity in action.
Now it's time to compute the mass of the moon. We know that the gravitational acceleration on the surface of the moon is about 1/6 of that of the earth or 1.67 m/s² to be precise. We know the radius of the moon, which is 1.737 * 10⁶ m. Now you can compute its mass. Enter a number with one decimal place in this first text field and an integer number in the second.
The force on this mass refers to mass times the acceleration, which is 1.63 m/s², but we know where this force comes from-- namely, from gravity, so it has to be equal to the constant of gravitation times the product of the masses, the mass of the moon--let's call that m1, times our mass, m2, divided by the distance squared. The distance is the radius of the moon. Now let's ignore this part of the equation. Then you see that m2, the mass of our object, doesn't matter, and we can solve for m1. If you plug in the value of the constant of gravity and do the math, you get 7.3 * 10²² kg.
Actually, by the book this equation for gravity--this equation for the force of gravity-- is only true for point masses. We would have to concentrate all of our earth in one single spot. Do we cheat when we don't do so? The nice thing about gravity is that this equation still holds for a rotationally symmetric distributed mass. This is called Newton's Shell Theorem, and you are going to see in the upcoming quiz why this is called "shell" theorem. To see why Newton's Shell Theorem holds, it's best to introduce an analogy to water. This looks outrageous, but please bear with me. If we leave our first mass where it is and move the second mass around, we can determine a force vector at every point in space. We get a force field. Imagine that this wasn't the solar system but a pool of water, and the water has velocities, and the velocity of the water is described by our force field. Water flows downward here at a high speed. It flows to the right at a low speed at this point. It flows to the left at a somewhat higher speed at this point, and so on. We interpret the force field a velocity field in our pool of water. Of course, we're ignoring the units of measurement right now. Of course when setting force equal to velocity we're ignoring units of measurement for a moment. To make that work, there has to be a huge drain in the center. The first mass acts like a cosmic drain. Why can we do so? Why does water behave in the same way as this force field does? To understand that consider two imaginary spheres in our pool, but centered at the drain. The radius of the outer sphere should be twice the radius of the inner sphere, which means that the surface area of the outer sphere is 4 times the surface of the inner sphere. All links are being multiplied by 2. These are square meters They are multiplied by 2 squared. Now the important quantity to consider is the flow of water through these spheres. How many cubic meters per second flow through these surfaces? This number has to be the same for the outer and for the inner sphere. We are not losing water or gaining water in between, but as the outer sphere has a surface area of 4 times that of the inner sphere the velocity has to go up to transport the same amount of water per second through each of these spheres the velocity at the inner sphere has to quadruple as compared to this velocity at the outer sphere. This is precisely what we saw before with gravity. As we double the distance the force shrinks to 1/4 of the original. Of course, this doesn't only work for a factor of 2. This works for all ratios. Hence, we can indeed identify the force field of gravity with the velocity field of water. Once this analogy between gravity and water is in place, it's easy to see that the flow through each of these surfaces has to be the same. Let's assume that we have three masses at the center of this sphere. This same masses are at the center of that smaller sphere. The same three masses are somewhere inside this weird closed surface. Then the flow through each of these seems to be the same. If we replace the force field of gravity by the velocity field of water, we have to seem the same number of cubic meters per second for each of these surfaces. Because we're draining water in three spots at the same rate. Somehow that amount of water has to enter from the outside. It has to be this same amount of water, because we're draining this same amount of water in each of them.
With the help of this analogy between gravity and water analyse this case--a huge spherical object of constant density in which we drill a hole that's half the radius deep. Now we put a test mass on the surface to position, and in that hole, that position. What's the ratio of the force of gravity in the blue position to the force of gravity in the red position. Are these two forces equal? Do we have twice the force at the surface or do we have twice the force at the inner point? Or is it four times on the outside or four times at this inner position?
As we go deeper the force of gravity shrinks, and it does so by a factor of 2. Let's see in detail why this has to be the case. The trick is to add an imaginary sphere of half the radius. Then we can look at the force from the core part and the force from the shell, and this is where the name "shell theorem" comes from. The core part is again a sphere. S is the complete object, so we can compare what's going to happen as we go from the large sphere to the small sphere. Distance is multiplied by 1/2 as we go down that hole. The mass is multiplied by 1/8 as we are shrinking the original sphere to half of its radius. We're shrinking the volume to 1/8. Hence the mass to 1/8 of the original value. If we take these two together, the original force will be multiplied 1/8, because the mass appears in the numerator, divided by 1/2 squared, because the distance squared appears in the denominator. In total, this is a factor of 1/2. To see what's happening with the force from the shell, let's put an imaginary sphere close to the inside of that shell. If there is a gravitational force on the surface of that sphere, it has to be rotationally symmetric, for instance, like that. Can this be? No. Where would the water be flowing? We would have to drain that water somewhere, which we don't. Can the force points to the outside? No. Where would that water come from in the first place? The only reasonable value for the magnitude of the force is 0. Hence, in total, the force goes down to 1/2 of its original value.
Now we want to put numbers to gravitation and do this in 2D, which means we need to have vectors. Let's place the earth at the origin. The moon sits at a vector xm. The spacecraft sits at a vector xs, and we need the distance of the spacecraft from the moon. Let's call that dms, and we need the distance of the spacecraft from the earth. Let's called that des. Now we can put both of Newton's laws together. The mass of the space craft times its acceleration as a vector now equals the force that is exerted on the spacecraft. This force stems from gravity. It has two components. One is the force that is exerted by the earth. The other is the force exerted by the moon. So, the force exerted by the earth would be gravitational constant times the mass of the earth times the mass of the spacecraft divided by the distance between them squared times a unit vector, that is, vector of length one pointing to earth--something like this. For the moon, we get the gravitation constant times the mass of the moon times the mass of the spacecraft divided by the distance between them squared times a unit vector pointing to the moon. How do we get these two vectors? For the first one we can take minus xs-- that's a vector that takes us from the spacecraft to earth-- and divide by the length of xs, which is nothing but des. For the second one, we can take the difference vector xm mines xs-- that's the vector that has its tail at the spacecraft and its tip at the moon--and we divide by the length of that vector, which is the distance from the moon to the spacecraft. Now, let's forget about the force. Then we see that the mass of the spacecraft cancels. What we need to know are the mass of the earth and the mass of the moon.
Now the task is to actually write a Python function to compute the acceleration that we have derived before. The mass of the earth and the mass of the moon and the gravitational constant are already given in that code. The function that you should write gets the position of the spaceship as 2-dimensional vectors and should return a 2-dimensional vector that describes the acceleration of the spaceship. There is one nice function of of the NumPy package that you will be needing, namely, the normal function which computes the length of a vector.
You may want to introduce auxiliary variables such as, for instance, this vector from the spaceship to the moon and this vector from the spaceship to earth. Then the rest is simply Newton's equation. We're dividing by the second power of the distance from the space craft to the earth. You're combining all occurrences of the distances of the distance of the space craft to earth in this single place which is the third power of the length of the vector from the spacecraft to the earth. The same occurs here with the moon.
Now we have reached our first real world differential equation-- the second derivative of the position vector of the spacecraft, which its acceleration vector, equals the gravitational constant times the mass of the earth times a vector that points from the spacecraft to the earth divided by the 3rd power of its length. This boils down to the 3rd power of the distance between the spacecraft and earth. Now comes the component due to the moon-- gravitational constant times the mass of the moon times vector from the spacecraft to the moon divided by the 3rd power of its length. This is a differential equation--an equation that governs or is governed by rates of change. The acceleration vector is the rate of change of a rate of change. This actually is a system of differential equations. It's not a single equation. We've got two components in here. Each of these two components has to fulfill this equation. The highest derivative that occurs is the second one, which is why we call this differential equation a differential equation of order 2. The highest derivative stands alone on one side and does not occur anywhere else. This is what we call explicit. If the highest derivative was hidden somewhere, we would first need to solve that equation, which is ugly. These two terms mean that this differential equation is nonlinear. A linear differential equation would only contain terms such as 42 times xs or sin(t) * xs.
Look at these equations. What is their respective order? Are they a system or not? Are they explicit or not? Are they linear or not?
The highest derivative here is the first one. The highest derivative here is the second one. Here it's the first one again. That' the order--1, 2, 1. The first one isn't a system. It's just a single equation. The second one either. The third one is a system--two equations. The first one is explicit. The highest derivative appears on one side alone and no where else. This one is not explicit. The highest derivative is hidden inside the sine. Same here--the highest derivative-- one of the two highest derivatives, I should be saying-- is hidden, so this one is not explicit either. This one is linear. In this case, we have the sine of the function we're looking for. This is not linear. In this case we have the square of the function we're looking for, which, again, is not linear.
What did we achieve in this unit? We found a differential equation that governs the motion of that spacecraft around the earth and around the moon. We know a simple solution method to solve differential equations on the computer--the forward Euler method. There is lots of stuff left for Unit 2. We have to actually solve that differential equation, and it turns out the forward Euler method isn't quite the method to be using. We have to actually solve the differential equation by computer. It turns out the forward Euler method is some what too simple for that purpose. Of course, we have to eventually find a trajectory that's going to bring Apollo 13 back to earth.
Hi! I'm Miriam and I'll be the assistant instructor for CS222. Now, I personally think that Math matters a lot but I know there's some skeptics out there so hopefully by the end of this course you'll know better. This is the first course that I'm working at Udacity and I'm really, really excited to be part of it. Aside from the fact that I really love Math and Physics and learning about pretty much anything, I'm a yoga teacher and I really love to bake anything. I'm not really into cooking though. I really only like baking sweet things like pie and cake and brownies and cheesecake and kind of anything that taste good. In terms of this course, I'll be helping you guys out on the forums and by filming to explain the problem sets. So now that you know a little bit more about me, I'm looking forward to seeing you in the forums and good luck in the class.
In this problem set, I want you to create a function that models the orbit of the moon around the earth. We're going to assume in this case that the moon's orbit is perfectly so circular, which means that we can model it using just sine and cosine functions. This assignment should then help you practice translating simple mathematical ideas into expressions in Python. So if you look over at the supplied code right here, you can see that we've helped you out with some pretty important parts of the code already. We've already told you that the moon's distance from the earth is 384 million meters, and we've also defined a function called orbit for you. Inside orbit, you can see that the number of time stops that we're going to look at as the moon moves in its orbit around the earth is 50. We've also created a 2-dimensional array called x, which is initialized with zeros. The number of arrays in x is equals to the number of time steps in the moon's orbit plus 1. The reason for this is that if you're watching the moon step around the earth 50 times, then the number of positions that we're actually looking at it is 50 + 1. Looking back at x, we see that there are two columns in the array-- one for the horizontal position of the moon compared to the earth and one for the vertical position. One important thing to note is that the cosine and sine functions from Python math library that we're using in this problem, take arguments that are measured in radiant not in degrees. When you finish filling in your code here and run the program, you should get a plot of a circular trajectory of the moon around the earth.
In the solution to this problem set, we've added a for loop with index ranges from 0 to the number of steps. We put the number of steps plus 1 as the argument for range because i will go up to the number inside minus 1. Inside the loop, we've created a variable called angle, which is equal to 2π times the index divided by the number of steps that are taken in the trajectory. Have you look over this picture. You can sort of see what's happening. The moon starts in this position, then after 1 time step, it's sent to this position and so on and so forth. The number of segments will equal the number of steps and the number of lines will equal the number of steps plus 1. After this, we use the right x to define the horizontal and vertical positions of the moon at any given time step. It's at this point that we have to remember our trigonometric functions--sine and cosine. In this first line right here, we're defining the horizontal position of x for the ith time step. In the second line, which is a sine, is what's going to show us the vertical position. This is one of those cases where being able to see a right triangle in this picture is very helpful. Looking at our picture, this horizontal line right here that extends from the earth out to the moon's orbit is the zero radian or 0 degree line. We're measuring all of the angles that the moon is going to be marked at up from this line. That means that at any given moment, we can draw a line from the moon down to this horizontal line to create a right triangle, which will then allow us to use sine and cosine in conjunction with this angle to determine the moon's vertical and horizontal distances from the earth. Going back to our code, after all of these is filled in, if we run the program, we end up with a perfect circle, just like we were hoping to get for the trajectory of the moon around the earth in this ideal simulation.
Now it's time for us to get some practice with an application of the forward Euler method. At this time, we define a function for you called trajectory-- that's going to determine the trajectory of a particle. We've already set the step size the acceleration to the gravity and the initial speed of the particle. Inside the definition, we've created an array called angles that's starts out at 20 then increases with increments of 10 up to 70. This creates a set of angles that which the particle can take off. Over here, we see an example of what a ballistic trajectory of a particle with a given initial angle might look like. The next step is to create variables for position and velocity. Each of these is an array where the number of arrays equals the number of steps that are going to be taken plus 1 and 2 columns. Your job is to find equations for the position and velocity of a particle that show how changing the initial take off angle of the particle changes its trajectory. Form your code here and good luck.
So in this problem set, we're going to try to plot the trajectory of the spaceship by creating functions for its acceleration and its trajectory. We'll start it out with some helpful information. We'll set the step size to 1 second. It told you the mass of the earth and giving you the gravitational constant, which you might recognize as G from the equations in other videos. We've also already created arrays for you for position and velocity, which right now I filled with zeros and set the initial position and the initial velocity of the spacecraft. Now, I'm going to remind you of some information that you've already learned that's going to be especially helpful for this problem. We talked earlier about the equation for the gravitational force between two objects that's what this little g here next to the F for force ??? for gravity. This big G in the equation is its gravitational constant that we've given you in the code that's multiplied by the mass of the earth and the mass of the spacecraft and this is divided by the difference between the earth and the spacecraft squared. Now, this d with a hat over it represents a unit vector that any given vector has a unit vector associated with it. This unit vector, which is denoted by this hat over top of it, is equal to the original vector itself divided by that vector's magnitude. So this d with a hat over it up here shows us that the gravitational force has this magnitude and is pointing in this direction, which is a line pointing from the earth out to the spaceship. Now, if you look back at the code for a second, you'll see that this function that we're asking of you to find is actually for acceleration not for force, but we know that force and acceleration are very intimately related by Newton's second law, which is that force equals mass times acceleration. This means in the case that we're considering right now we can find the acceleration of the spaceship by simply taking the equation for force that we just read out and dividing by the mass of the spaceship, which leaves us with this expression right here. Your job is to translate this equation into an expression in Python for acceleration and then to use that expression along with the information we've given you in a forward Euler method to describe the position and velocity of the spaceship at any given time step.
So now, we're going to look at the solution to this final problem set for Unit 1. The first thing we we have to do is fill in the definition for the acceleration function. Now the acceleration function takes an argument that we've called spaceship position. So we can define the position of the spaceship in relation to earth with this variable vector to earth. A vector pointing from the earth to the spaceship is just the opposite of a vector pointing from the spaceship to the earth. So we define vector to earth as the negative of this argument, spaceship position. Now since we're trying to define the acceleration, what we want to return is an expression for acceleration. So we rate return and then a translation of this equation over here that we talked about earlier. So we have the gravitational constant which is G times the earth mass which is mE, divided by this expression that looks pretty tricky, so let's dissect that briefly. Now, the first thing we have right here is a method from a linear algebra library which gives us the norm or the magnitude of whatever vector we put into it. We, of course, are inputting the vector from the spaceship to the earth. Now over here, we can see in the original equation that the denominator is just the norm of that vector squared. Within the code, we have it to the 3rd power. Now, the reason for this is that we are also multiplying by that same vector again. Whereas in the equation we're multiplying by the unit vector. This means that in the Python version of the equation, we effectively have the magnitude cubed in the denominator and the magnitude to the 1st power, the numerator which gives overall a factor of 1 over the magnitude squared which is equally what we see in the original equation. This makes our job a little bit easier because we don't have to define a unit vector for the vector to earth. Now we move on to the definition of the function ship trajectory. Since we gave you all of these codes, we skip down here to this final four loops. This is something that we've seen several times before. For example, in the last problems that these two lines implement the forward Euler method to show how position and velocity are going to change with each step. Once we have all of this code filled in, we can run the program, and our final product is this picture. Now this picture looks a lot like what we would expect from elliptical orbit. We have the earth here and the spaceship moving around it. Everything looks pretty normal until we get almost to the end and we realized the ellipse actually won't close. This is a great example of how the forward Euler method is a method using approximations. If we are using more exact expressions for position and velocity, then we would end up with a closed ellipse and we can also play with the number of steps that we used to show how increasing the steps gives us a more exact approximation of the trajectory of the spaceship. Now we've done something that I think is pretty cool right here. We've changed the number of steps from 13,000 to 1.3 million. This means that since we cut the step size the same, this picture shows what the position of the spaceship would be like after much more time has passed after it has gone through many, many orbits. So even though in that initial orbit, the trajectory only seems slightly off. If we let that happen over and over and over again, eventually the spaceship will be much further away from earth than it was originally. Now, just to play with this example a little bit more, we've gone in and first change the step size, so that's 1/10 of the size that it used to be. This should give us a much more exact approximation since we're taking steps more closely together. However, we've also had to change the number of steps from the original 13,000 up to 130,000, so that we still have the same number of seconds total that the spaceship is in orbit which is a result of this changed code. At first, it might look pretty similar to what we had after we ran the program the first time. However, if you'd examine the end of the trajectory a little bit more closely, you can see that this tail looks like it's actually going to intersect the beginning. This time, it actually looks like the ellipse might close which we remember is what the trajectory in real life would look like. This is a great example of how changing the step size and using the forward Euler method can greatly decrease the area and the results we produce. In the next unit, we'll look at another numerical method that deals with similar situations but in a slightly different way.