Simple Hanging Harmonic Oscillator

Developed by K. Roos

In this set of exercises the student builds a computational model of a hanging mass-spring system that is constrained to move in 1D, using the simple Euler and the Euler-Cromer numerical schemes. The student is guided to discover, by using the model to produce graphs of the position, velocity, and energy of the mass as a function of time, that the Euler algorithm does not conserve energy, and that for this simple oscillatory system, a modified algorithm (Euler-Cromer) is necessary to avoid artificial behavior in the model.

Subject Area Mechanics
Levels First Year and Beyond the First Year
Available Implementations C/C++, Fortran, IPython/Jupyter Notebook, Mathematica, Octave*/MATLAB, Python, and Spreadsheet
Learning Objectives

Students who complete this set of exercises will

  • be able to build a model of a simple hanging harmonic oscillator using the Euler algorithm (Exercises 1 and 2);
  • be able to build a model of a simple hanging harmonic oscillator using the Euler-Cromer algorithm (Exercises 4 and 5);
  • be able to produce graphs of the positon, velocity, and total energy as a function of time from the results of their computational model (Exercises 1-5);
  • be able to assess the accuracy of two different computational algorithms (Euler and Euler-Cromer) by comparing results from the different algorithms to each other and to the exact analytical solution (Exercises 1-5);
  • discover that they bloody well can’t use the simple Euler method when modeling an oscillatory system (Exercises 1-3).