In his talk Four Ways of Thinking, mathematician David Sumpter did a Chaos experiment with his audience. Here, I have plotted it in Python that shows the chaotic result plot.
Chaos definition: In maths, Chaos means a system where a small difference in a system's starting conditions can lead to huge changes in the final result.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
NUM_ITERS = 100 # can vary this no. of iterations to see how the result plot would change
def eventual_number(x: int) -> int:
"""Both x and return value (y) are between (inclusive) 1 to 99"""
for _ in range(NUM_ITERS):
if x < 50:
x = 2 * x
elif x > 50:
x = 2 * (100 - x)
elif x == 50:
x = 99 # spl case for 50 - doubling would get 100, which is outside required bounds of 0 <= x <= 99
return x
# Draw scatter plot
initial_vals = np.array(range(1, 100))
final_vals = np.array([eventual_number(x) for x in range(1,100)])
plt.scatter(initial_vals, final_vals)
plt.show()
Upon reflection, the above "chaos" plot actually appears to have a regular pattern of rise & fall.
Fun Problem: Try to approximate this with a function 🙂