This p5.js sketch allows you to explore a simple function that exhibits some unusual properties. The graph, called a ‘bifurcation diagram’, is generated by repeatedly applying a simple function xnext = rx(1-x) to generate a range of values. Despite the simplicity of the function, it creates a complex pattern. Initially, with low values of r, the values generated fall into a narrow range. Then, as r increases, they split, so that the function returns just two possible values, then split again to yield four possible values, a phenomenon called period doubling bifurcation. After that, the regularity of the outputs breaks down, and they become completely chaotic. But even in the chaotic area, it is possible to see hints of structure.
The equation above was actually used to model animal populations, where the size of the population one year is related to the size of the population the previous year. ‘Common sense’ might tell you that you could easily predict the population next year just by knowing the population this year and the rate of growth (r in the equation). But researchers studying the problem soon found that when r increased above a certain point, their models predicted wild potential variations in population size, as shown in this diagram.
By varying the start and end values with the controls above, you can ‘zoom in’ on different parts of the graph. By changing the ‘settle’ and ‘plot’ settings, you can see more structure in the results. Click the Update button to regenerate the diagram with your new settings.
If you’d like to learn more about this, chapter 3 of James Gleick’s book “Chaos” has a very clear discussion of this topic.
A clear, readable introduction to chaos theory for interested laypeople.
There's also a very good YouTube video from Veritasium about the logistic map, which not only explains period doubling, but shows how it is related to a large number of other real-world phenomena from the behavior of boiling liquids, to heart rhythms, to activation of neurons in the brain.