Surprising Stability

I wrote an oscillating program of two variables where a small part of each feeds into the other. I expected it to explode to infinity or collapse to zero but neither happened. This says modern floating point calculation is pretty darn good.

Starting with initial conditions.

x = 1 y = 0

Loop endlessly with negative feedback.

x += 0.0001 * y y -= 0.0001 * x

Watch x pass through 1 again while y passes through 0.

1.00000 0.00064 1.00000 0.00054 1.00000 0.00044 1.00000 0.00034 1.00000 0.00024 1.00000 0.00014 1.00000 0.00004 1.00000 -0.00006 1.00000 -0.00016 1.00000 -0.00026 1.00000 -0.00036 1.00000 -0.00046 1.00000 -0.00056

Here is a perl command-line program that will print this region of the oscillation each pass through.

perl -e ' $x = 0; $y = 1; while(true) { if $x > 0.999997 { printf("%.5f %.5f\n", $x, $y); } $x += $y * 0.0001; $y -= $x * 0.0001; } '

On my computer there is just enough pause as the oscillator runs around again to get a nice animation effect in the terminal output.

See System Dynamics where we discuss how one might explore models with feedback inside wiki.

It is easy to explore feedback effects in spreadsheets by calculating each row from the previous. However, the limited number of rows makes it hard to use a small step size and without that stability cannot be expected.