Saturday, December 12, 2009

Intro To Computer Science Lesson Plan : Visualizing Chaos via Orbit Diagrams of Logistic Map and the Henon Map



Last Fall I taught a class to incoming Freshman to introduce "interesting" ideas from the field of Computer Science. I tried to create some labs that would engage the students without being too technical or too dumbed-down. One successful lab had the students take a well-known chaotic function known as the logistic equation x(n+1) = r*x(n)*(1-x(n)) and asked them to try to form a visualization. Here are some of the results of the students.

Here are project results from CS0 students: Daniel Hagerstrand, Cody Mays, and Scott Resnick



Here is basic python code that generates the graphic for the orbit diagram of the logistic equation:



from Tkinter import *
import random
root = Tk()
canvas = Canvas(width=1000, height=750, bg='white')
canvas.pack(expand=YES, fill=BOTH)
text = canvas.create_text(50,10, text="Chaos Test")

def drawcircle(canv,x,y,radius,color):
canvas.create_oval(x-radius,y-radius,x+radius, y+radius,width=0,fill=color)

# Feigenbaum bifurcation values.
# b1 = 3, b2 = 3.449490…,
# b3 = 3.544090…, b4 = 3.556441…, b5 = 3.568759…, and b6 = 3.569692

r=2.4
while r < 4:
for pix in range(50):
x = random.random()
for i in range(100):
x = r*x*(1-x)
drawcircle(canvas,x*1000,(r-2.4)*(750/1.6),1,'blue')
r+=0.005
root.mainloop()























Here is basic python code that generates the graphic for the orbit diagram of the Henon Map:



from Tkinter import *
import random
root = Tk()

def drawcircle(canv1,x,y,radius,color):
canv1.create_oval(x-radius,y-radius,x+radius, y+radius,width=0,fill=color)

canvas = Canvas(width=1400, height=800, bg='white')
canvas.pack(expand=YES, fill=BOTH)
text = canvas.create_text(100,10, text=" Orbit Diagram of the Henon Map")


def HenonMap(a,b,x,y):
return y + 1.0 - a *x*x, b * x

# Map dependent parameters
a = 1.4
b = 0.3
iterates = 100000

xtemp = 0.1
ytemp = 0.2

for pix in xrange(0,iterates):
xtemp, ytemp = HenonMap(a,b,xtemp,ytemp)
drawcircle(canvas,400*xtemp+750,1000*ytemp+400,1,'blue')

root.mainloop()




No comments:

Post a Comment