Chaos and Java:
Interactive Learning


By Brian Davies
Australian National University
ABSTRACT

This paper reports on a project in which I have developed special purpose software to allow students to learn about complex dynamical behaviour by making their own numerical experiments. I shall show examples of how theory and experiment may be synthesised by students, taken from a course currently being taught at the ANU. I shall also relate some of my experiences in using JAVA for computationally intensive tasks, and demonstrate the remarkable efficiency of the latest JIT technology.

Perspective

Non-linear dynamics and chaos is a comparatively new science, emanating from the remarkable fact that determinism does not imply either regular behaviour or predictability in even the most simple non-linear systems. Poincaré appreciated these matters over 100 years ago, as did a few other pioneers during the years 1900 - 1960. Poincaré wrote about the stability of the solar system2, an academic question which does not have high priority in everyday life. Nevertheless, chaos is an important area of study for today's undergraduates, since chaotic behaviour is ubiquitous in everyday systems.

It is often the case that an increase in some controlling factor can cause a system to break into complex - apparently random - behaviour, despite the fact that the smaller value did not produce such undesirable effects. In other cases the reverse may happen. Either way, there are symptoms which prefigure such events, and factors which should be understood in order to avoid such a circumstance.

Interest in chaos has grown rapidly since Edward Lorenz published, in 1963, a numerical study
3 of a simplified model of atmospheric convection and discussed its gloomy implications for weather prediction on a common topic of conversation. One reason for the growth of interest in chaos is the wide relevance of the subject, already alluded to.

In this regard it is important to note that Lorenz went looking for it rather than trying to dismiss it as entirely bizarre and uninteresting. Increasingly, some understanding of chaos is required in many disciplines; hopefully future graduates will learn to distinguish between its scientific meaning and its many misleading everyday uses, just as one knows that the temperature in parliament is not measured in degrees Celsius.

It was the computer which made Lorenz discoveries possible, and computers and computer graphics
4 continue to be the single most important tool at the 'cutting edge' of research in the field. By contrast, most published texts provide only rudimentary computer assistance - typically a few programs in BASIC5. Few students have the time to write their own computer programs in addition to learning a new theory. This pedagogic problem is the origin of the present project, which has been under way for several years. Initially I set out to produce software which could be integrated with an elementary level course.

The first incarnation was a few simple MATLAB programs, integrated with some student exercises. The next was a Macintosh program which had expanded features and ease of use, but the same basic philosophy.

Following the World Wide Developers Conference in May 1997, where one of the themes was the emerging importance of JAVA, the project was redefined to be a new text, closely integrated with a JAVA package. It will be titled Exploring Chaos: Theory and Experiment, and will be published early in 1999.

In this talk I shall concentrate mainly on the software, and on the suitability of JAVA for the purpose at hand. In writing a book, I have the same intention as numerous other authors: to provide the clearest possible exposition of the subject matter at the chosen level - in this case undergraduates6. From the beginning of my forays into the teaching of chaos, I was convinced that students need software which enables them to make sophisticated numerical experiments as part of the learning process.

The software should provide visualisation of non-linear dynamical behaviour, together with tools for making precise numerical measurements on representative systems. The solution of non-linear equations is numerically intensive; nevertheless the graphical user interface, for which we owe much to the Apple Macintosh, is a convenient way to present the results to students.

 

Lorenz equation - visualising infinite complexity

The Lorenz equations are one of the standard paradigms for chaotic dynamics. Before enunciating them, I want to plead with non-technical readers that there will be no sophisticated mathematics here. Lorenz equations are:

 

dx/dt = Fx = s (y-x),
dy/dt = Fy = r x - y - x z,
dz/dt = Fz = x y - b z,

 

  • where b, s and r are positive real parameters (numbers), x, y, z the variables whose evolution in time we wish to understand. Let me give some explanations and make some comments, before demonstrating the software.
  • Lorenz was interested in motion of the atmosphere when driven by heating from below, such as might occur locally over warm terrain.
  • A complete description is unbelievably complicated, since it must take account of the temperature, movement, and other relevant data, at every point in space and instant in time.
  • The equations were introduced by Lorenz as the simplest possible reduction of the original problem. Remember that Lorenz brand new computer had the power to carry out 30 (thirty) multiplications per second!
  • The three variables (x, y, z) represent measurable quantities. z measures the reverse temperature gradient as a function of time. x and y describe rolling convective motion; when they are positive the direction is one way, when negative the other.
  • Each equation says that the corresponding variable changes in time at a rate proportional to the instantaneous value of a driving force (Fx, Fy, Fz).
  • Two of the force terms are non-linear7, were it not for this the behaviour would be extremely simple oscillations which die out.

 

