Chaos

Post Reply
sky
Posts: 17
Joined: Fri Jun 06, 2008 7:40 pm

Chaos

Post by sky »

A little "game" that some of you may not know: Choose three points in the plane, say A1, A2, A3, and another point P. Now choose a random number, k, between 1, 2, 3, and move P to the midpoint of the segment joining Ak with P. Choose again a number between 1, 2, 3, and so on....

In this way you get an infinite sequence of points (the orbit of the P). What figure does it form? Why if you start with a P already inside this figure all subsequent Ps will still be inside the figure?

(Hint: http://processing.org/ may help if you know a little of Java)
sky
Posts: 17
Joined: Fri Jun 06, 2008 7:40 pm

Post by sky »

Ok, here it is a little ruby code that writes a file "cg.dat" with the coordinates of the points (for those of you who are curios but don't know a little of java)

Code: Select all

#!/usr/bin/ruby

def play(v, p)
  a = v[rand(v.length)]
  return [ (a[0]+p[0])/2, (a[1]+p[1])/2 ]
end

v = [ [0.0, 0.0], [1.0, 0.0], [0.5, 0.866] ]
p = [ 0.5, 0.289 ]
nit = 10e4.to_i

f = File.new "cg.dat", "w"

v.each do |vi|
  f.puts "#{vi[0]} #{vi[1]}"
end

nit.times do
  f.puts "#{p[0]} #{p[1]}"
  p = play(v, p)
end

f.close
then you can plot the file with gnuplot

Code: Select all

#!/usr/bin/gnuplot

set term png
set output "cg.png"
set pointsize 0.01
plot "cg.dat" with points
I suggest to try some modifications like changing the number of points in the array v, or try to modify the code so that some points of v are more likely to come out then the others in the play function...

it's very funny to experiment with this thing :D
sky
Posts: 17
Joined: Fri Jun 06, 2008 7:40 pm

Post by sky »

A friend of mine asked me if i knew any other "strangely behaving thing" like the one above (that is actually called the "chaos game"). Hoping that it will interest somebody else here other then my friend and I, I will post an extremely interesting fact, that is, by the way, the starting point of many dynamical systems courses (so maybe you wont find anything new in the following).

It shows how the same problem, the growth of a population, is deterministic when modeled by continuous time, while chaos arise when modeled by discrete time.

The continuous model is given by the differential equation x' = a x ( 1 - x ) where a is a parameter (this is actually a very basic model of the growth of a population taking account only of reproduction and the competition for resources). This d.e. is integrable (by separation of variables). Solve it, and study qualitatively the solutions (what are the equilibrium points? Are they attracting or repelling? how does the qualitative behavior of the solutions change with a? etc...). You will see that no "chaos" arise.

Now, instead of having the density of population change with continuous time we take it as a function of a discrete variable (it is like saying that we measure it once a year), so that the model would be x[n+1] = a x[n] (1 - x[n]) (where x[n] means x at time n =P). Set a = 0.5, take x[0] in the interval [0,1], try out some iterations, you will see that it is attracted by 0. With a = 2.5 it will be attracted by the other fixed point (that is actually created when a=1). With a = 3.2, after a little while, the orbit will start bouncing between 2 points. At a = 3.5 between 4 points. Try out a = 3.8, you will see chaos. But then at a = 3.835 it will bounce between 3 points. You can keep increasing a till 4, after that the orbit of almost all points in [0,1] will escape to -inf. Almost because there are actually an infinite number of points with a limited orbit, but they form a Cantor set, that has measure 0 (that is 0 probability to get a value inside of it by randomly picking a value in [0,1]).

Hoping you found it interesting (it amused me the first time i saw it),

Sky
Post Reply