Harmonic Oscillation
basic mathematics and physics
Colin Fahey
1. Introduction
I wrote a mathematical description of harmonic oscillation.
2. Download document
You can download the document as a PDF file.
3. Download associated computer code
I am making this source code (with project files) available only to give readers of the "Harmonic Oscillation" document some idea about how one might implement some of the ideas in C/C++ code. I recommend against using my code, which may contain mathematical errors, but I still think there is enough value to inspire readers to try out their own experiments. I wrote the following program to generate tables of data for various graphs featured in the "Harmonic Oscillation" document. I executed the program from a command prompt, routing the plain text output to plain text files. Then I simply opened the text file with Microsoft Excel, highlighted columns, and created charts. The only purpose of the program was to generate data for these charts, so there are many hard-coded constants (limited to demonstration functions). I think the computer code will compile under Linux, but the supplied project file is for Microsoft Visual C++ 6.0. Simply double-click on the DSW file, and then press Control-F5, and then you should see a meaningless stream of numbers flow in a console window. Use the command prompt to go to the directory containing the compiled executable, and type:
simple_harmonic_oscillator.exe > out.txt
This will "pipe" the output in to the text file named "out.txt". Then start Excel, if you have it, and just highlight the columns with numbers, insert a chart (an "X-Y" type), and you should see one of the charts in my document. You can edit the function that calls the various demonstration functions, and thus print out data for my other charts. Under Linux you might use gnuplot. I commented-out some hacks that I used to artificially separate sequences of curves, and you can reproduce something similar to my charts if you un-comment various parts. Anyhow, I feel really bad about the code. There are some hard-core hacks in there to help me generate weird data for charts.