HomePage

## Problem 10.1

In [7]:
from IPython.core.display import Image

Out[7]:
In [21]:
#Propagation
from matplotlib.patches import Circle
from matplotlib.patches import Arrow

%pylab inline
fig = plt.figure()

node1=Circle([10,0],1,fill=False)
node2=Circle([0,10],1,fill=False)
node3=Circle([-10,0],1,fill=False)
node4=Circle([0,-10],1,fill=False)

arrow1=Arrow(10,0,-3,0,0.5)
arrow2=Arrow(0,10,0,-3,0.5)
arrow3=Arrow(-10,0,3,0,0.5)
arrow4=Arrow(0,-10,0,3,0.5)

newnode=Circle([0,0],1,fill=True)

ax.set_ylim(-20,20)
ax.set_xlim(-20,20)

plt.show()

Populating the interactive namespace from numpy and matplotlib


In [3]:
#Header
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle
import random
%pylab qt
#--- matplotlib variables-
interval=500
x=[]
y=[]
p=[]
q=[]

# ------------ Initializing Lattice------- :
"""m=134456
a=8121
c=28411
ran=1 """
SIZE=200
L1=np.zeros([SIZE,SIZE]) # inital lattice
L2=np.zeros([SIZE,SIZE]) # updated lattice

#------------ In initializing Lattice :

for i in range(SIZE):
for j in range(SIZE):
#ran=(ran*a+c)%m
L1[i,j]=random.randint(0,16)
if L1[i,j]==15:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

# Making corners zeros
L1[0,0]=L1[SIZE-1,0]=0
L1[0,SIZE-1]=L1[SIZE-1,SIZE-1]=0

# Filling Center - 40 percent x 40 percent dimensions.
for i in range(4*SIZE/10,6*SIZE/10):
for j in range(4*SIZE/10,6*SIZE/10):
L1[i,j]=15
if L1[i,j]==15:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

"""
#as can be seen from table supplied above configuration 5 (0101) <--> needs to be converted into
#case 10.
"""

Table=[0,1,2,3,4,10,6,7,8,9,5,11,12,13,14,15]

for t in range(interval): # for animation
p=[]
q=[]
#-----------------Collison ---------------------
for i in range(SIZE):
for j in range(SIZE):
L2[i,j]=Table[int(L1[i,j])]

#----------- propagation ------------- :
for i in range(SIZE-1):
for j in range(SIZE-1):
L1[i,j]=int(int(L2[i,j-1])&1)+int(int(L2[i-1,j])&2)+int(int(L2[i,j+1])&4)+int(int(L2[i+1,j])&8)

#----------- Boundaries ------------- :

# ------ Upper boundary -----:
for i in range(SIZE-1):
L1[i,0]=int(int(L2[i,1])&1)+int(int(L2[i-1,0])&2)+int(int(L2[i,SIZE-1])&4)+int(int(L2[i+1,0])&8)

# ------ Lower boundary -----:
for i in range(SIZE-1):
L1[i,SIZE-1]=int(int(L2[i,0])&1)+int(int(L2[i-1,SIZE-1])&2)+int(int(L2[i,SIZE-2])&4)+int(int(L2[i+1,SIZE-1])&8)
# ------ Left boundary -----:
for i in range(SIZE-1):
L1[0,0]=int(int(L2[i+1,0])&1)+int(int(L2[i,SIZE-1])&2)+int(int(L2[i-1,0])&4)+int(int(L2[i,1])&8)
# ------ Right boundary -----:
for i in range(SIZE-1):
L1[SIZE-1,0]=int(int(L2[i+1,SIZE-1])&1)+int(int(L2[i-1,SIZE-2])&2)+int(int(L2[i-1,SIZE-1])&4)+int(int(L2[i,0])&8)

for i in range(SIZE):
for j in range(SIZE):
if L1[i,j]==15:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

#----- populating artists----

fig=plt.figure()
ax.set_xlim(0,SIZE)
ax.set_ylim(0,SIZE)

point,=ax.plot([],[],'o-',lw=0.00001)

