COMPUTING II: COURSEWORK 2
The simple pendulum and energy conservation
Your coursework should be handed
in at the beginning of next week’s computing lab. session.
Make sure you write your name on all work you hand in and attach a plagiarism
statement.
2.1
Download (right click and select "Save target as..") ‘pendulum.c’ and add a function that calculates the sum
of the kinetic and potential energy of the pendulum at each value of t.
[4] The length and mass of the
pendulum are 9.8 m and 1 kg respectively. Assume the small angle approximation.
The program should save the energy vs. time data to a file called “energy.dat” . Run the program with a step size of
0.02 sec and a starting angle of 10 degrees. Use EasyPlot
to produce a graph of total energy vs. time and sketch the graph [1]
2.2 Modify “pendulum.c” so
that the second order Runge-Kutta method (p. 31 of the
lecture notes) is used to calculate the values of theta. The easiest way
to do this is to first declare two variables that will hold the values of theta
and omega
at the centre of the Dt interval.
These values may then be used to predict qt+1
and wt+1
[4]. Use the function you wrote in 2.1 above to calculate
the
energy of the pendulum. Output the values of energy (up to the fourth decimal place) and time to a file and use EasyPlot to produce a graph of energy vs
time. Again, provide a sketch of the graph [1].