Skip to content

Chaos in simple systems

This is a program that graphs and displays chaos in Python code.\ It is an example of how Chaos can emerge from simple systems; in this case, a model for population growth.\ The model we will use is known as the Logistic Map:

\(x_{n+1} = rx_n(1-x_n)\)

Here \(x_{n+1}\) represents the population in the next generation.\ \(x_n\) is the current population.\ \(r\) is the rate of reproduction.\ And the amount of resources available is given as \(1-x_n\).

First we import the Python library mathplotlib - this allows us to display our model visually.

import matplotlib
import matplotlib.pyplot as plt

Next we define the logistic map equation as a function

def Pop_growth(r, x): # model / function

    total = (r*x*(1 - x))        # r = rate of growth, x = population size
    return total

Here we set values for the variables.

a, b = 4, .02     # rate of growth a = r = 2.7, initial pop size b = x = .02
i = 1

Then we create a time component, represented by a for loop.

for i in range(30):

    print(Pop_growth(a, b))

    b = Pop_growth(a, b)    # set b = previous population size
    i+=1

    plt.scatter(i, b)
    #plt.pause(.3)

#plt.grid()
plt.show()    
0.0784
0.28901376
0.8219392261226496
0.585420538734198
0.9708133262494375
0.1133392473037629
0.4019738492975175
0.9615634951138167
0.14783655991327094
0.5039236458651232
0.9999384200125004
0.00024630478161879977
0.0009849764622934059
0.0039360251346485355
0.015682131363151802
0.06174480847624261
0.23172954840989893
0.712123859214573
0.8200138734076641
0.5903644833064942
0.9673370406270013
0.12638436183198606
0.44164541966523074
0.9863789718158118
0.053741983101575
0.2034151294155401
0.6481496581615968
0.9122067151464082
0.32034249595283165
0.8708927249581668