def animate(i):
thisx=[x[i]]
thisy=[y[i]]
point.set_data(thisx,thisy)
point.
return point,

ani=FuncAnimation(fig,animate,np.arange(1,SIZE),interval=100)


In [5]:
#Header  --- Empty this time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle
import random
%pylab qt
#--- matplotlib variables-
interval=500
x=[]
y=[]
p=[]
q=[]

# ------------ Initializing Lattice------- :
"""m=134456
a=8121
c=28411
ran=1 """
SIZE=200
L1=np.zeros([SIZE,SIZE]) # inital lattice
L2=np.zeros([SIZE,SIZE]) # updated lattice

# Filling Center - 40 percent x 40 percent dimensions.
for i in range(4*SIZE/10,6*SIZE/10):
for j in range(4*SIZE/10,6*SIZE/10):
L1[i,j]=15
if L1[i,j]==15:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

"""
#as can be seen from table supplied above configuration 5 (0101) <--> needs to be converted into
#case 10.
"""

Table=[0,1,2,3,4,10,6,7,8,9,5,11,12,13,14,15]

for t in range(interval): # for animation
p=[]
q=[]
#-----------------Collison ---------------------
for i in range(SIZE):
for j in range(SIZE):
L2[i,j]=Table[int(L1[i,j])]

#----------- propagation ------------- :
for i in range(SIZE-1):
for j in range(SIZE-1):
L1[i,j]=int(int(L2[i,j-1])&1)+int(int(L2[i-1,j])&2)+int(int(L2[i,j+1])&4)+int(int(L2[i+1,j])&8)

#----------- Boundaries ------------- :

# ------ Upper boundary -----:
for i in range(SIZE-1):
L1[i,0]=int(int(L2[i,1])&1)+int(int(L2[i-1,0])&2)+int(int(L2[i,SIZE-1])&4)+int(int(L2[i+1,0])&8)

# ------ Lower boundary -----:
for i in range(SIZE-1):
L1[i,SIZE-1]=int(int(L2[i,0])&1)+int(int(L2[i-1,SIZE-1])&2)+int(int(L2[i,SIZE-2])&4)+int(int(L2[i+1,SIZE-1])&8)
# ------ Left boundary -----:
for i in range(SIZE-1):
L1[0,0]=int(int(L2[i+1,0])&1)+int(int(L2[i,SIZE-1])&2)+int(int(L2[i-1,0])&4)+int(int(L2[i,1])&8)
# ------ Right boundary -----:
for i in range(SIZE-1):
L1[SIZE-1,0]=int(int(L2[i+1,SIZE-1])&1)+int(int(L2[i-1,SIZE-2])&2)+int(int(L2[i-1,SIZE-1])&4)+int(int(L2[i,0])&8)

for i in range(SIZE):
for j in range(SIZE):
if L1[i,j]==15:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

#----- populating artists----

fig=plt.figure()
ax.set_xlim(0,SIZE)
ax.set_ylim(0,SIZE)

point,=ax.plot([],[],'o-',lw=0.00001)

def animate(i):
thisx=[x[i]]
thisy=[y[i]]
point.set_data(thisx,thisy)
return point,

ani=FuncAnimation(fig,animate,np.arange(1,SIZE),interval=100)


## Problem 10.2

In [18]:
Image(filename=('C:/Users/LLP-admin/Desktop/1.png'))

Out[18]:

code for FHP configuration

In [26]:
#Header
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle
import random
%pylab qt

#--- matplotlib variables-
interval=500
x=[]
y=[]
p=[]
q=[]

# ------------ Initializing Lattice------- :
SIZE=200
L1=np.zeros([SIZE,SIZE]) # inital lattice
L2=np.zeros([SIZE,SIZE]) # updated lattice

Table1=[]
Table2=[]
for i in range(64):
Table1.append(i)
Table2.append(i)
if i==9:
Table1.append(18)
Table2.append(36)
if i==18:
Table1.append(36)
Table2.append(9)
if i==21:
Table1.append(42)
Table2.append(42)
if i==36:
Table1.append(9)
Table2.append(18)
if i==42:
Table1.append(21)
Table2.append(21)

