# The Logistic Map

The equation

```xn+1=λxn(1-xn)
```

is known as the logistic map. The two series considered are both logistic maps, one with λ=2, the other with λ=4. What can we discover about this equation for different values of λ?

Suppose that, for a given value of λ, we iterate the equation a hundred times, to give it an opportunity to converge, and then plot the next ten values produced.

```#!/usr/bin/python3
import matplotlib.pyplot as plt

l_min=0
l_max=4
l_steps=40

plt.xlim(l_min,l_max)
plt.ylim(0,1)
plt.ion()
plt.show()

for i in range(0,l_steps):
lmbda=l_min+i*(l_max-l_min)/(l_steps-1)
x=0.52
for j in range (0,100):
x=lmbda*x*(1-x)
for j in range (0,10):
x=lmbda*x*(1-x)
plt.plot(lmbda,x,'k.')
plt.pause(0.0001)

plt.ioff()
plt.show()
```

(Note that lambda is a reserved word in python, hence it is abbreviated above.) But there is a problem. The above script took over 50s to run, and the output is a little coarse. Something faster is needed. The slow step is updating the plot for each individual point. We could collect a column's worth, and then make a single call to the plot routine. So the lines from the second `j' loop are replaced by:

```    py=[]
for j in range (0,10):
x=lmbda*x*(1-x)
py=py+[x]
plt.plot([lmbda]*10,py,'k.')
plt.pause(0.0001)

plt.pause(0)
```

and the runtime decreases to under 6s. Much better, so we can afford to adjust the code to give more detail.

```#!/usr/bin/python3
import matplotlib.pyplot as plt

l_min=2
l_max=4
l_steps=200

plt.xlim(l_min,l_max)
plt.ylim(0,1)
plt.ion()
plt.show()

for i in range(0,l_steps):
lmbda=l_min+i*(l_max-l_min)/(l_steps-1)
x=0.52
for j in range (0,100):
x=lmbda*x*(1-x)
py=[]
for j in range (0,200):
x=lmbda*x*(1-x)
py=py+[x]
plt.plot([lmbda]*200,py,'k,')
plt.pause(0.0001)

plt.ioff()
plt.show()
```

(Note the change of the format string on the plot line from `k.` to `k,`, as well as the range increase on the second j loop.) The runtime is back to just under a minute, but at least the result is rather more impressive.

### Further Thoughts

For 1<λ<3 there is convergence to a single value, which must be such that xn=xn+1. What is x as a function of λ?

For 3<λ<3.4494... the series oscillates between two values, so xn=xn+2. What are these values as a function of λ? (Hint: solving quartics is very hard, but solving them when two roots are already known is merely hard.)

Is the region for λ>3.75 just a mess, or is there further structure? Try looking in detail at the range from 3.8 to 3.9 with

```l_min=3.8
l_max=3.9
l_steps=500
```

A sudden window of clarity amongst the chaos (if one has the patience to wait for the ninety seconds or so this will take to run).

### History

The logistic equation was invented in the early 1970s by Robert May (later Baron May of Oxford) in order to model the dynamics of fish populations. It took what was then a very large computer, a CDC 6000 sited in America, to start to reveal the surprising properties of this seemingly-simple equation. Fortunately for us a core of the Pi 4 has over a thousand times the performance of a CDC 6000, whilst the whole of a Pi 4 uses less than a thousandth of the electrical power of the CDC 6000.