Simple Chaos: A Three Body Problem

Woke up to find this elegant little conceptualization in my inbox. It’s from Jim Lyons, who is one of the alpha boffins on the ridiculously helpful netlogo-users discussion group. While I was preparing my hangover, apparently Jim was preparing something for me to peer at through it.

(I stuck an online version here if you want to see it go. I recommend slowing it down a little.)

Simple Chaos
Posted by: “Jim Lyons”
This simple model exhibits chaotic behavior with very little code.

Each turtle moves towards the centroid of the others, accelerating at a
rate inversely proportional to its distance from that point — except
when the distance is below a certain small threshhold, it just coasts.

As you watch the turtles wander erratically, remember that the code
they are executing is entirely deterministic — randomness is used only
to set their starting positions. Even so, very slight differences at
the beginning produce very different outcomes, the defining
characteristic of chaotic systems.

It is really quite entertaining, and is fun with more than 3 turtles,
too. (It even works with only two turtles.)

Paste this code into the Procedures of a new NetLogo 4 model. In the
Interface, make setup and go buttons and set View Updates to On Ticks.
Enjoy!

Jim Lyons

————-
turtles-own [ vx vy ] ; x and y components of velocity

to setup ;by observer
clear-all
ask patches [ set pcolor sky + 3 ]
create-ordered-turtles 3
[ set shape “circle” jump 1 + random-float .1 ]
end

to go ;by observer, forever
foreach sort turtles [ ask ? ; this keeps order same
[ setxy (xcor + vx) (ycor + vy) ; update position
; find centroid of others
let $x mean [xcor] of other turtles
let $y mean [ycor] of other turtles
let $d distancexy $x $y
if $d > .02 ; apply acceleration if not too close
[ facexy $x $y ; so dx and dy yield components
set vx .9 * vx + .01 * dx / $d
set vy .9 * vy + .01 * dy / $d
]
]]
display
end

leave a comment