#------------ In initializing Lattice :

for i in range(SIZE):
for j in range(SIZE):
L1[i,j]=random.randint(0,64)
if L1[i,j]==63:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

# Making corners zeros
L1[0,0]=L1[SIZE-1,0]=0
L1[0,SIZE-1]=L1[SIZE-1,SIZE-1]=0

# Filling Center - 40 percent x 40 percent dimensions.
for i in range(4*SIZE/10,6*SIZE/10):
for j in range(4*SIZE/10,6*SIZE/10):
L1[i,j]=63
if L1[i,j]==63:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

for t in range(interval): # for animation
p=[]
q=[]
#-----------------Collison ---------------------
for i in range(SIZE):
for j in range(SIZE-1):
L2[i,j]=Table1[int(L1[i,j])]
L2[i,j+1]=Table2[int(L1[i,j+1])]

#----------- propagation ------------- :
for i in range(SIZE-1):
for j in range(SIZE-1):
L1[i,j]=int(int(L2[i,j+1])&1)+int(int(L2[i-1,j+1])&2)+int(int(L2[i-1,j])&4)+int(int(L2[i,j-1])&8)+int(int(L2[i+1,j])&16)+int(int(L2[i+1,j+1])&32)

#----------- Boundaries ------------- :

for i in range(SIZE-2):
L1[i,0]=int(int(L2[i,1])&1)+int(int(L2[i-1,1])&2)+int(int(L2[i-1,0])&4)+int(int(L2[i+1,0])&8)+int(int(L2[i+1,0])&16)+int(int(L2[i+1,1])&32)

L1[i+1,0]=int(int(L2[i+1,1])&1)+int(int(L2[i,0])&2)+int(int(L2[i,SIZE-1])&4)+int(int(L2[i+1,SIZE-1])&8)+int(int(L2[i+2,SIZE-1])&16)+int(int(L2[i+1,1])&32)

L1[i,SIZE-1]=int(int(L2[i,0])&1)+int(int(L2[i-1,0])&2)+int(int(L2[i-1,SIZE-1])&4)+int(int(L2[i,SIZE-2])&8)+int(int(L2[i+1,SIZE-1])&16)+int(int(L2[i+1,0])&32)

L1[i+1,SIZE-1]=int(int(L2[i+1,0])&1)+int(int(L2[i,SIZE-1])&2)+int(int(L2[i,SIZE-2])&4)+int(int(L2[i+1,SIZE-2])&8)+int(int(L2[i+2,SIZE-2])&16)+int(int(L2[i+2,SIZE-1])&32)

L1[0,i]=int(int(L2[0,i+1])&1)+int(int(L2[SIZE-1,i])&2)+int(int(L2[SIZE-1,i-1])&4)+int(int(L2[0,i-1])&8)+int(int(L2[1,i-1])&16)+int(int(L2[1,i])&32)

L1[SIZE-1,i+1]=int(int(L2[SIZE-1,i+1])&1)+int(int(L2[SIZE-2,i+1])&2)+int(int(L2[SIZE-2,i])&4)+int(int(L2[SIZE-1,i-1])&8)+int(int(L2[0,i])&16)+int(int(L2[0,i+1])&32)

for i in range(SIZE):
for j in range(SIZE):
if L1[i,j]==63:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

#----- populating artists----

fig=plt.figure()
ax.set_xlim(0,SIZE)
ax.set_ylim(0,SIZE)

point,=ax.plot([],[],'o-',lw=0.00001)

def animate(i):
thisx=[x[i]]
thisy=[y[i]]
point.set_data(thisx,thisy)
return point,

ani=FuncAnimation(fig,animate,np.arange(1,SIZE),interval=200)

Populating the interactive namespace from numpy and matplotlib


WARNING: pylab import has clobbered these variables: ['random']
%pylab --no-import-all prevents importing * from pylab and numpy