2.1 Simple problem, complex solutions


No matter how complicated the problem with which Lorenz started, the equations he investigated are rather simple to state. By contrast, the solutions he found are incredibly complex: non-periodic and undamped. That is, they never repeat themselves and they never die out. These solutions are also sensitively dependent on the initial state of the system, which means that for all practical purposes, prediction is limited to relatively short times.

Many papers, and at least one monograph, have been devoted to the study of these equations and their behaviour. This is quite usual for topics which are the subject of undergraduate study. The real problem is that there are no simple formulae to represent the solution of even one representative problem; even worse, Poincaré's work shows that there can be no simple formulae.

This means that static pictures have very little to say about an infinitely complex situation. It also implies that we cannot teach students using the same techniques as are used in elementary calculus, with dozens of routine problems on which to practice.

Recall what I said about the meaning of (x, y, z). An increase in z signifies an increase in the reverse temperature gradient due to the heating from below, this feeds energy into convective rolling motion which serves to shed the heat. Sometimes the roll is one way, sometimes the other. What Lorenz discovered, and what the student can also investigate quickly and conveniently, is that it is impossible to make long term prediction about the sequence of events, although their general pattern is quite clear.

 

2.2 Strange attractors and butterflies

The first thing is to visualise how solutions of the Lorenz equations unfold in time.
For the purpose of the printed proceedings, I have introduced at this point a static figure
8. Since the 'orbit' is in three dimensions, while a computer screen is flat, there is provision in the JAVA program for rotating the object in space, which I demonstrate here.

Following Lorenz choice for the parameters9, we see orbits which have become one of the icons of chaos. Notice how, on rotating the figure to get an impression of its three-dimensional form, it is somewhat reminiscent of 'Butterfly wings'.

In a moment I shall explain how apposite this coincidence is. Using another of the software features, we may watch how the solution point generates the orbit in time. You will see that it makes one or more circuits around one of the wings before switching to the other; this process of making circuits and switching sporadically continues indefinitely.

Lorenz noticed that when he attempted to recompute a given orbit, using the same program on the same computer, he got a different result from the original. This was because his recorded values of (x, y, z) were less accurate than the internal representation used by the computer
10, so he was comparing two solutions which differed in their initial state by a small amount. The surprising effect was that, after a while, the two solutions didn't seem to have much correlation with each other at all.

For example, two orbits which differ initially only in the fourth significant place, are not even on the same 'wing' after a dozen circuits or so. Nevertheless, one obvious qualitative feature is that they are both organised by the same strange attractor. This effect, sensitive dependence of the evolution of a system to the most insignificant changes of initial state is known as the butterfly effect, after the title of a talk by Lorenz, Predictability: Does the flap of a Butterfly's Wings in Brazil set off a Tornado in Texas?11

 

2.3 Tracking the return

One of the tools used by Lorenz in his original paper was based on the simple observation that, as the system evolves, it repeatedly attains a maximum value of z (reverse temperature gradient). This suggests that there might be useful information in correlating successive maxima in z; this was done by Lorenz, and I repeat here his experiment using another feature of the software. Looking at the figure it indeed appears that there is a very good correlation lying on a tent shaped graph, although close examination allows us to see that it is not quite a one-dimensional curve.

 

3. Iteration of maps: what is chaos?


The plot of return values is an example of a basic tool introduced by Poincaré, iteration of a map of section. Computers are very good at iteration, and so are real life systems. I will set the stage for this section by giving (in non-technical language) the precise definition of chaotic motion of a dynamical system: it is motion which never repeats itself, and which exhibits the butterfly effect. Stated more technically, and in a way which relates to the previous section, it is motion which is non-periodic and sensitively dependent on the initial state.

I want to shift the focus from a tent-like map to the Logistic map
12. I do not have time here to justify why this map is worthy of study; my purpose is to demonstrate some computer tools for its investigation. The formula is

xn+1 = f(xn) = r xn (1 - xn)

 

where r is an adjustable parameter (number) between the values 0 and 4, and x is a real number between 0 and 1; n denotes the n'th iteration. Notice the extreme simplicity of this formula, evident also in the graph13 of the function f(x); it involves no more than taking the square of a number. But therein lies the non-linearity, and the source of infinite complexity14.

 

3.1 Examining the dependence on r


