3. PROGRAM DESCRIPTIONS

3.1 PENDULUM PROGRAM

When this program is executed a primary screen (see fig. 3.1.1) appears which prompts the user to input the data. When this is done the main screen then appears which consists of four displays (see fig. 3.1.2). The top-left display is the animated pendulum; The top-right is the phase-space; the bottom-right is the Poincaré and the bottom-left displays text and information about the parameters used and the labelling of the axes. All calculations were carried out using double precision. This was needed to eliminate drift, (smearing of points) which occurred for a large number of iterations when using real variables.

While the program is running, the instantaneous position of the pendulum can be seen to be moving in real time. Provided that the step size is set to a reasonable value (50-500 steps) then the position of the pendulum is updated often enough to produce a smooth animation of its motion. As the step size increases, so too does the number of calculations performed. Thus the program slows down when the step size is increased.

The two graphs on the right of the screen show the history of the pendulum's motion. Note that when the pendulum is perfectly vertical in the animated display, the phase-space diagram shows the circle passing through the point displacement = 0, and when the pendulum reaches its maximum amplitude (without rotation), the phase-space shows the red circle passing through the velocity = 0 point.

The biggest problem encountered whilst writing this program was the graphics. FORTRAN does not lend itself readily to programming graphics and a lot of concessions had to be made. For instance, it was extremely difficult to marry the text to the axes with any degree of accuracy. Filling in shapes with colour was another source of constant frustration and the idea was eventually abandoned.

 

N.B. Initially the program was written so that the two equations, x and vel, were called as functions from outside the loop. This made the program look more complicated than it really was. If the user intends to use the program to solve a range of dynamic equations (such as Duffing's equation or the Van der Pol equation for instance) then it would be advisable to create the sub-functions, so that the equations can be changed easily from one line of the program.

 

3.2 PHASE-SPACE AND POINCARE PROGRAMS

The program listings for these programs can be downloaded from this site

The phase-space and poincaré programs are basically the same as the pendulum described above except that only the respective displays appear. The graphs in these programs have slightly more detail than their respective counterparts in the pendulum program. For instance, the axes are labelled and dimensioned. Also, the red circle was eliminated from these programs as this tends to slow the program down. The main purpose of these programs was to produce a print of the graphs that could be included in this project in the shortest possible time. They took between 10 and 15 minutes to perform ten thousand iterations. Because the Poincaré consisted of fewer points than its phase-space it was necessary to perform as many as forty thousand iterations to get the best indication of the pendulum's state. In some cases as many as the first six thousand points had to be excluded to guarantee transient free solutions.

The Poincaré program highlighted a serious problem with the common structure of all the programs. After a great many iterations, drifting became apparent. What should have appeared as a single pixel on the screen turned out to be a smeared line that constantly drifted towards the edge of the screen. This, however, was quickly rectified by declaring all variables as double precision. Fortunately, this did not have much effect on the running speed of the program. The time taken for ten thousand iterations was increased by approximately one to two minutes. This was not considered to be too much of a sacrifice.