In [28]:
#Header  --- Empty this time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle
import random
%pylab qt
#--- matplotlib variables-
interval=500
x=[]
y=[]
p=[]
q=[]

# ------------ Initializing Lattice------- :
"""m=134456
a=8121
c=28411
ran=1 """
SIZE=200
L1=np.zeros([SIZE,SIZE]) # inital lattice
L2=np.zeros([SIZE,SIZE]) # updated lattice

# Filling Center - 40 percent x 40 percent dimensions.
for i in range(4*SIZE/10,6*SIZE/10):
for j in range(4*SIZE/10,6*SIZE/10):
L1[i,j]=63
if L1[i,j]==63:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

for t in range(interval): # for animation
p=[]
q=[]
#-----------------Collison ---------------------
for i in range(SIZE):
for j in range(SIZE-1):
L2[i,j]=Table1[int(L1[i,j])]
L2[i,j+1]=Table2[int(L1[i,j+1])]

#----------- propagation ------------- :
for i in range(SIZE-1):
for j in range(SIZE-1):
L1[i,j]=int(int(L2[i,j+1])&1)+int(int(L2[i-1,j+1])&2)+int(int(L2[i-1,j])&4)+int(int(L2[i,j-1])&8)+int(int(L2[i+1,j])&16)+int(int(L2[i+1,j+1])&32)

#----------- Boundaries ------------- :

for i in range(SIZE-2):
L1[i,0]=int(int(L2[i,1])&1)+int(int(L2[i-1,1])&2)+int(int(L2[i-1,0])&4)+int(int(L2[i+1,0])&8)+int(int(L2[i+1,0])&16)+int(int(L2[i+1,1])&32)

L1[i+1,0]=int(int(L2[i+1,1])&1)+int(int(L2[i,0])&2)+int(int(L2[i,SIZE-1])&4)+int(int(L2[i+1,SIZE-1])&8)+int(int(L2[i+2,SIZE-1])&16)+int(int(L2[i+1,1])&32)

L1[i,SIZE-1]=int(int(L2[i,0])&1)+int(int(L2[i-1,0])&2)+int(int(L2[i-1,SIZE-1])&4)+int(int(L2[i,SIZE-2])&8)+int(int(L2[i+1,SIZE-1])&16)+int(int(L2[i+1,0])&32)

L1[i+1,SIZE-1]=int(int(L2[i+1,0])&1)+int(int(L2[i,SIZE-1])&2)+int(int(L2[i,SIZE-2])&4)+int(int(L2[i+1,SIZE-2])&8)+int(int(L2[i+2,SIZE-2])&16)+int(int(L2[i+2,SIZE-1])&32)

L1[0,i]=int(int(L2[0,i+1])&1)+int(int(L2[SIZE-1,i])&2)+int(int(L2[SIZE-1,i-1])&4)+int(int(L2[0,i-1])&8)+int(int(L2[1,i-1])&16)+int(int(L2[1,i])&32)

L1[SIZE-1,i+1]=int(int(L2[SIZE-1,i+1])&1)+int(int(L2[SIZE-2,i+1])&2)+int(int(L2[SIZE-2,i])&4)+int(int(L2[SIZE-1,i-1])&8)+int(int(L2[0,i])&16)+int(int(L2[0,i+1])&32)

for i in range(SIZE):
for j in range(SIZE):
if L1[i,j]==63:
p.append(i)
q.append(j)
x.append(p)
y.append(q)

#----- populating artists----

fig=plt.figure()
ax.set_xlim(0,SIZE)
ax.set_ylim(0,SIZE)

point,=ax.plot([],[],'o-',lw=0.00001)

def animate(i):
thisx=[x[i]]
thisy=[y[i]]
point.set_data(thisx,thisy)
return point,

ani=FuncAnimation(fig,animate,np.arange(1,SIZE),interval=100)

Populating the interactive namespace from numpy and matplotlib


WARNING: pylab import has clobbered these variables: ['random']
%pylab --no-import-all prevents importing * from pylab and numpy


In []: