CHAPTER 2

1

1a

D[f,x] differentiates f with respect to x:

n[t_]:=a Exp[r t]

D[n[t],t]

Verify that this derivative is equal to rn[t] and that n[t] has the correct initial value:

r n[t]

n[0]

1b

DSolve[] solves a differential equation; you must first clear the existing definition of n:

Clear[n]

DSolve[{n'[t]==r n[t],n[0]==a},n[t],t]

2

I first calculate and plot the logarithms of the numbers.

logdata=N[Log[{8,30,81,282,705,1325}]];

logplot=ListPlot[logdata,PlotRange->{{0,6},{1.5,7.5}},
AxesOrigin->{0,1.5}]

I now calculate and plot the best-fitting line:

regline=Fit[logdata,{1,t},t]

Show[logplot,Plot[regline,{t,1,6},
					DisplayFunction->Identity]]

Notes: Log[list] will return a list of the logarithms of the elements of list, but in this case N is needed to convert integers to real numbers. Note the use of Plot and ListPlot for plotting continuous curves and lists of data respectively, and of Show for combining two or more graphics in a single plot. Fit calculates regressions by least squares. In this case {1,t} fits a linear regression, with an intercept (called for by 1) and a slope (called for by t).

3

Solve the logistic equation as in Exercise 1b (giving the name logisticsoln to the rule for the solution and calling the initial value a and the parameters r and k) by writing logisticsoln=DSolve[..].

Note that logisticsoln is a replacement rule n[t]–>xxx; if we write n[t]/.logisticsoln, where /. (pronounced "slash dot" and meaning "evaluated at") is the replacement operator, then n[t] is temporarily replaced by xxx

n[t]/.logisticsoln

The solution with values of r, k and a temporarily assigned the values 0.1, 1000 and 1500 can be plotted thus

Plot[n[t]/.logisticsoln/.{r->0.1,k->1000,a->1500},
	{t,0,30},PlotRange->All]

4

Choose parameter values giving the same carrying capacity and initial rate of increase for the two models and plot the curves. You can superimpose the two curves making one solid and the other dotted as in the following example:

Plot[{Sin[x],Cos[x]},{x,0,4Pi},
	PlotStyle->{{Thickness[0.004]},{Dashing[{.05,.05}]}}]

5

5a

gausedata={2,10,10,11,21,56,104,137,165,194,217,
			199,201,182,192,179,190,206,209,196,
			195,234,210,210,180};

The days are not in exact sequence so that to plot the data against time it is necessary to compute a matrix {{0,2},{2,10},{3,10},...,{25,180}}:

pairsdata=Transpose[{Range[25],gausedata}];
pairsdata[[1,1]]=0;
gauseplot=ListPlot[pairsdata]

5b

We first show that (K–n)/n is proportional to exp(–rt). (I assume that logisticsoln is defined from Ex 3 as the replacement rule for the logistic curve. If not, you must define it by entering logisticsoln=n[t]–>xxx):

(k-n[t])/n[t]/.logisticsoln

Simplify[%]

We now estimate K and r:

k=Sum[gausedata[[i]],{i,10,25}]/16   //N

data9=Take[gausedata,9]
pairs9=Transpose[{Range[9],Log[(k–data9)/data9]}]//N

pairs9[[1,1]]=0;

Fit[pairs9,{1,t},t]

Assign r the value from the negative slope of this line, then plot the logistic curve and superimpose it on the data. (Since r and k have been assigned values, they should not be included in the temporary replacement rule in plotting the logistic curve.)

6

Adapt Exercise 5

7

Clear the existing values of r and k, define and differentiate the function, simplify it since it looks rather complicated, and then evaluate it at the equilibrium values. % denotes the output from the previous calculation; this notation should be used sparingly.

Clear[r,k]
f[n_]:=r (1-n/k) n

D[f[n],n]

Simplify[%]

%/.{{n->0},{n->k}}

8

Adapt Exercise 7.

9

F[n_]:=n Exp[r (1-n/k)]

Evaluate this function at 0 and k, and then evaluate its derivatives at these points.

10

The operator NestList[] provides a powerful method of iteration. For example

r=2.5;
k=1000;
NestList[F,800,10]

returns a list of the values obtained by iterating F(n) 10 times, starting with the initial value 800. (Thus there are 11 values altogether.) The parameters in the function must be assigned values before  NestList[] is used. This list of values can be passed for plotting to ListPlot:

ListPlot[NestList[F,800,10],PlotJoined->True]

The graphics option PlotJoined–>True joins the points by lines. Some experimentation with further graphics options such as AxesOrigin and PlotRange may be needed to make the graph look pretty.

Use this method to investigate the behavior of the iterates of F(n) with different values of r and k and with different initial values.

11

First enter the data, data={. , ... , .}. Then calculate

logdata=N[Log[data]];
var1=Rest[logdata];
var2=Drop[logdata,-1];
pairsdata=Transpose[{var2,var1}];

var1 is the list of log numbers with its first element dropped, var2 is the list with its last element dropped, and pairsdata is the list of pairs of values {{x1,x2},{x2,x3},...,{xn–1,xn}}, where xt = log nt. Thus ListPlot[pairsdata] will give the required plot, and Fit[pairsdata,{1,x},x] will give the ordinary least squares fit.

The package MonteCarlo contains a procedure called Pollard which will implement the test of Pollard et al. (1987) for density dependence. You must first read in the package by using the command <<Package. (This may not work if the package is not in the same folder as the Mathematica program.) The command Pollard[data,99] will then calculate 99 Monte Carlo simulations and return the rank of the observed slope among the 100 values (99 simulated + 1 observed); ?Pollard gives information about the procedure.

<<MonteCarlo.m

?Pollard

Pollard[data,99]