71
630
A Sequences anddifference equations
y
n
=y
n−1
+qy
n−1
(1 −y
n−1
), n = 0,...,N .
Read the input parametersy
0
,q, andN from the command line. The
variables and the equation are explained in Section A.1.5.
b) Equation(A.13)hasthesolution y
n
=1 asn→∞ . Demonstrate, by
running the program, that this is the case wheny
0
=0.3,q = 1, and
N= 50.
c) For larger q q values, y
n
does not approach a constant limit, but
y
n
oscillates instead around the limiting value. Such oscillations are
sometimes observed in wildlife populations. Demonstrate oscillatory
solutions when q is changed to 2 and 3.
d) Itcouldhappenthat y
n
stabilizes at a constant level for largerN.
Demonstrate that this is not the case by running the program with
N= 1000.
Filename: growth_logistic2.py.
Exercise A.20: Automate computer experiments
It is tedious to run a program like the one from Exercise A.19 repeatedly
for a wide range of input parameters. A better approach is to let the
computer do the manual work. Modify the program from Exercise A.19
such that the computation ofy
n
and the plot is made in a function. Let
the title in the plot contain the parametersy
0
andq (N is easily visible
from thex axis). Also let the name of the plot file reflect the values of
y
0
,q, andN. Then make loops overy
0
andq to perform the following
more comprehensive set of experiments:
• y
0
=0.01,0.3
• q = 0.1,1,1.5,1.8,2,2.5,3
• N = 50
How does the initial condition (the value y
0
) seem to influence the
solution?
Hint. If you do no want to get a lot of plots on the screen, which must
be killed, drop the call toshow() in Matplotlib or useshow=False as
argument to plot in SciTools.
Filename: growth_logistic3.py.
Exercise A.21: Generate an HTML report
Extend the program made in Exercise A.20 with a report containing all
the plots. The report can be written in HTML and displayed by a web
browser. The plots must then be generated in PNG format. The source
of the HTML file will typically look as follows: