# 780.20: 1094 Session 8

Printouts of filename_test.cpp, diffeq_pendulum.cpp, GnuplotPipe class; plots of damped oscillations

Today we'll study another nonlinear system: the damped, driven pendulum.

Your goals for today (and ...):

• Play around with C++ strings and string streams.
• Look at the effects of friction (damping) in the differential equation for a physical pendulum.
• Explore the parameter space for a driven, damped pendulum, looking for limit cycles and chaos.

Please work in pairs (more or less). The instructors will bounce around 1094 and answer questions.

## Strings and Things

The filename_test.cpp code has examples of the use and manipulation of C++ strings, including building filenames the way we do stream output. Be careful NOT to put << endl when creating filenames.

1. Compile and link filename_test.cpp in Dev-C++ and run it. Look at the output files and the printout of the code to see how it works.
2. Modify the code so that there is a loop running from 0 to 3 with index variable j. For each j, open a file with a name that includes the current value of j. Write "This is file j", where "j" here is the current value, into each file and then close it.
3. Modify the code to input a double named alpha and open a filename with 3 digits of alpha as part of the name. (E.g., something like pendulum_alpha5.22_plot.dat if alpha = 5.21934.) Output something appropriate to the file.

## Upgrades from the diffeq_oscillation to diffeq_pendulum Code

• There are three new menu items: plot_start, plot_end, and Gnuplot_delay. The equation is still solved from t_start to t_end, but results are only printed out from plot_start to plot_end. Initially these are the same time intervals, but you can use plot_start to exclude a transient region. So if the system settles down to periodic behavior at t=20, setting plot_start=20 means that 0 < t < 20 is not plotted, which makes the phase-space plots much easier to interpret.
• We've also incorporated code to do real-time plotting in gnuplot directly from C++ programs. We have a new, experimental class to do this; "experimental" implies that the class is still being developed; the interface and documentation needs work, and it probably has bugs! Look at the GnuplotPipe.h printout and the GnuplotPipe.cpp file to get an idea how it works. Gnuplot_delay sets the time in milliseconds between plotted points.
• To make this work on Windows, we need to set the path to include the Gnuplot directory. Right click on "My Computer" (under the Start menu), select "Properties", then the "Advanced" tag, then "Environment Variables". At the top, click "New" and type PATH for the variable name and "C:\Program Files\gnuplot\bin" (without quotes) for the variable value. To prevent mistyping, you might want to cut-and-paste the directory name. If you get a message later that "pgnuplot.exe not found", then you didn't succeed with this step.

## Damped (Undriven) Pendulum

The pendulum modeled here has the analog of the viscous damping: Ff = -b*v, where v(t) is the velocity, that was used in session 7. The damping parameter is called alpha here.

1. Create a project called diffeq_pendulum and add diffeq_pendulum.cpp, diffeq_routines.cpp, diffeq_routines.h, GnuplotPipe.cpp, and GnuplotPipe.h. Compile, link, and run it while taking a look at the printout of the code. It should look a lot like diffeq_oscillations.cpp, with different parameter names. Run it with the default parameters, noting the real-time phase-space plot. There is also an output file diffeq_pendulum.dat.
2. Modify the code so that the output file includes two digits of the variable alpha in the name.

3. Generate the analogs of the four phase-space plots on the handout but with pendulum variables and initial conditions theta_dot0=0 (at rest) and theta0 such that you are in the simple harmonic oscillator regime (note that theta is in radians). Set f_ext=0 (no external driving force) and then do four runs with four values of alpha corresponding to undamped, underdamped, critically damped, and overdamped (convert from the conditions on b discussed in the background notes). What values of theta0 and alpha did you use?

## Damped, Driven Pendulum

This is a quick exercise to look at transients.

1. Restart the program so that we use the defaults. There is both damping and an external driving force, with frequency w_ext = 0.689. The initial plot is from t=0 to t=100. Run it. The green points are plotted once every period of the external force.
2. Note that it seems to settle down to a periodic orbit after a while. Plot ("by hand" with gnuplot) theta vs. t from the output file diffeq_pendulum.dat and see how long it takes to become periodic.

3. Run the code again with "plot_start" set to the time you just found. Have you gotten rid of the transients? What is the frequency of the asymptotic theta(t)?

## Looking for Chaos

Now we want to explore more of the parameter space and look at different structures. On page 191 of the Landau/Paez book (see the handout), there is a list of characteristic structures that can be found in phase space, with sample pictures on page 190.

1. In phase space, a fixed point is a (zero-dimensional) point that "attracts" the time-development of a system. By this we mean that many (or all) initial conditions end up at the same point in phase space. The clearest case is a damped, undriven system like a pendulum, which ends up at theta=0 and zero angular velocity no matter how it starts. If the steady-state trajectory in phase space is a closed (one-dimensional) curve, then we call it a limit cycle.

2. We'll start with some prescribed values for the pendulum. Try the following combinations:
descriptionalphaf_extw_exttheta0theta_dot0
period-1 limit cycle0.00.00.6890.80.0
0.20.520.689-0.80.1234
0.20.520.6940.80.8
0.20.520.6890.80.8
chaotic pendulum0.20.90.54 -0.80.1234

You will need to adjust "plot_start" and extend the plot time (increase "t_end" and "plot_end"). Can you tell how many "periods" the limit cycles have from the graphs? How might you identify whether a function of time f(t) is built from one, two, three, ... frequencies?

One characteristic of chaos is an "exponential sensitivity to initial conditions." For the last combination, vary the initial conditions very slightly (e.g., change x0 by 0.01 or 0.001) and see what happens.

3. Java applets that show the behavior of a chaotic pendulum interactively and also a comparison of two such pendulums (to illustrate sensitivity to initial conditions) can be found at http://www.physics.orst.edu/~rubin/nacphy/JAVA_pend/.

780.20: 1094 Session 8. Last modified: 08:39 am, February 05, 2007.
furnstahl.1@osu.edu