pt+1 = r * pt * (1 - pt)
This is an iterative equation because the value of pi depends on the value of pt-1. Given the values of r and p0 it seems trivial to write a computer program that calculates pt for arbitrary t. In fact matters are a little more complicated than they seem at first. In particular, depending on the value of r, this equation can be chaotic and exhibits sensitive dependence on initial conditions.
Generally the equation is subject to these constraints:
0 <= p0 <= 1
0 <= r <= 4
Normally p is called the population, r the rate, and t the time. With this interpretation the meaning of the first condition above becomes obvious. The population is always between 0% and 100%.
populationt+1 = rate * populationt * (1 - populationt)
If you like you can think of population as a function of three variables, time (t), initial population, and rate. However, the long-term behavior of this equation mostly depends on the rate, not the generation or the initial population. For rates less than 3, the population converges to one value. The speed and nature of that convergence (with or without overshoot) depends on the rate, In particular 1, 2, and 3 are all critical points where the behavior of the equation over time exhibits qualitative change. Between 3 and 3.57, the equation oscillates between values, initially between two values, then four, then eight, then sixteen, and so on until chaotic behavior sets in around 3.57. though there are occasional islands of stability (for instance at ????).
Chaos: Making a New Science
Use full-length variable names (e.g. population rather than p).
Indent code with spaces rather than tabs.
Do not overdo it. This is a straight-forward and simple problem that requires a straight-forward and simple answer.
Include your name, email address, homework number (1), and a brief description of the problem in header comments. Include other comments as necessary.
Be sure to handle all user errors (e.g. not providing three values on the command line) to the extent possible. Check the ranges of the data the user enters (e.g. don't let population be bigger than 1 or less than 0). Print an error message and exit if a value outside the allowed range is entered. Provide a default value if none is given.
Be sure to handle all user errors (e.g. not providing three values on the command line) to the extent possible. Check the ranges of the data the user enters (e.g. don't let population be bigger than 1 or less than 0). Print an error message and exit if a value outside the allowed range is entered. Provide a default value if none is given.
Detect if convergence has occurred and stop output if so. Be especially careful of equality comparisons between floating point numbers.
Be sure to handle all user errors (e.g. not providing three values on the command line) to the extent possible. Check the ranges of the data the user enters (e.g. don't let population be bigger than 1 or less than 0). Print an error message and exit if a value outside the allowed range is entered. Provide a default value if none is given.
Detect if convergence or static oscillation has occurred and stop output if so. Be especially careful of equality comparisons between floating point numbers.
LogisticEquation class which represents a
particular instance of the logistic equation (that is particular
values for rate and initial population). Set these values in the
constructor. Provide methods to get the rate, get the population
of a specified generation, get the converged value (return -1 if
there is no converged value; we'll fix this later), get the list of oscillating values, and
the period of oscillation, and to return
the complete list of values.
Rewrite Problem 4 and Problem 5
using this LogisticEquation class.
equals(), hashCode(), and toString() methods to
the logistic equation class. Be sure to think carefully about what it means for two
logistic equations to be equal and document and justify your choice.
LogisticEquation class cloneable.
LogisticEquation class in
a suitably named package. Then rewrite the LogisticArguments
and LogisticTable classes
to use this new class. However, leave the LogisticArguments
and LogisticTable classes in the default package.
java.math.BigDecimal
instead of doubles
internally.
(Does it make sense to provide overloaded versions of the public methods
that take big decimals or strings as arguments instead of doubles?)
Place it in
the same package used above.
Then rewrite the LogisticArguments
and LogisticTable classes
to use this new class. However, leave the LogisticArguments
and LogisticTable classes in the default package.
Write an abstract class
representing all iterated equations; i.e.
not just the logistic equation but any iterated equation.
Put as much functionality in this class as possible
while still making it quite general.
Rewrite the logistic equation class so that it's a subclass of this class.
Put it in the same package as above.
Then rewrite the LogisticArguments
and LogisticTable classes
to use this new class. However, leave the LogisticArguments
and LogisticTable classes in the default package.
Write two new subclasses of the iterated equation class that iterate these equations:
Provide table and argument classes for these as well, along with sample output. Investigate and describe their behavior; e.g. where are the fixed points? Where do they converge? Where do they oscillate? Where are they chaotic? Do they exhibit period doubling?
IllegalArgumentExceptions with appropriate messages.
Then rewrite the Arguments and Table classes
to use these new classes.
interface that describes an arbitrary indexed collection of
java.lang.Number objects such as that represented by the
IteratedEquation class. Make the IteratedEquation class
implement this interface.
Write an applet that draws a graph of p(n) vs. n where p(n) is the nth iteration of the logistic equation (p(i) = r*p(i-1)*(1.0-p(i-1)). (You only need to draw the graph. You do not need to draw axes or legends or anything of that nature.)
UsePARAM tags to specify the rate, the initial population, precision,
and the number of iterations to track.
Note that it is not necessary to achieve convergence. Thus this problem
is a little different from previous ones involving the logistic equation.
Handle all
exceptions reasonably. (Printing an error message on
System.out and exiting is not reasonable.) Assume
one generation per horizontal pixel. Make this applet reasonably
quick.
Make the applet available on a Web page. Include at least three instances of the applet on the page: one with a rate between 1 and 2, one with a rate between 2 and 3, and one with a rate between 3 and 4. Include a link to full source code for the applet. Hand in the source code for the applet, sample HTML files for the applet, screenshots of the running applet, and a URL where the applet can be viewed.
Write a subclass of either Canvas or Component
that draws the graph of an iterated equation.
(You only need to draw the graph. You do not need to draw axes or legends
or anything of that nature.)
LogisticApplet, add the necessary user interface components to allow the
user to set the rate (probably a label, a text field, and a button).
Canvas subclass
for plotting X-Y graphs. Rewrite last week's applet to use this
new component. At this stage it is enough to merely draw the graph.
You do not need to draw axes, legends, tick marks, or similar material.
This component should be in a new package, and should not have any knowledge
of the logistic equation classes. (Should an interface be defined
which classes that want to be graphed can implement, possibly through an adaptor?
or should the interface be in the X-Y plot component? In other words, does the
X-Y plotter ask the objects the graphing for their data, or do the objects tell
the X-Y plotter what to plot? Whichever way it goes, there should almost
certainly be a middle layer adaptor between the thing plotted and the plotter. ) Write a new iterated equation applet that uses the X-Y graph component.
LayoutManager.Then write a frame based stand-alone application that uses frames, each containing an instance of the above panel. Don't do anything that would prevent the program from being expanded to a multiple window application. Hand in the application as a runnable jar archive.
How can the logistic equation be generalized?
What happens if the constraints are relaxed?