One simple experiment, which reveals a lot about how the behaviour depends on the parameter r, is effected by keeping track of several thousand iterations of the system, discarding the first few hundred to allow the system to attain 'equilibrium' and then plotting to the nearest pixel what x values the system actually visits thereafter. I call such a diagram a final state diagram
15, and show one in the figure below. Zooming in on an interesting part a few times reveals two interesting and important features:

  • There is an apparently endless amount of detail to be found (in fact an infinite amount)
  • The finer the degree of scrutiny, the more computation is required to see anything

The point of my demonstration, in relation to the title of the talk, is the ease with which a student may make these discoveries.

It is apparent from these diagrams that the system enjoys relatively simple periodic behaviour for many values of r. It is also clear that such states suddenly branch (bifurcate) at critical values of r. This is related to the stability or otherwise of associated periodic orbits. It is easy to tell a student this; in general checking such a claim involves a great deal of computation. Let's look at the previous final state diagram
16, superimposing information about stable (blue) and unstable (red) periodic orbits. Since there are an infinite number of possible periods, and only a finite number of pixels on the screen, I must impose a limit. Here the search is limited to periods no greater than 24. Nevertheless, we see some interesting things:

  • At the points of branching (bifurcation) one orbit becomes unstable while a new stable orbit suddenly appears. The new one has twice the period.
  • This continues in a cascade to chaos - the period doubling route to chaos. Superposing the unstable orbits shows the awesome complexity of this phenomenon.
  • Experimentally, it is quite clear what is driving chaos: a dense set of unstable orbits.
  • All this is readily accessible to the student using easy-to-use software.

 

3.2 Looking for chaos


The question arises: how can one recognise the signatures of chaos, non-periodicity and sensitivity, when the motions of even the simplest non-linear system cannot be described by simple formulae?

The answer is that both of the properties can be observed experimentally, by actually iterating the system and computing some global data from it. To investigate the question of whether the motion repeats itself, one can examine the frequency content. If the only observable components are at low frequency, this is strong evidence of periodic behaviour. If there seems to be a continuous distribution of frequencies, that is evidence of non-periodicity. Similarly, one can compute the tendency to converge or diverge at each step, and from it an average (logarithmic) factor called a L'Lyapunov exponent'. If it is positive in the long term limit, then the observed motion is unstable.

This may seem rather ad-hoc, justifying the taunt that it is 'experimental mathematics'. But then mathematics is employed in the present context as servant, not master17. Here I demonstrate in the case of the logistic map with the maximum parameter value, r = 4. First let's look at some iterations as a simple plot18; irregularity is apparent but nothing is proved thereby. One useful way to observe the data is to take rather a long sample - here I choose 100,000 iterations - and plot a histogram which shows the relative frequency with which they land in various parts of the allowed range between 0 and 1. Now, with the click of a button, the Lyapunov exponent is calculated for this orbit. The result is approximately +0.69, an indication of very strong dependence on the initial state19. Now let's look at the frequency components of this orbit, using yet another facility which evaluates Fourier transforms. It is quite clear from the figure that there are no dominant frequencies. Thus one can settle, at least in an experimental way, the fact that this is almost certainly a chaotic orbit.

 

4. The price of control - fractal boundaries

Suppose I introduce some linear feedback into the logistic map, aimed at keeping the iterations from jumping about20. This gives a system whose specification requires two variables, the present and immediate past value of x. I spare the technicalities, and ask that it be taken on faith that things can be arranged in a way which effects the possibility of control. But it also introduces the possibility of disaster!

Recall that I said that x was confined between the values of 0 and 1. This is perpetuated by the fact that, for a given input state x in this range, the logistic function delivers a new state in the same range - look at the graph to see this. But adding together this output to the control, it is entirely possible that their sum will be out of range. After that, the system may go right off the planet.

We can observe this using yet another feature of the software. For reasons I don't want to explain, the value of a = 1.6 which I use here corresponds to an r value of nearly 4, for which the logistic map is chaotic. The (desired) stable state of the system is shown as a large dark blue point sitting in the middle of a light blue region; starting the system from anywhere in the light region results in control, that is it steadily approaches the stable state.

Starting the system from anywhere in the dark grey region results in disaster: the values of x increase without limit. Instantly one sees something new, indeed fractal; the light blue and dark grey regions are mixed up in an infinitely complex manner.

