#This program will plot time vs total popluation for a fixed d and r=r1=r2

#dynamic equations:
from CpledLogClass import *

import pylab as pl
from RandomArray import *

#set values of parameters
r1=3.8
r2=3.8
d=0.15

#set dynamics equations from the class with the above parameters:
F=CpledLogEqs(r1,r2,d)

#we will sweep over an array of intial conditions chosen from a uniform [0,1] distribution:
seed()

x1_0=[uniform(0,1)]
x2_0=[uniform(0,1)]

for i in range(1,6):
	x1_0.append(x1_0[0]+i*.001)
	x2_0.append(x2_0[0]+.001*i)
nTrans=100
nIterations=20
time=range(nIterations)

count=0

f=pl.figure(1,(14,7))
f.text(.5,.95,'r1=%g r2=%g d=%g'%(r1,r2,d))
#colors for different time series:
c=['b.','g.','r.']
for i in range(len(x1_0)):
	count=count+1
	x1=x1_0[i]
	x2=x2_0[i]
	
	for n in range(nTrans):
		x1temp=F.x1dot(x1,x2)  #we need the value of x1 at the previous time to calc x2dot
		x2=F.x2dot(x1,x2)
		x1=x1temp
	
	#we want to store the next iterations as well as their sum to make plots:
	x1vals=[]
	x2vals=[]
	pop=[]
	
	for n in range(nIterations):
		x1temp=F.x1dot(x1,x2)
		x2=F.x2dot(x1,x2)
		x1=x1temp
		sum=x1+x2
		x1vals.append(x1)
		x2vals.append(x2)
		pop.append(sum)
	
	pl.subplot(2,3,count)
	pl.title('X_0=(%.5f,%.5f)'%(x1_0[i],x2_0[i]))
	pl.xlabel('n')
	pl.plot(time,x1vals,c[0],label='x1(n)')
	pl.plot(time,x1vals,'b')
	pl.plot(time,x2vals,c[1],label='x2(n)')
	pl.plot(time,x2vals,'g')
	pl.plot(time,pop,c[2],label='x1(n)+x2(n)')
	pl.plot(time,pop,'r')

pl.legend()
pl.show()
	
