“Logistic Equation” with Python & Feigenbaum Constant
“Logistic Equation” has many applications in various sciences. This simple equation is used in biology, quantum physics, and many other sciences. Even the contribution of this equation to understanding complex natural systems is very significant. However, the applications of “Logistic Equation” are not the subject of this article, but in this article only for different values of “R”, the results of this equation are examined and analyzed in successive iterations.
The name of this equation has always been associated with concepts such as “Bifurcation” and “Chaos”. Finally, in the 1970s, Feigenbaum was able to compile a list of “R” values in which bifurcation occurs. Of course, he only used a programmable calculator. He was amazed when he calculated the convergence speed of the “R” values. Because this value was constant. Even when he looked at some similar equations, he was surprised to find that the convergence rate of “R” values was similar. This amount has been used as “Feigenbaum Constant” for many years by scientists around the world.
Some time ago we decided to use Python and increase the number of iterations. That is, we were interested in repeating previous work with high accuracy. Then we wanted to make tables as well as diagrams of the results. But in doing so, we realized another astonishing fact about the results of this equation, and we were really surprised. We realized that at each stage, and exactly at the location of the bifurcation, we again see a kind of chaos. That is, for example, when (R=3), even if we do even one hundred million initial iterations, the results of the equation still do not converge !!! we discovered this fact by accident.
If the description seems vague or inadequate, please do not worry. In the following, we will examine all the issues separately. Descriptions, codes, and diagrams will also help make everything clear. This article was written in November 2021 by Somayyeh Gholami and Mehran Kazeminia.
Logistic Equation
The logistic equation (sometimes called the Verhulst model or logistic growth curve) is a model of population growth first published by Pierre Verhulst (1845, 1847).
Before we start quantifying the equation and iteration, please note a few important points:
- The value of x0 is between zero and one.
- The value of R is between two and four.
- Given the above values, it can be easily proved that the results of the equation will surely be between zero and one.
- Therefore, iterations can continue indefinitely.
- This is not the subject of this article when the values of “R” and “x0” are not in the upper range.
The codes of this article can be uploaded from our notebook in Kaggle:
In addition, these codes are also available on GitHub.
Step 1 — Logistics function
We wrote a general function in Python to calculate the results of the Logistic Equation. This function takes the values of “R” and “x0” as well as the number of consecutive iterations and then plots the results of all iterations in a diagram.
If R = 2, the result of the equation will be 0.5 after a maximum of several iterations, and then in all subsequent iterations, the result will be a constant of 0.5. (Fixed Point)
logistic(2, 0.99, 30, 103)
If R = 2.5, the result of the equation will be 0.6 after a maximum of several iterations, and then in all subsequent iterations, the result will be a constant 0.6. (Fixed Point)
logistic(2.5, 0.5, 30, 105)
But if “R” is slightly larger than the value of 3, for example, “R = 3.1”, after a few initial iterations we see that the result of the equation in all subsequent iterations will be two different constant numbers. (Period=2)
logistic(3.1, 0.85, 90, 108)
If we increase the value of “R” again, for example, “R = 3.45”, after a few initial iterations we see that this time the result of the equation will be four different constant numbers in all subsequent iterations. (Period=4)
logistic(3.45, 0.30, 90, 109)
If we increase the value of “R” again, for example, “R = 3.555”, after a few initial iterations we see that this time the result of the equation will be eight different constant numbers in all subsequent iterations. (Period=8)
logistic(3.555, 0.30, 90, 110)
As you can see, by increasing the value of “R”, each time the number of periods doubles. But if “R = 4.0”, something new happens. Even after many initial iterations, all results in subsequent iterations are different. That is, this equation appears to generate random numbers. This is called Chaos.
logistic(4.0, 0.30, 120, 201)
Another important point is that when it is “R = 4.0” if the value of “x0” changes very, very small, the results of the equation in successive iterations are new random numbers that bear no resemblance to the previous results. By the way, we can not assume the value of “x0” with infinite decimal places, so it is practically impossible to predict the results.
Suppose the example above is “x0 = 0.3000000001”, the result changes dramatically. This means that if you look closely at the new results in the diagram below, you will find no resemblance to the diagram above.
logistic(4.0, 0.3000000001, 120, 202)
Step 2— The bifurcation diagram of the Logistic Equation.
In this step, we want to plot the results of the “Logistic Equation” for a thousand different values of “R” (between 2 and 4) in a diagram. For each point, we increase the number of iterations to 500 times. Of course, we only draw the last 100 iterations, and the first 400 iterations are an opportunity for possible convergence.
As you can see in the diagram above; we have only one answer for each value of “R” between 2.0 and 3.0 (Fixed Point). But for any value of “R” between 3.0 and 3.449, we will have two answers (Period=2)…. And if “R” is equal to 4.0, we have infinite answers (Chaos).
Step 3— Feigenbaum Constant
The Feigenbaum constant delta is a universal constant for functions approaching chaos via period-doubling. It was discovered by Feigenbaum in 1975 (Feigenbaum 1979) while studying the fixed points of the iterated function.
The first Feigenbaum constant δ is the limiting ratio of each bifurcation interval to the next between every period-doubling, of a one-parameter map.
30 decimal places : δ = 4.669201609102990671853203820466
The results of Feigenbaum calculations, which correspond to the diagram above, are as follows:
Step 4— Another astonishment of the Logistic Equation
“Feigenbaum Constant” is of special importance in various sciences and especially in understanding complex natural systems. That’s why we want to do these calculations once again and of course differently. That is, this time instead of just finding the results and plotting them, for each value of “R”, we get all the solutions of the equation in successive iterations and put them in a definite set. We then count the number of non-repetitive numbers in each of these sets. Finally, we draw the results of the count in a diagram.
In this step, we calculate the results of the “Logistic Equation” for 20,000 different values of “R” (between 2 and 4). And for each of these points, we increase the number of consecutive iterations to 1,200. Of course, we only consider the last thousand iterations, and the first 200 iterations are an opportunity for possible convergence.
So we have 20,000 different values for R. First to do 1200 iterations for the first value of R (The first 200 iterations are an opportunity for possible convergence). This way, we get a thousand results for the value of x. Then we count the non-repetitive numbers of these 1000 results. For example, if all are equal, the number “1” (Fixed Point), if there are two types of numbers, the number “2” (Period=2), or if all the results are different, the number “1000” (Chaos) is the result of the calculations of this step. The calculations for the first value of R are completed and fortunately, only 19999 is left :) Finally, we draw all 20,000 results in a diagram.
WOW!
The diagram above clearly shows that another strange event occurs exactly at the points that Feigenbaum has identified as the location of the bifurcation (period-doubling).
For example, when R=2.7, the equation is convergent and all our thousand of results are equal (Fixed Point). But as the R gets bigger and bigger and closer to 3.0, the number of non-repetitive numbers increases, so much so that in the range R=3.0 every thousand results differ. But when the value of R gets bigger and bigger than 3.0, the number of non-repetitive numbers gradually decreases. For example, when R=3.2 is, the number of non-repetitive numbers is equal to two. That is, the same number we expect because R=3.2 is in the range Period=2.
This seems to happen to all points of the bifurcation, although it may be difficult to detect in the small diagram above (even the difference between 1, 2, 4, and even 8 is a bit difficult). That’s why we have to go to the numbers themselves.
Selecting points
As you can see many points do not converge based on the Feigenbaum bifurcation diagram. Rather, there are differences between the results in these points. Of course, these differences are small, but in different sciences, if large coefficients are multiplied by the results of the “Logistic Equation”, it can be problematic.
Of course, we currently have 200 initial iterations that are ignored. If we consider this number as millions, we see that the number of converging points increases more and more. But the points that Feigenbaum has identified as a place of bifurcation will still not converge. For example, if you get a thousand results in consecutive repetitions for these points, every thousand results are slightly different from each other and we see a suspicion of chaos in the results.
To prove this, we consider the number of initial iterations to be ten million 10,000,000, that is, we allow the results to converge with ten million consecutive iterations. Then with another 1000 iterations, we get the main results.
Of course, we only try 14 values of R; That is, 7 points that Feigenbaum identified as the location of the bifurcation, and another 7 points between the previous values. Also, as mentioned, we get a thousand results for each of the 14 points. Finally, we will print the number of non-repetitive numbers for the results of each of the 14 points.
When R=2.8
the number of non-repetitive numbers is equal to: 1
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.0
the number of non-repetitive numbers is equal to: 1000
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.2
the number of non-repetitive numbers is equal to: 2
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.4494897
the number of non-repetitive numbers is equal to: 1000
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.5
the number of non-repetitive numbers is equal to: 4
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.5440903
the number of non-repetitive numbers is equal to: 1000
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.55
the number of non-repetitive numbers is equal to: 8
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.5644073
the number of non-repetitive numbers is equal to: 1000
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.566
the number of non-repetitive numbers is equal to: 16
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.5687594
the number of non-repetitive numbers is equal to: 1000
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.569
the number of non-repetitive numbers is equal to: 32
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.5696916
the number of non-repetitive numbers is equal to: 1000
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=3.5697
the number of non-repetitive numbers is equal to: 64
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::When R=4.0
the number of non-repetitive numbers is equal to: 1000
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The above results prove that even if we consider the initial ten million iterations, the results will still not converge in all the places that Feigenbaum has identified as a place of bifurcation. That is, we are facing a phenomenon similar to chaos. As mentioned earlier; The difference in results is small, but if these results are multiplied by large coefficients, scientific calculations and predictions become problematic. Moreover, if the initial iterations are low, the difference in results will increase.
Results variance of one point
To complete this description, we draw the variance of all the answer lists in a diagram.
Summary & Conclusion
First, with a few examples, we explained the concept of bifurcation in the “Logistic Equation” results. It was also found that the results of this equation do not always converge and even reach chaos in some places. In the chaos phase, the results are unpredictable with the slightest change in the initial value. The results of this equation in the chaos stage can be used to generate random (quasi-random) numbers.
In the following, we examined the “Feigenbaum constant”. It was also found that at each stage, and exactly at the location of the bifurcation, we again see a kind of chaos. That is, for example, when (R=3), even if we do one hundred million initial iterations, the results of the equation still do not converge.