##### Personal tools
You are here: Home logmap.py

# logmap.py

A Python program to compute a plot of the logistic map invariant measures.

logmap.py — Python Source, 0Kb

## File contents

```# This program will compute the iterates of the logistic map, and histogram
# them in a two-dimensional (r,x) grid.
# can choose to plot on screen or save as a png.

from pylab import *
screen = True

# The size of the grid in the R and X dimensions, and the range of r
RDIM = 1000
XDIM = 1000
rmin = 3.0
rmax = 4.0

# Get started. Initialize histogram
h = zeros((RDIM,XDIM))

# Will compute all values of r in parallel. So we will have RDIM copies of x, r
x=rand(RDIM) # might want to start from the maximum 0.5, or from random
r= rmin+(rmax-rmin)*arange(RDIM)/(RDIM-1)
in0 = range(RDIM)

# iterate until the transients decay.
for i in range(10000):
x=r*x*(1.0-x)

# iterate and histogram
for i in range(5000):
x=r*x*(1.0-x)
ind = floor( x*(XDIM-1) ).astype(int)
h[in0,ind] += 1

# plot according to choice above.
if( screen ):
imshow(log(h[:,::-1].T+1),aspect='auto',extent=(rmin,rmax,0.0,1.0))
show()
else:
imsave("logmap.png",log(h.T+1),cmap=cm.jet,origin='lower')
```