Home Download Resources Extensions FAQ References Contact Us Models: Library Community Modeling Commons User Manuals: Web Printable Chinese Czech Japanese |
## NetLogo Models Library: |

If you download the NetLogo application, this model is included. (You can also run this model in your browser, but we don't recommend it; details here.) |

## WHAT IS IT?

This model draws a mathematical object called the Mandelbrot set, named after its discoverer, Benoit Mandelbrot. It demonstrates an interesting technique for generating the design as well as providing a nice example of hill climbing.

A number of fractal generation turtles do a random walk across a complex plane, computing one additional iteration of F(Z) = Z<sup>2</sup> + C each time they cross a patch, where C is the coordinates of the patch, and Z is a complex number from the result of the last iteration. A count is maintained of the number of iterations computed at each patch before the complex number at that patch reaches a maximum. This count is then translated into a color, giving the Mandelbrot set its distinctive look.

An interesting way to view the emerging set is that you are looking straight down on one of the Hawaiian Islands. The center is extremely high (infinitely so, in fact), simply because no fixed number of iterations at these points will cause the associated complex number to reach a pre-determined maximum. The edges of the set are steeply sloped, and the "sea" around the set is very shallow.

## HOW IT WORKS

In case you are not familiar with complex numbers, here as an introduction to what they are and how to calculate with them.

In this model, the world becomes a complex plane. This plane is similar to the real or Cartesian plane that people who have taken an algebra course in middle school or high school should be familiar with. The real plane is the combination of two real lines placed perpendicularly to each other. Each point on the real plane can be described by a pair of numbers such as (0,0) or (12,-6). The complex plane is slightly different from the real plane in that there is no such thing as a complex number line. Each point on a complex plane can still be thought of as a pair of numbers, but the pair has a different meaning. Before we describe this meaning, let us describe what a complex number looks like and how it differs from a real one.

As you may know, a complex number is made up of two parts, a real number and an imaginary number. Traditionally, a complex number is written as 4 + 6i or -7 - 17i. Sometimes, a complex number can be written in the form of a pair, (4,6) or (-7,-17). In general, a complex number could be written as a + bi or (a,b) in the other way of writing complex numbers, where both a and b are real numbers. So, basically a complex number is two real numbers added together with one of them multiplied by i. You are probably asking yourself, what is this i? i is called the imaginary number and is a constant equivalent to the square root of -1.

Getting back to the complex plane, it is now easier to see, if we use the paired version of writing complex numbers described above, that we let the real part of the complex number be the horizontal coordinate (x coordinate) and the imaginary part be the vertical coordinate (y coordinate). Thus, the complex number 5 - 3i would be located at (5,-3) on the complex plane. Thus, since the patches make up a complex plane, in each patch, the pxcor corresponds to the real part and the pycor corresponds to the imaginary part of a complex number. A quick word on complex arithmetic and you will be set to understand this model completely.

Two complex numbers are added or subtracted by combining the real portions and then combining the imaginary portions. For example, if we were to add the two complex numbers 4 + 9i and -3 + 11i, we would get 1 + 20i, since 4 - 3 = 1 and 9 + 11 = 20. If we were to subtract the first number from the second number, we would get -7 + 2i, since -3 - 4 = -7 and 11 - 9 = 2. Multiplication is a bit harder to do. Just remember three things. First, remember that i * i = -1. Second, be sure to follow the addition and subtraction rules supplied above. Third, remember this scheme First Outside Inside Last or FOIL for short. In other words, you multiply the first parts of each number, add this to the product of the outside two parts of each number, add this to the product of the inside two parts of each number, and add this to the product of the last two parts of each number. In general, this means given two complex numbers a + bi and c + di, we would multiply the numbers in the following manner:

(a * c) + (a * di) + (bi * c) + (bi * di) = ((a * c) - (b * d)) + ((a * d) + (b * c))i

If we were to multiply the same two numbers from above, we would get -12 + 44i - 27i - 99 = -111 + 17i, since 4 * -3 = -12, 4 * 11i = 44i, 9i * -3 = -27i, and 9i * 11i = -99.

## HOW TO USE IT

Click on SETUP to create NUM-TURTLES fractal generation turtles, place them in the middle of the world (at complex coordinate (0,0)), and scale the 101,101 world to approx -1 to 1 on both the real and complex planes.

To start the calculation, start the slider THROW at 0, press the GO button. Note that the system seems to stall, with each turtle "stuck" on a local maximum hill.

Changing THROW to 7 will "throw" each turtle a distance of 7 each time they reach the top of a hill, essentially giving them a second chance to climb an even greater hill. The classic Mandelbrot shape will begin to appear fairly quickly.

The slider SCALE-FACTOR scales the fractal so that you can see more or less of it. The higher the value, the less of the entire fractal you will see. Be aware that you sacrifice resolution for the price of being able to see more of the fractal.

## THINGS TO NOTICE

Notice that the "aura" around the Mandelbrot set begins to appear first, then the details along the edges become more and more crisply defined. Finally, the center fills out and slowly changes to black.

Notice how different values for THROW change the speed and precision of the project. Also, try running the model with different values for NUM-TURTLES.

## THINGS TO TRY

It's fairly easy to hack at the NetLogo code to change the scale factor --- it's set as the global variable `factor`. You might also think about adjusting the viewport in the plane, to allow for a larger picture (although the smaller sized picture might look better and emerge quicker).

You might also play with the colors to experiment with different visual effects.

Notice also what happens when you turn off climbing and/or wiggling.

## EXTENDING THE MODEL

Try to produce some of the other complex sets --- the Julia set for instance. There are many other fractals commonly known today. Just about any book on them will have several nice pictures you can try to duplicate.

## NETLOGO FEATURES

To accomplish the hill climbing, the code uses `current-count` and `previous-count` turtle variables, comparing them to one another to establish a gradient to guide turtle movement. The goal of each turtle is to move up the emerging gradient, "booting itself up" to the ever growing center of the set.

Note that complex arithmetic is not built in to NetLogo, so the basic operations needed to be provided as NetLogo routines at the end of the code. These complex arithmetic routines are also used in other fractal calculations and can be tailored to your own explorations.

## CREDITS AND REFERENCES

You may find more information on fractals in the following locations:

This site offers an introduction to fractals:

http://web.cs.wpi.edu/~matt/courses/cs563/talks/cbyrd/pres1.html.

An introduction to complex mathematics and the Mandelbrot set.

http://www.ddewey.net/mandelbrot/

An introductory online textbook for Complex Analysis.

(Note: This is a college level text, but the first chapter or so should be accessible to people with only some algebra background.)

http://people.math.gatech.edu/~cain/winter99/complex.html

_The Fractal Geometry of Nature_ by Benoit Mandelbrot

## HOW TO CITE

If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

* Wilensky, U. (1997). NetLogo Mandelbrot model. http://ccl.northwestern.edu/netlogo/models/Mandelbrot. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

Please cite the NetLogo software as:

* Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

## COPYRIGHT AND LICENSE

Copyright 1997 Uri Wilensky.

![CC BY-NC-SA 3.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png)

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2001.

(back to the NetLogo Models Library)