About
Developed by E. Ayars
Easy JavaScript Simulation by Fremont Teng and Loo Kang Wee
Simple Harmonic Oscillation (SHO) is everyone’s favorite type of periodic motion. It’s simple, easy to understand, and has a known solution. But SHO is not the only kind of periodic motion. In this set of exercises we’ll investigate an anharmonic oscillator. We’ll explore characteristics of its motion, and try to get an understanding of the circumstances under which the motion can be approximated as simple harmonic.
Subject Area  Mechanics 

Levels  First Year and Beyond the First Year 
Available Implementations  Python and Mathematica Easy JavaScript Simulation 
Learning Objectives  Students who complete these exercises will be able to use an ODE solver to develop a qualitative understanding of the behavior of an anharmonic oscillator. Most students gain a good understanding of the behavior of harmonic oscillators in their introductory classes, but not all oscillators are harmonic. Here we investigate an idealized boat hull which exhibits asymmetric oscillation: the restoring force is stronger for displacements in one direction than in the other. This results, for large oscillations, in a visibly nonsinusoidal oscillation. For small oscillations, the motion is approximately simple harmonic again. 
Time to Complete  120 min 
This set of exercises guides students through the development of an anharmonic oscillator, then lets them use an ODE solver to plot the motion. It does not describe how to use an ODE solver. Emphasis is on qualitative understanding of the system, although if the instructor chooses it is certainly possible to use real parameters (, dimensions of boat, etc) to obtain an “engineer’s answer”.
The problem is accessible to firstyear students, but it may also be of interest to students in higherlevel courses.
There is opportunity to discuss limitations of the model on the final problem. In this problem, if the amplitude is high enough that the boat gets out of the water, the model in the ODE breaks down in interesting and spectacular ways.
The pseudocode, Mathematica notebook, python code, and sample solutions of this Exercise Set assume the use of builtin differential equation solving capabilities. Depending on instructor preference, it may be desirable for students to have experienced the direct application of a finitedifference algorithm to a variety of firstorder differential equations before using a computational ‘black box.’
The simplest example of Simple Harmonic Oscillation (SHO) is a mass hanging on a spring. In equilibrium, the string will have stretched some equilibrium distance , so that the weight of the mass is balanced by the spring force . Any additional motion of the spring will result in an unbalanced force:
This last equation is in the form of the equation for SHO:
where in this case. Knowing , we can then go on to do whatever we need to do with the problem. The period of the motion is , the position as a function of time will be , etc.
We can use this “known solution” to SHO any time we can get the equation of motion into the form of the SHO differential equation. If the second derivative of a variable is equal to a negative constant times the variable, the solution is SHO with equal to the square root of that constant.
Even when we can’t get the equation of motion for a system into the form of SHO, we can often approximate the motion as SHO for small oscillations. The classic example of this is the simple pendulum. The equation of motion for the pendulum is
This equation is not SHO, but for small , so we can approximate the motion as SHO as long as the oscillations are small.
In the case of our wedgeshaped boat, the equation of motion is
This is not SHO! If is small, it is approximately SHO, but only approximately.
Note: The Mathematica and Python solutions here make use of builtin tools for solving differential equations. For other implementations the reader is directed to Numerical Recipes in C, or equivalent text, which will provide an introduction and theoretical description of the numerical approach to solutions via finitedifference methods.
Exercise 1: A straightsided boat
Imagine a boat with vertical sides, floating. There will be two forces on this boat: its weight , and the buoyant force . (I’ve defined down to be the positive direction, here, so the buoyant force is negative since it’s upwards.) The volume in the buoyant force component is the volume of water displaced by the boat: in other words, the volume of boat that is below water level. In equilibrium, the bottom of the boat will be some distance below the water, so , where is the area of the boat at the waterline.
If we then push the boat down some additional distance and let go, the boat will bob up and down.
 Show that the boat’s vertical motion is SHO. It will probably be helpful to follow the same pattern as for the introduction example: the key is to get the equation in the form of the equation for SHO.
 What is the period of the boat’s motion?
Exercise 2: A Vhulled boat
Instead of a straightsided boat, imagine a boat with a Vshaped hull profile, as shown below.
The width of the hull at the waterline depends on the depth below waterline :
The volume of water displaced by this boat is the area of the triangle below water level, times the length of the boat:
 Show that the vertical motion of this boat is not SHO. Replace with , where is the equilibrium depth, and follow the example in the introduction.

Rearrange the equation you got in the previous problem to be as close to SHO as possible by putting it in this form:
In this form, you can see that if is small, the motion is approximately SHO with angular frequency . What is that ? What must be small for this approximation to be valid?

If is not small, would the period of the boat’s oscillation be larger or smaller than ? Use a numeric solution of the equation of motion for the boat to verify your answer.

Plot the motion of the boat for various amplitudes. In addition to effects on , how else does the motion differ from SHO? It will be helpful to plot both the solution to the differential equation and the SHO approximation,

