# Predicting Fish Populations

Suppose you are studying populations of a particular type of fish found in three different lakes. For each lake, you are able to make a reasonable projection as to the maximum number of fish that could ever be encountered in that lake, based on various natural limitations (e.g., lake volume, predators, etc...). You also discover that the fish populations in any given year, when expressed as a fraction, $x_n$ of this maximum population, adhere to the following quadratic relationship: $$x_{n+1} = r x_n (1 - x_n)$$ where $r$ is some constant value that depends upon the lake being studied.

The fish populations for the three lakes under study for the last 23 years are shown below*.

As can be seen, Lake Lanier, which had an $r$-value of 2.9, has a very stable population -- with an essentially constant percentage around $65.5$% of maximum.

Lake Allatoona had a high percentage in the first year of study, presumably due to a change in fishing regulations made at that time. It took a few years to settle down, but this lake has "stabilized" as well -- just in a different way. Here, the populations are oscillating back and forth between $79.9$% and $51.3$%. Lake Allatoona's $r$-value was $3.2$

Lake Oconee's population, on the other hand, is far from stable --with violent, seemingly chaotic fluctuations taking the fish to the brink of extinction. This lake's $r$-value, $4.0$, was the highest encountered.

You would like to get a better idea of what is happening, and so you decide to simulate the fish populations over time for a continuous spectrum of $r$-values, and display the results graphically in the following way:

Starting with $r=1.0$, you will set the initial population of fish as $x_0 = 0.38$. Then, calculating 100 successive values, $x_1$, $x_2$, $x_3$, ..., using the formula given above, you plot points that represent the last $50$ of these $x_i$ values along a vertical line. That is to say, you plot the points $(r,x_{51})$, $(r,x_{52})$, $(r,x_{53})$, and so on... Note, you don't bother plotting the first $50$ points, as you are interested in the limiting behavior for the $x$-values with a given $r$-value. You wish to know if things stabilize, or not. Hopefully, if there is a limiting behavior for a given $r$-value, the populations will be close to it after $50$ generations.

Then, incrementing the value of $r$ slightly, you do it again, just to the right of the line you just graphed (repeating your initial population of $x_0 = 0.38$). You continue in this way drawing dots on vertical lines that creep slowly to the right until you finally get tired ending with graphing the dots on the vertical line that corresponds to $r=3.9$ (since you already know what happens when $r=4.0$)

To your amazement, you get a diagram that looks similar to the figure in black below:

As can be seen by the annotations in blue and red above -- it appears that: As the value of $r$ rises from $1.0$ the limiting behavior is an essentially constant fish population (once enough time $t$ has passed). Then at some point, the limiting behavior changes to oscillating between two values. As $r$ continues to increase, the limiting behavior "bifurcates" again, bouncing back and forth between 4 different values. At some point, however, $r$ reaches a critical size where the limiting behavior becomes non-periodic (i.e., "chaotic"). As you stare at this amazing diagram, you have many questions. You wonder how exactly when the transition from stability to chaos occurs. It looks like there might be an $r$-value where the limiting behavior involves $8$ values -- is there one where it involves $16$ values? ...$32$ values? ...and what's up with that giant gap near $r=3.85$?

Write a class named FishPopulationPredictor that extends the TwoButtonBreadboard class to investigate this phenomenon further. When executed, a similar diagram should be drawn, but with the user allowed to enter the number of $x$-values to plot for each $r$-value, as well as the number to initially "throw away". The user should also have the ability to zoom in, repeatedly, on different parts of the diagram, as well as resetting the image to its default range of $r=0$ to $r=4.0$.

What happens when you change the initial population value to something besides $x_0 = 0.38$ Does the limiting behavior change?

Check out the video below for how this program might look when executed...

* This is a fictional scenario in the sense that this data was not collected from any real-world lakes -- however, the mathematics here is real. When one finds successive iterates of the equation $x_{n+1} = r x_{n} (1 - x)$, the resulting stability or lack thereof depends entirely on the value of $r$, and in a strange and bizarre way -- as you will see!