somewhere near the beginning.

A mathematical kind of day

Filed under: Mathematics — Alex @ 4:01 pm 2/18/2005

I’ve had a good day, the kind I imagined that I would have every day when I was in high school thinking about college. The kind I now imagine I will have every day when I’m in grad school… :)

I spent all day thinking about math, talking about it, doing it. Now I have a new project; I was talking to a friend taking a stochastic processes class. He’s been trying to convince me to take it when it’s offered again, but while I can see that it is a practical subject, and would like to know how to use Markov fields to create realistic images— I won’t be taking it, because it has a lot of probability and statistics. I would read a book on it, but not take a class. Then he told me about a non-linear dynamics class that UH used to offer, and mentioned a neat illustration that the prof gave:

A dog is in the center of an equilateral triangle with three trainers at each corner. When a trainer blows the whistle the dog travels in a straight line toward the trainer; when it reaches half-way, a different trainer (a random one of the other two) blows his whistle.

My project is to: think about this problem and see if I can prove something interesting about the dog’s behavior. Also, to write a program that lets you visualize the dog’s behavior– supposedly it is very interesting.

Here’s a Postscript program that simulates the dog’s travels after 101 whistles: (the conversion really loses a lot of information, but you can see there is a definite pattern; if you download the actual program, you can see it much better)

%PS
% visualize the dog training problem
/dogpnts 1 array def
/sidelength 4 def
/nummoves 1000 def
/ptrad 1 def
/triangle [ [0 0] [sidelength 0] [ 60 cos sidelength mul 60 sin sidelength mul] ] def
dogpnts 0 [sidelength 60 cos mul sidelength 60 sin mul 3 div] put
/lastmoveindex 0 def
/curtrainer 0 def
/unit 36 def
/setup {
	20 srand
	unit unit scale
	8.5 sidelength sub 2 div  11 sidelength sin 60 mul sub 2 div translate
	1 unit div setlinewidth
} def
/drawtriangle {
	/x1 triangle 0 get 0 get def
	/y1 triangle 0 get 1 get def
	/x2 triangle 1 get 0 get def
	/y2 triangle 1 get 1 get def
	/x3 triangle 2 get 0 get def
	/y3 triangle 2 get 1 get def
	newpath
	x1 y1 moveto
	x2 y2 lineto
	x3 y3 lineto
	closepath
	stroke
} def
/drawdot {
	dup
	0 get /x exch def
	1 get /y exch def
	gsave
	%1 0 0 setrgbcolor
	newpath
	x y ptrad unit div 0 360 arc
	closepath
	fill
	grestore
} def
/getnewtrainer {
	rand 3 mod
} def
/drawdogmove {
	/lastmoveindex dogpnts length 1 sub def
	/lastpnt dogpnts lastmoveindex get def
	{
		/nexttrainer getnewtrainer def
		nexttrainer curtrainer ne
		{
                  /curtrainer nexttrainer def
                  exit
		} if
	} loop
	/newtrainerloc triangle nexttrainer get def
	% calculate halfway to next trainer
	/newx lastpnt 0 get newtrainerloc 0 get add 2 div def
        /newy lastpnt 1 get newtrainerloc 1 get add 2 div def
	/nextpoint [newx newy] def
	/dogpnts [dogpnts aload pop nextpoint] def
	%newpath
	%lastpnt 0 get lastpnt 1 get moveto
	%newx newy lineto
	%closepath
	stroke
	nextpoint drawdot
} def
setup
drawtriangle
dogpnts 0 get drawdot
nummoves { drawdogmove } repeat

Possibly relevant posts:

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment