# LogisticMap2ICs.py: Illustrate sensitive dependence on initial
#                     conditions in the logistic map.
#                     Based on LogisticMap.py, we look at the time series
#                     of two close initial conditions.

# Import plotting routines
from pylab import *

#
# Simulation parameters
# A chaotic parameter setting
r  = 3.7
# Initial condition loaded into the array for time series 1
x1 = [0.1]
# A nearby initial condition loaded into the array for time series 2
delta = 1e-5
# Initial condition number 2, which starts close to x1
x2 = [x1[0] + delta]
# The number of iterations to generate
N  = 50

# The loop that generates data
for n in xrange(0,N):
  x1.append( r*x1[n]*(1.-x1[n]) )
  x2.append( r*x2[n]*(1.-x2[n]) )

# Setup the plot
xlabel('Time step n') # set x-axis label
ylabel('x(n)') # set y-axis label
# Set plot title
title('Logistic map at r= ' + str(r))
# Plot each time series
#   The first is red circles connected by a blue line
plot(x1, 'ro', x1 , 'b')
#   The second is yellow diamonds connected by a green line
plot(x2, 'yD', x2 , 'g')

# Use command below to save figure
#savefig('LogisticMap', dpi=600)

# Display the plot in a window
show()
