Logistic Map in Python
Last Updated on Saturday, 17 July 2010 14:54 Written by Mehmet Ali ANIL Saturday, 24 April 2010 19:52
Whenever I have an assignment to do, I try to do it in a procedure, or a style that I am not familiar with and also that I am eager to learn. This was once typesetting with LaTeX2e, now I am messing around with Python, so instead of realizing Logistic Map in Matlab, I tried to accomplish the task that was given in Python, though I had to put more effort in doing so.
For the more technically inclined, I am using Python 2.6.4, with Stani's Python Editor, on Ubuntu. I don't think that would make a lot difference, but for the sake of precision, I wanted to state it. In my opinion, those are a good choice to start, and also I will try Eclipse with Pydev, since it is an IDE I am more accustomed with.
The Logistic map is a second order mapping, that is also called a logistics equation in which I will be analyzing as a discrete mapping henceforth. So in our case,
And we are going to use our logistic map such that the output generated by an nth of a series, will be introduced to another logistic function, so (n+1)th element of the series is obtained. In a more compact way:
that relation causes a simple bevahior when x values evolve with time if r<3. Simply, x values converge into a finite, real value when this relation holds. If r=3, the system undergoes a bifurcation and two different equillibrium points are generated. The behaviour of the system gets more and more complex with r getting larger. At some point, the system behaves chaotically, in other words, the values diverge form the values when x is introduced with an infinitesimally small perturbation.
I coded in a function oriented fashion, though Python is a language that is designed for an object oriented coding style. The following can also be witthen in C pretty easily, and the runtime would be much less. Also, those are coded in a non-optimized way, I guess I like using Python a bit like Matlab, It eases brainstorming with coding.
As a result, one can easily obtain this beautiful bifurcation diagram:
A bifurcation diagram is obtained with plotting persistent slotions, or equilibrium points with respect to the bifurcaion parameter, that was r in our case. Despite of seeing that a very simple mapping rule turns out to be so exotic and complex in action, it was a relief to see that logistics map has values of r, that it returns to acting like it has finite points. Just like an eye of a tornado, from a distinctive chaotic behaviour, with a little change in parameter r, it intoduces a silent, predictable state space.
The code provided does a similar thing, but in a rather crude way. I will optimize it, and play with it more, add more chaotic maps to it, and also add the ability to draw Cobweb diagrams.
I encourage you all to spend some time with Python, it is an easy programming language and it has lot of modules that can be implemented with an easy line of code. Python can be used in an interactive mode, just like Matlab, so that you can play with your data, or alter it in real time. It is not a Matlab alternative in may ways, but it is fun to use it.



