05-A Simple Pendulum

In this exercise you will model the motion of a Simple Pendulum.  A pendulum is made by suspending a small mass \(m\), called a bob, attached to the ceiling or other support using a string of length \(L\).

The adjacent diagram shows the pendulum when it has been displaced from the vertical by an angle \(\theta\).  When we use our standard coordinate system with \(x\) horizontal and \(y\) upward then the coordinates of the pendulum bob will be \(\langle L\textrm{cos}(\pi/2-\theta), L\textrm{cos}(\pi – \theta),0 \rangle = \langle L\textrm{sin}(\theta), -L\textrm{cos}(\theta),0 \rangle\).

The starter code below draws the pendulum string and bob and shows the support point as a dot.  The initial angle is also defined using a variable called theta. You will notice that initially the mass just sits still.  This is due  to the fact that the code describing the physics hasn’t been added yet. You will need to complete the steps that are identified in the comments with letters A – F.  Be sure to use the variables indicated and to remove the hashtag comment symbols in front of the variable assignments that you add.

Notice that the tension force in the string is a reaction force.  It will take on whatever value is needed to produce the motion.  Its value cannot be determined with a fundamental formula like a gravitational or electrostatic force.  Instead, you will have to use the momentum principle and the current velocity of the pendulum bob to determine the value of the tension.

When finished with these steps you should find that the pendulum moves in a periodic manner. A graph showing the angular position of the pendulum will be shown.  Your cursor can be used to determine features of the motion such as the period, the time required for the motion to repeat.

# Simple Pendulum
#

# Define needed constants
g = 9.8         # Strength of the gravitational force in N/kg (or m/s/s)
L = 1.0         # Length of the pendulum in meters
R = 0.02        # Radium of the pendulum bob in meters 

# Move the center of the scene downward so the pendulum takes up more of the screen.
scene.center = vector(0, -L/2, 0)
scene.background = vector(0.5, 0.5, 0.5)

# Draw a small sphere to represent the anchor point
anchor = sphere(pos=vector(0,0,0), radius=R, color=color.white)

# Define the intial angle for the pendulum.  Use the radians function to
# convert the angle from degrees into radians.
theta = radians(20)

# Draw the pendulum bob as a black sphere.  Call it 'ball'.
ball = sphere(radius = R, color=color.black, make_trail=True, trail_radius=R/10, retain=200)
ball.pos = L*vector(cos(pi/2-theta),cos(pi-theta),0)    # Initial position of the ball (m)
ball.m   = 0.05                                         # Mass of the ball (kg)
ball.v   = vector(0,0,0)                                # Initial velocity of the ball (m/s)
ball.p   = ball.m * ball.v                              # Initial momentum of the ball (kg m/s)

# Draw the string as a white cylinder.
string = cylinder(pos=anchor.pos, axis=ball.pos, radius = R/4, color=color.white)

# Define flags for showing forces and momentum.  Set these to True or False as desired.
showRealForces = False
showNetForce = False
showNetForceComponents = False
showMomentum = False

# Define Arrow objects for the forces or momentum
if showRealForces:
    Ft_arrow = arrow(color=color.blue, shaftwidth=R/2)
    Fg_arrow = arrow(color=color.blue, shaftwidth=R/2)
    label(pos=vector(-1.2*L, 0.5*L, 0), color=color.blue, text="Real Forces", box=False)
    
if showNetForce:
    Fnet_arrow = arrow(color=color.red, shaftwidth=R/2)
    label(pos=vector(-1.2*L, 0.4*L, 0), color=color.red, text="Net Force", box=False)

if showNetForceComponents:
    Fpara_arrow = arrow(color=color.green, shaftwidth=R/2)
    Fperp_arrow = arrow(color=color.green, shaftwidth=R/2)
    label(pos=vector(-1.2*L, 0.3*L, 0), color=color.green, text="Net Force Components", box=False)
    
if showMomentum:
    p_arrow = arrow(color=color.cyan, shaftwidth=R/2)
    label(pos=vector(-1.2*L, 0.2*L, 0), color=color.cyan, text="Momentum", box=False)
    
# Set up a graph of angle versus time
graph(width = 800, height = 400, fast = False,
        xtitle = 'Time [s]', ytitle = "Angle, theta [rad]")

AngleVsTime = gcurve(color = color.blue,  width = 2)

dt = 0.001          # Time step in seconds
t = 0               # Initialize the time

###############################################################################
#                                                                             #
# Complete the lines of code following each of the lettered comments A thru F #
# below.  Be sure to not change the suggested names of the variables and also #
# be sure to remove the hashtag characters to uncomment your entered code.    #
#                                                                             #
###############################################################################

while (t<12):
    rate(1000)
    
    # Use the current position of the ball to get the angle of the pendulum
    theta = atan(ball.pos.x / -ball.pos.y)
    
    # Find a unit vector in radial direction
    rhat = norm(ball.pos)
    
    # A: Define the gravitational force Fg on the ball which has mass ball.m
    #Fg = 
    
    # B: Find the magnitude of the tension force.  Call it 'T'
    #T = 
    
    # C: Express the tension force as a vector.  Call it 'Ft'
    #Ft = 
    
    # D: Find the net Force on the ball
    #Fnet = 
    
    # E: Update the momentum, position, and velocity of the ball
    #ball.p   = 
    #ball.v   = 
    #ball.pos = 
    
    # Redraw the string
    string.axis = ball.pos
    
    # Advance the time counter
    t = t + dt
    
    # Plot the Angle versus time
    AngleVsTime.plot(t,theta)
    
    # F: Compute the Parallel and Perpendicular components of Fnet
    #phat = 
    #Fpara = 
    #Fperp = 
    
    if showRealForces:
        Ft_arrow.pos  = ball.pos
        Ft_arrow.axis = Ft
        
        Fg_arrow.pos  = ball.pos
        Fg_arrow.axis = Fg
    
    if showNetForce:
        Fnet_arrow.pos  = ball.pos
        Fnet_arrow.axis = Fnet
        
    if showNetForceComponents:
        Fpara_arrow.pos  = ball.pos
        Fpara_arrow.axis = Fpara
        
        Fperp_arrow.pos  = ball.pos
        Fperp_arrow.axis = Fperp
    
    if showMomentum:
        p_arrow.pos  = ball.pos
        p_arrow.axis = ball.p*5