Looking at Chaos
Written by Mike James   
Saturday, 05 September 2009
Article Index
Looking at Chaos
Scrolling to plot progress

 

An article in Babbage's Bag is all about chaos and this seems like a good time to have some fun plotting some chaos diagrams and using the scrolling technique described in the recent project Stripchart Scrolling.

The basic idea is very simple. The iteration

x<-ax(1-x)

is performed to see what values of x are generated for various values of the constant a.

The values of a that are of interest are between about 2.95 and 4.00. For this range the iteration stays within the interval 0 to 1 and chaos sets in at about a = 3.5.

When the iteration is started it takes some time to settle down and then it cycles though a finite number of values. The values that the iteration cycles though form the attracting set of the process and it’s these we need to plot.

Start a new C# project and place a button and a picturebox on the form.

form

The form you need to show chaos

 

The button’s click routine does the work of plotting. First we need to make the pictureBox have a persistent drawing surface in the form of a bitmap:

private void button1_Click(
object sender, EventArgs e)
{
Bitmap  BImage1 = new Bitmap(
pictureBox1.ClientSize.Width,
pictureBox1.ClientSize.Height);
pictureBox1.BackgroundImage = BImage1;
Next we work out a scaling that gives the correct range of values for to cover the entire picturebox:
Double a;
Graphics G = pictureBox2.CreateGraphics();
for (int y = 0; y < BImage1.Height; y++)
{
a = 2.95 + (4 - 2.95) *
 y / BImage1.Height;

We then initialise x to some convenient value, the eventual result doesn’t depend much on what this is, and then iterate 500 times to allow transients to die away:

Double x = 0.2;
for(int i = 1;i<500;i++)
{
x = a * x * (1 - x);
}

The next 500 iterations are used to find out what values of x occur in the iteration after the transients have gone:

for ( int i= 1; i < 500; i++)
{
x = a * x * (1 - x);
BImage1.SetPixel(
(int)(x * BImage1.Width),
y,Color.Green);
int y1 =(int) (x * pictureBox2.Height);
G.DrawLine(Pens.Red, 0, y1, 0, y1 + 1);
pictureBox2.Scroll(1, 0);
Application.DoEvents();
}

Finally we Refresh the pictureBox and make sure to dispose of the Graphics object:

  pictureBox1.Refresh();
}
G.Dispose();
}

If you run this finished program you will see the bifurcation diagram for the map - see the next page.

<ASIN:0738204536>

<ASIN:0387202293>

<ASIN:0821801376>

<ASIN:1559533560>



Last Updated ( Saturday, 05 September 2009 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.