2 Motion Of A Simple Pendulum: θ mg tangent L
2 Motion Of A Simple Pendulum: θ mg tangent L
2 Motion Of A Simple Pendulum: θ mg tangent L
s
tangent
mg
d 2
d 2s
=
L
= g sin
dt 2
dt 2
(1)
where the bob moves on the arc of a circle of radius L, s is parallel to the tangent to this arc
when the angular displacement of the bob from its equilibrium position is , and g sin is
the component of the acceleration due to gravity in the s direction. (N.B. The positive s
direction is chosen to be away from the equilibrium position, in the direction which makes
increase.)
For small angles sin , and equation (1) may be approximated by
d 2
g
2 =
L
dt
(2)
This is a linearised version of equation (1), since the right hand side is linear in whereas
sin in equation (1) is nonlinear. Equation (2) can be solved analytically, giving the usual
periodic solution:
= a sin( t + ),
d
= a cos( t + ),
dt
g
L
(3)
d
= ,
dt
d
= f ( , , t )
dt
(4)
where f(, , t) = 2 sin in the case of the pendulum equation (1), and f(, , t) = 2 in
the case of the linearised equation (2). In the case of a damped pendulum, with damping
force -mk, the function f depends on as well as . If the pendulum is also forced by an
external time-dependent force mA cos(t) the function on the right hand side of (4) becomes
a function of the three variables , and t:
f ( , , t ) = 2 sin k + A cos(t )
(5)
To solve these equations numerically we need to choose initial values for and and then
calculate a series of values for (n, n), n = 1, 2, 3, We step forward in time using Taylor
series expansions for and .
d (t )
d 2 (t ) t 2
t +
+ O(t ) 3
2
dt
2!
dt
t 2
(t + t ) = (t ) + (t )t + f ( (t ), (t ), t )
+ O(t ) 3
2!
n +1 = n + n t + O(t ) 2
(t + t ) = (t ) +
n +1 = n n t + O(t ) 2
This is the simple Euler method for integrating the simple pendulum differential equations.
The notation O(t)2 means that there are error terms of order t squared and higher. The
equation for updating the angular frequency is obtained using a Taylor expansion in the same
way that the equation for updating the angle was obtained.
The trapezoid rule makes improved approximations for updating the angular frequency and
angle.
Trapezoid
Simple
Euler
d (t + t )
dt
d (t )
dt
t+t
d (t ) d (t + t )
+
t + t
d
dt
dt = n +1 n
Area under trapezoid = (t + t t ) dt
dt
2
t
n +1 n +
t d (t ) d (t + t )
+
2 dt
dt
d (t + t ) d (t ) d 2 (t )
=
+
t + O(t ) 2
2
dt
dt
dt
d (t + t )
n + f ( n , n , t )t = n + k1b
dt
t
k1a + k 2a
n +1 n + ( n + ( n + f ( n , n , t ) )t ) = n +
2
2
k1a = n t k2a = ( n + f ( n , n , t )t )t
t d (t ) d (t + t )
+
2 dt
dt
t
k1b + k 2b
n +1 n + ( f ( n , n , t ) + f ( n +1 , n + k1b, t n +1 ) ) = n +
2
2
k 2b = t f ( n +1 , n + k1b, t n +1 )
n +1 n +
The program calculates the angle and angular velocity at n+1 instants of time, starting
from t=0 and increasing in steps of equal size h until t=nh. The output is a 3-column
table, with values of t in the first column, in the second and in the third. h is used
instead of t in the actual programme.
The function f(, , t) is calculated in a separate C function, so that it is easy to alter as
necessary.
At each step the integration of the two first order equations is performed using the
trapezoid rule. The variable k1a is h times the value of the derivative of at t, the start of
the step. k2a is h times the first order approximation to the derivative of at t+h. The
trapezoid rule then gives (t+h)= (t)+(k1a+k2a)/2. Similarly k1b and k2b are h times
the values for the derivative of at each end of the step, and the value of at t+h is
calculated using the trapezoid rule.
To make it easy to show the results graphically, the output is written to a datafile as well
as to the screen. The datafile can then be used with GNUPLOT to show graphs of and
against t.
(6)
(7)
(8)
When you have finished using a file you must close it with a statement of the form
fclose(filepointer);
/* pendulum.c
method */
(9)
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
/* function prototype */
main()
{
int i, n;
double h, k1a, k1b, k2a, k2b, theta, omega, t;
FILE *Oscp;
/* declare file */
char filedat[20];
/* declare string of characters for filename */
h=0.1;
n=100;
theta=0;
omega=1;
t=0;
/* function header */
return deriv;
}
EXERCISES 1
Investigate the motion of a simple pendulum in the particular cases listed below. In each case
write the data to a datafile, and use GNUPLOT to plot graphs of the data.
To plot a datafile, open GNUPLOT. Type plot at the prompt, and pull down the PLOT menu
from the top bar. Click on Data filename and a dialog box will allow you to find any data
files you have saved. Click on the file you want and its name will appear after plot. Now
type using 1:2 and press <RETURN>. GNUPLOT will use the first column of your datafile
for the horizontal axis, and the second column for the vertical axis. To plot the third column
instead of the second, replace 1:2 by 1:3. If you use GNUPLOT with a file pendulum.dat to
plot the angle and angular velocity as functions of time on the same graph, the command line
will be gnuplot> plot 'pendulum.dat' using 1:2, 'pendulum.dat' using 1:3
1. Run pendulum.c as it stands to solve the linearised equation with 2=1 and initial values
=0 and =1. Run the program again with the pendulum initially at rest and the
following set of initial positions: (0)= 0.2 rad, 1.0 rad and 3.124 rad. (The last value is
approximately equal to 179o). In each case plot graphs of and against t. Describe
what the pendulum is doing in each of these cases.
2. Replace the sine function so that the program solves the nonlinear equation (1) for the
same sets of initial values as in question 1. Compare the results with those of question 1.
To see how they differ as the displacement of the pendulum increases, plot the angles
calculated in this question and those found in question 1 as functions of time on the same
graph.
d (t )
dt
t
d
2
dt
d ( 0)
dt
t
t
) d 2 ( )
d (t )
2 +
2 t t + O( t ) 2
=
2
dt
dt
2
2
dt
t
t
t
d ( )
d 2 ( ) t
d ( )
t
d (t )
t
2
2
2
0 dt dt dt t + dt 2 0 t 2 = dt t + 0
d (
The second term in the series above is equal to zero when we choose the mid-point of the time
step for the Taylor expansion. To use the algorithm we need approximate values for and
at the mid-point of the time step which are generated using the Simple Euler method.
t 2
)
2
t
t
n +1 / 2 n + f ( n , n , t n ) + O( ) 2
2
2
t
n +1 n + n + f ( n , n , t n ) t
2
n +1 n n +1 / 2 t + O(
n +1 n f ( n +1 / 2 , n +1 / 2 , t n +1 / 2 )t + O(
n +1 / 2 n + n
t 2
)
2
t
2
t
2
n + f ( n +1 / 2 , n +1 / 2 , t n +1 / 2 )t
n +1 / 2 n + f ( n , n , t n )
n +1
The algorithm for second order Runge-Kutta integration has been derived; formulae for the
4th order Runge-Kutta method are given below.
k1a = h
k2a = h (+k1b/2)
k3a = h (+k2b/2)
k4a = h (+k3b)
k1b = h f(, , t)
k2b = h f(+k1a/2, +k1b/2, t+h/2)
k3b = h f(+k2a/2, +k2b/2, t+h/2)
k4b = h f(+k3a, +k3b, t+h)
EXERCISES 2
1.
Edit pendulum.c so that it uses the 4th order Runge-Kutta algorithm in the for loop.
2.
Check your program by running it for the case of the nonlinear equation (1), with
several different initial values of and , and comparing the results with those
obtained in question 2 of exercise 1.
3.
Examine the behaviour of a damped pendulum, equation (5), using 2=1, k = 0.5, A=0
and a range of initial positions and velocities. Plot graphs of against t to compare
the nonlinear case with the linearised version. Your graphs should show that the
linear approximation becomes very good after a sufficiently long time. Explain why.
4.
Change the function in your program to solve the equation for the damped driven
pendulum, using 2=1, k = 0.5, = 0.6667, and a range of drive amplitudes:
A = 0.90, 1.07, 1.35, 1.47 and 1.5. The best way to understand the behaviour of the
pendulum is to plot graphs of against , and restrict to the range [-, ]:
To restrict the range of , add the following if statement in the for loop where
theta is calculated:
if (fabs(theta)>PI)
{
theta = theta - 2*PI*fabs(theta)/theta;
}
To use PI instead of having to type in the numerical value, define it at the very
top of your program with the statement # define PI 3.14159265 (N.B. no
semicolon at the end).
It is convenient to divide the 'drive period' 2/ into an integer number N of
steps (e.g. N=1000), and calculate values of and at each of these times over a
small number of drive cycles (e.g. 5).
Approximately the first 500 iteration points represent an initial transient
trajectory before the motion settles down. Do not plot the first 500 points
(include a statement in your program to prevent it writing the initial 500 points to
the datafile).
Plot against for initial positions and velocities in the ranges -3.0<(0)<-1.0,
-0.5<(0)<0.5. For A = 0.90 you should be able to see that the motion is periodic,
while for A = 1.07 it is a combination of oscillations at two different periods - period
doubling has occurred. For A = 1.5 the motion is chaotic.