Let's go over the solution to this problem starting with the definition of the acceleration function.
We know the acceleration due to gravity points downward.
So let's put this factor into two components.
We have one component right here that is parallel to the string of the pendulum
and another component that is perpendicular to this green one.
Now we know that the acceleration in this direction is going to be exactly cancelled out
by the acceleration due to the tension in the rope.
So that means that the acceleration we're looking for is really just this pink component,
which any point along the path is going to be tangent to the trajectory.
Now if we call this angle θ right here, we can figure out the length of this pink component
by just saying that it is equal to length of the resultant vector times the sine of θ.
The θ down here is actually exactly equal to θ in the diagram of the pendulum itself.
So that means to figure out the length of this component,
we can use information that we already know about this larger diagram.
Since position is just the arc link right here of this imaginary circle,
then the measure of that angle in radiant is going to be equal to the length of the arc
that it corresponds to divided by the radius of that circle.
So that means that in our case, θ is equal to arc length over radius or position over length.
So since θ equals position over length and we want the sine of θ,
we fill in our definition for acceleration as -g or negative
magnitude of the acceleration due to gravity times sine of the position over length.
Okay, moving on towards symplectic Euler function.
We have to fill in this for loop with the input num_initial conditions.
As I said in the InterVideo of the problem, we wanted the initial x to vary from 1.75 to 2.25
and the initial v to vary from -2 to 2
corresponding to the coordinates of every point along that green circle that I'd showed you.
Now a convenient way to make a variable cycle through values that are symmetric
about an equilibrium value is to use sine or cosine.
So we're going to keep that in mind.
Now as you learn from the circular orbit problem of Unit 1, if we consider any point
along the circumference of the circle, then we can define an angle that corresponds to that point.
These are coming from right here as a zero radian mark.
You can write the coordinates of this point then as the radius of the circle times the cosine of the angle.
That's for the horizontal component and for the vertical component,
we get the radius times the sine of the angle.
In the phase based plot that I showed you in the InterVideo, we saw that position lying along
the horizontal axis and velocity lying along the vertical axis.
So we wanted to plot the coordinates of the points on that green circle--the initial condition circle
where the position is going to correspond to cosine and the velocity is going to use sine.
Now I created a variable called phi. You could pick any name you want I guess.
And phi effectively split the circle into 49 segments
by marking out 50 different points along the circumference.
So every time I increases by one, we're going to step to the next point along the circumference.
Since as we saw in the phase base plot, we have a complete circle of green points.
The x values of those green points vary like this with 2 as the middle value
and the v coordinates vary like that.
You noticed that the amplitude in either case corresponds to the
half link of the green shape in that direction.
So actually we have in a phase base plot is an ellipse for that set of initial conditions.
Now that we have our starting additions figured out, we can finally use the symplectic Euler method
to proximate the values with x and v at later sets.
This code right here is just a direct transition pretty much of the equations that I showed you earlier.
Now let's go back to looking at the plot that we get things plugged in
but first let's look at our top two plots.
The horizontal axis in both of them represents time measured in seconds.
The vertical axis in the top one is x measured in meters
and here it is v measured in meters per second.
So you can see that our initial values of x go from 1.5 to 2.25 and v from -2 to 2.
So that corresponds to this green ellipse right here.
The most important thing to notice about this bottom graph, which like I said earlier represents
phase base is that if we look closely at each one of these ellipses they all have the same area.
Now let's look at the shapes that we have down here in this bottom graph.
If you look closely and do a bit of calculating, you'll notice that all these different color shapes
have the same exact area even though they are well shaped very differently.
This is a great example of how phase base is conserve in the system where energy is conserve.
Now the fact that its conservation principle holds in this diagram
shows how the symplectic Euler method improve upon the accuracy of the forward Euler method.
When the forward Euler method is used, it often result in the energy suddenly increasing.
So it means that the area of each of these shapes down here will get progressively bigger.
Symplectic Euler method, however, confirms much better the equations of motion in physics,
It never reflects exactly radical predictions more accurately. Great job with the first problem in Unit 2.