# Programming Mathematical Models ... with NetLogo

Última modificación: 18 de Julio de 2016, y ha tenido 109 vistas

Etiquetas utilizadas: || || || || ||

These icons link to social bookmarking sites where readers can share and discover new web pages.

This post has the goal to serve as guide for the session "Programming Mathematical Models ... with NetLogo" from the 5th International Summer School of Mathematics in Seville, between July 15th and 31st 2016.

For this reason, this post is more like a set of notes to focus our achievements that something to read from outside... sorry for those coming from outside the Summer School, as it can be of little interest for them.

## Objective

The main objective of this session is showing how to use mathematical computational models (that is, programming in a adequate environment) as a tool for experimenting and improving knowledge in math. For that, we will take a BIG problem, that cannot be totally explained with current math developments, and will provide some models for playing, getting experience, formulating hypotheses and testing ideas on the math object behind.

Actually, this can (and must) be done with ALL the mathematics we find, but we will take some Complex System related content, as it is not so usual for the beginners. Specifically, we will play around Cellular Automata as representatives of mathematical objects with a simple definition but with complex evolution in time.

## Resources

You can find the slides used in the session here. Please, remember that it is lesson oriented, so the slides are incomplete since some of the main aspects have to be discovered by the students while discussing about them.

After the theoretical presentation we will build a series of models using NetLogo as programming and experimentation framework (modeling and simulation) that will take us from a very simple (and wrong) model to a complete model for 2D Cellular Automata. After that, we will optimize our model to work with the popular and fascinating Game of Life case (from John H. Conway).

### Version 1.0

We show here a very basic implementation of a first 2D CA. The initial program is given, so we will not start from scratch.

Cells are Patches and we store the information (state) of the cells in the color:

white -> alive
black -> dead

NetLogo concepts: ca, ask, one-of, count, neighbors, with, use of [...] blocks, if, ifelse, lists

#### Some exercises

1. base-colors is the list of basic colors in NetLogo. Give a procedure to, randomly assign a color to every patch in the world.
2. Create a procedure that randomly selects a patch and colors its neighbors with the same color of it. Assign this procedure to a forever button.
3. Create a procedure that changes all black patches to white, and the others to green.

### Version 2.0

Compute num-neigh out of the alive/dead checking.

Use the concept of list to store rules and reduce the transition computation.

NetLogo Concepts: item

### Version 3.0

Create state patch property to store the state of every cell, and change its value to 0/1.

Assign color by using a ifelse structure.

Assign color by using lists adequately.

### Version 4.0

Create recolor patch procedure. Explain patches procedures and contexts.

Create global variables for alive-rule and dead-rule.

Create a procedure to create rules independently (they will be prefixed in this point).

Don’t forget to remove ca.

Emphasize differences between let and set.

### Version 5.0

Create a patch predicate (0/1 report) alive?

Reports: Emphasize differences between to and to-report.

NetLogo concepts: true/false, comparisons, report

#### Some exercises

1. Create a report to calculate that receives two numbers and report the biggest one.
2. Create a patch report to return the number of neighbors with the same color to it.

### Version 6.0

Parallelism problem: create patch property new-state and adapt the program by doing a 2-stages process in step procedure.

### Version 7.0

Create random rules.

Play with random rules and try to find interesting behaviors.

NetLogo Concepts: n-values

#### Some exercises

1. Use n-values to return the following lists: $$[0\ 1 \ \dots\ n]$$, $$[0\ 2\ \dots\ 2n]$$, $$[0\ 1\ 4\ 9\ \dots\ n^2]$$, $$[0\ \dots\ 0]$$
2. Create a report that receives 2 numbers, m and n, and returns the list of length n with all its elements as m: $$[ m\ m\ \dots\ m]$$

### Version 8.0

Statistical problems in the random construction of rules:

1. How is the mean rule we can build?
2. How can we solve it?

One possible way:

Represent rules in decimal way, use the random in this new representation, and then convert to binary (be careful with the :size: of the resulting list).

1. How many rules can we obtain?

NetLogo concepts: recursion, sentence, mod, random, length, lput, int

#### Some exercises

1. Create a report that receives a number n, ad returns a list of n random numbers between 0 and 99.
2. Create a report to return the list of divisors of a number.
3. Create a report to say if a number is prime or not.
4. Create a report to convert from binary to decimal.

### Version 9.0

Add new types of starting worlds and options to draw/erase by hand.

Create procedure for Game of Life.

Improve looking.

NetLogo concepts: mouse instructions, in-radius, sliders, notes

### Version 10.0: GoL

Convert execution mode from continuous to ticks.