Let's look at what happens if a is given the smaller value of 1.0, which corresponds to stable period doubled behaviour in the original logistic map. As desired, there is control which brings it back to a single equilibrium. Unexpectedly, it is at the price of infinite complexity. Even worse, the red areas
21 signify initial states from which the system is indeed under control, but in a different state from what is desired!



I conclude with a few comments:

  • An understanding of these matters is relatively recent.
  • These are not simply academic curiosities - the lack of this kind of knowledge is known to have been the cause of at least one North Sea ferry disaster, and is almost certainly at the heart of many other unexplained catastrophes.
  • All this is readily accessible to the student, making it possible to address the issues rather than the details of how to make the calculation, at least until there is motivation to do so.

 

4.1 Efficiency considerations

The demonstrations just shown are computationally intensive. What the program must do is to compute, for each pixel position, the evolution of the system if it starts from the point represented by that pixel. That is, several thousand calculations for tens of thousands of pixels! I believe that you have seen for yourself that things are comfortably fast, since the picture is displayed as it is computed, on the fly.

More generally, because of the way this project has developed, I have C++ code for many of the computations, with which I can compare the JAVA performance, since much of the code is identical line by line. A number of trials have convinced me that a good JAVA JIT compiler performs very well compared with a good C++ compiler, although I would temper this claim by the observation that graphic performance in Java is still far from optimal.

However, having seen a 10-fold increase in computational performance in the past year, I have every confidence that reservations about the graphical performance will soon fade, leaving one to exploit the many advantages of JAVA in teaching.


ACKNOWLEDGEMENTS

I would like to acknowledge the assistance I have received from the Apple University Consortium and Apple University Development Fund, by way of an AUDF grant and support to attend World Wide Developer's Conferences in the USA in 1997 and 1998. I would particularly like to thank my local contact with these bodies, Berrick Krahnen.

1 That is, systems whose law of evolution is not governed by simple proportionality to their present state.

2 In fact, he was awarded a major prize for his ground-breaking work.

3 References to scientific literature will not be given here; they may be found in many textbooks on Chaos.

4 It is interesting to note that Lorenz graphics consisted of printing asterisks on a 132 character printer and joining them with a coloured crayon!

5 The chief exception to this is that their is a lot of software available for constructing fractals', such as the well known Mandelbrot and Julia sets, for both Macintosh and Windows platforms.

6 Almost all the existing books are at a higher level, or mainly descriptive.

7 The terms xz and xy are products of two of the state variables, the vital feature. Thus the relative influence of either variable in this term is proportional to the instantaneous value of the other.

8 The software may be visited at http://wwwmaths.anu.edu.au/~briand using a Java-enabled browser.

9 Lorenz selected the values b=10, s=8/3 and r=28 from consideration of the underlying physical processes.

10 A fortuitous result of the expense, both in dollars and time, of printing out all six digits actually computed!

11 Lorenz pointed out that one might equally well ask if the Butterfly can prevent a tornado in Texas.

12 The only interesting behaviour of the tent map is chaos; the Logistic map exhibits richer modes of behaviour.

13 Here I chose r = 3.2, so the maximum is 0.8 rather than 1.

14 The most famous fractals of all, the Mandelbrot set with its associated Julia sets, are obtained from the iteration of the same quadratic. In that case the formula is usually written in a different (but equivalent) manner, and the state variable x assumes values in the complex number plane, rather than just real numbers as here.

15 Often called a bifurcation diagram; however there is good reason to use the present terminology when observing actual states rather than theoretically possible orbits.

16 Only the second figure appears in the written version of this paper; black and white printing makes it somewhat harder to interpret since the colours are rendered as shades of grey.

17 Of course there is much important current research aimed at elucidating carefully formulated theoretical propositions about chaos. Such investigations are at a high level of theoretical difficulty, more suitable for graduate level courses than the present purpose. Moreover, for the example I shall consider in the final section, (the Hénon map) there is at present no theoretical resolution of many questions for which a relatively certain answer may be given using just the software of this paper.

18 There is no printed figure corresponding to this demonstration.

19 In fact, because it is the natural logarithm of 2, it indicates a divergence by an average factor of 2 per step over the whole orbit. This is one of the few occasions where such a result can be proved theoretically.

20 This produces a system more commonly know as the Hénon map, hence the different parameter conventions.

21 This appears as lighter grey in the printed version.



Contact Details
Dr Brian Davies
Department of Mathematics
School of Mathematical Sciences
Australian National University
Canberra ACT 0200
Phone: (06) 249 2915
Fax: (06) 249 4984
Email: Brian.Davies@anu.edu.au


Return to top