We’ve neglected viscous damping, which is a bad idea in liquids! Redo your calculations, and plots, adding a viscous damping force
to your equations.
#!/usr/bin/env python
'''
vhull.py
Eric Ayars
June 2016
A solution to the vertical motion of a Vhulled boat.
'''
from pylab import *
from scipy.integrate import odeint
# definitions
w = 1.0 # Well, we need to pick something. Might as well
# normalize the frequency. :)
delta = 0.2 # not sure what this should be, play with it!
def vhull_ODE(s,t):
# derivs function for vhull ODE, without viscous damping
g0 = s[1]
g1 = w*(1+s[0]/2)*s[0]
return array([g0,g1])
def vhull_ODE2(s,t):
# derivs function for vhull ODE, with viscous damping added
g0 = s[1]
g1 = w*(1+s[0])*s[0]  delta*s[1]
return array([g0,g1])
# Now set up the solutions.
time = linspace(0,20,500) # 500 points on interval [0,20]
# And now plot some things!
# Here's a lowamplitude one, should be approximately SHO.
A = 0.1 # Fairly small amplitude
yi = array([A,0.0])
answer = odeint(vhull_ODE, yi, time)
y = answer[:,0] # position is just the first row
plot(time,y, 'b', label="Actual solution")
plot(time,A*cos(w*time), 'r', label="SHO approximation")
A = 0.5 # Not small amplitude
yi = array([A,0.0])
answer = odeint(vhull_ODE, yi, time)
y = answer[:,0] # position is just the first row
plot(time,y, 'b')
plot(time,A*cos(w*time), 'r')
'''
# For damped motion, just use vhull_ODE2() instead of vhull_ODE.
A = 0.5
yi = array([A,0.0])
answer = odeint(vhull_ODE2, yi, time)
y = answer[:,0] # position is just the first row
plot(time,y, 'b', label="Actual solution")
plot(time,A*cos(w*time), 'r', label="SHO approximation")
'''
title("VHull Boat Solution")
xlabel("time")
ylabel("Position")
legend(loc="lower right")
show()
Exercise 1: A straightsided boat
For a boat with vertical sides, the equation of motion can be derived by starting with Newton’s second law:
where is the area of the boat’s crosssection at the waterline. is the equilibrium depth, so and
This is in the form of the equation for SHO, with
The period of the boat’s oscillation will be
Exercise 2: A Vhulled boat
The derivation for the Vhulled boat follows the same general procedure.
The equilibrium position is given by , so and
This can be further simplified as
From that equation we can see that if is small, then the motion is approximately SHO with
There are an awful lot of constants in that equation, so to simplify our numeric calculations let’s just redefine things.
We can also define the unitless variable , which allows us to rewrite the equation in (almost) unitindependent form:
That’s the equation we need to send through the ODE solver.
The equation is approximately SHO if the amplitude is small. The easist way to control the amplitude is to set initial position to , with , so that the amplitude is .
Setting different values of amplitude gives different behavior: for small amplitude () the result is nearly indistinguishable from SHO, but for larger values both the period and symmetry change. The figure below shows that at , the boat spends more time higher (the graph is inverted, since down is positive in our initial setup) and the period lengthens relative to the SHO approximation.
These effects are even more prominent at larger values of , as shown in the next figure.
There’s an opportunity here for the model to break down. If the boat gets completely out of the water, then the width of the boat becomes negative (ok, it doesn’t really but it does in the model) so then the volume becomes negative and the buoyant force becomes negative and the boat leaps away from the water exactly the way that real boats don’t. Be prepared to discuss this interesting result should the students get the amplitude too high.
Adding damping is relatively easy: just add another force term in the definition of the ODE. Results are shown below.
Translations
Code  Language  Translator  Run  

Software Requirements
Android  iOS  Windows  MacOS  
with best with  Chrome  Chrome  Chrome  Chrome 
support fullscreen?  Yes. Chrome/Opera No. Firefox/ Samsung Internet  Not yet  Yes  Yes 
cannot work on  some mobile browser that don't understand JavaScript such as.....  cannot work on Internet Explorer 9 and below 
Credits
Fremont Teng; Loo Kang Wee
Sample Learning Goals
[text]
For Teachers
Instructions
Solver Combo Box
Amplitude Field Box
Damped Check Box
Play/Pause and Reset Buttons
Research
[text]
Video
[text]
Version:
 https://www.compadre.org/PICUP/exercises/exercise.cfm?I=117&A=anharmonic
 http://weelookang.blogspot.com/2018/07/harmonicandanharmonicoscillationsof.html
Other Resources
[text]
end faq
{accordionfaq faqid=accordion4 faqclass="lightnessfaq defaulticon headerbackground headerborder contentbackground contentborder round5"}
 Details
 Written by Loo Kang Wee
 Parent Category: 02 Newtonian Mechanics
 Category: 09 Oscillations
 Hits: 3769