Welcome to Project Lovelace! We're still in early development so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or comments please let us know on Discourse, Discord, or GitHub!

# Chaos

## You will learn about: chaos theory and loops.

Let's look at an example of chaos arising from simplicity in nature: the logistic map. It's a simplified model used to describe population sizes and can be written mathematically as $$x_{n+1} = rx_n(1 - x_n)$$ where $0 < r < 4$ is a parameter and $0 < x_n < 1$ represents the population size at time step $n$. Starting with an initial population size of $x_0 = 0.5$ and $r$ as an input parameter, return a list of the first 50 values of the logistic map $x_0, x_1, x_2, \dots, x_{49}, x_{50}$. You should see different behavior depending on the value of $r$, but we'll leave you to play around with it and we'll have more to say in the solution notes.

Input: The parameter $r$.

Output: A list containing the first 51 values of the logistic map $(x_0, x_1, x_2, \dots, x_{49}, x_{50})$.

Example 1 (population growth)

Input: 2.81 Output: [0.500000, 0.702500, 0.587272, ⋯, 0.644125, 0.644130, 0.644126]

Example 2 (steady state)

Input: 2 Output: [0.5, 0.5, 0.5, ⋯, 0.5, 0.5, 0.5]

Example 3 (chaotic behavior)

Input: 3.88 Output: [0.5, 0.97, 0.112908, ⋯, 0.940932, 0.215644, 0.656271]
 Difficulty logistic_map(r)

You must be logged in to view your submissions.

### Notes

• The sensitivity to initial conditions exhibited by the logistic map is more commonly known as the butterfly effect. It means that unless you knew the initial conditions exactly, there will be uncertainty in future predictions and is why we can only predict the weather up to roughly two weeks ahead (much less in many cases).
• If you plot the value the logistic map ends up at for each value of $r$ you get a bifurcation diagram for the logistic map, which matches up beautifully with the Mandelbrot set if you're into that sort of thing.

### References

May R.M., Simple mathematical models with very complicated dynamics, Nature 261 (1976)
The logistic map was first introduced as a simple model of population dynamics with very complicated dynamics.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.