fiche td avec le logiciel : tp1-newenglish ||||| insa 4

14
Fiche TD avec le logiciel : TP1-newEnglish ————— INSA 4-BIM TP1 : Recursion equation in R Christelle LOPES [email protected] ————— Table des mati` eres 1 Introduction 2 2 Definition of the models 2 3 Qualitative analysis of discret-time models 2 3.1 Fixed points ............................................ 2 3.2 Stability of fixed points ..................................... 3 4 Numerical simulations 4 4.1 Model implementation ...................................... 4 4.2 Cobweb (stair step) diagram ................................... 5 4.3 Dynamics of the models ..................................... 6 4.4 Bifurcation diagram ....................................... 7 5 Towards a stable structure of chaos? 10 5.1 Sensitivity to initial conditions ................................. 10 5.2 Towards a mean prediction ................................... 13 5.3 Towards the ”control”of chaotic trajectories .......................... 14 1

Upload: others

Post on 24-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Fiche TD avec le logiciel : TP1-newEnglish

—————

INSA 4-BIM

TP1 : Recursion equation in R

Christelle [email protected]

—————

Table des matieres

1 Introduction 2

2 Definition of the models 2

3 Qualitative analysis of discret-time models 23.1 Fixed points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2 Stability of fixed points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

4 Numerical simulations 44.1 Model implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44.2 Cobweb (stair step) diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.3 Dynamics of the models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.4 Bifurcation diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

5 Towards a stable structure of chaos ? 105.1 Sensitivity to initial conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.2 Towards a mean prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135.3 Towards the ”control” of chaotic trajectories . . . . . . . . . . . . . . . . . . . . . . . . . . 14

1

Christelle [email protected]

1 Introduction

The aim is to become familiar with software to analyse discrete-time models. This first sessionconcerns the study of the most famous population models characterised by a recursion equation.

2 Definition of the models

Discrete time population dynamic models are defined by a recursion equation :

Nt+1 = f(Nt)

We will study here the most famous population models :— The exponential model

Nt+1 = rNt

— The logistic modelNt+1 = rNt

(1 − Nt

K

)— The Gompertz model

Nt+1 = −rNt ln(

Nt

K

)where r and K are positive parameters.

Let N0 be the initial condition.

3 Qualitative analysis of discret-time models

3.1 Fixed points

1. How do you obtain the fixed points of a discrete-time population dynamic model ?

2. Give the fixed points of the exponential model.

3. Give the fixed points of the logistic model.

Christelle [email protected]

4. And the ones of the Gompertz model.

3.2 Stability of fixed points

5. How do you determine the stability of the fixed points of a discrete-time model ?

6. Determine the stability of the fixed points of the exponential model.

7. Do the same for the logistic model.

Christelle [email protected]

8. And the Gompertz model.

4 Numerical simulations

4.1 Model implementation

We want to create generic functions (depending on the parameters and the initial condition) that cal-culate population densities according to the three population models for t from 0 to tmax. Each function,when applied, should return a table with time in the first column and population densities in the secondcolumn.

To avoid the use of loops for(), we can use recursive functions. A recursive function is a function thatrefers to itself. It can thus be used to calculate the nth term of the equation un = f(un−1). In , arecursive function can be defined as follows :

> #n is time, u0 the initial condition, func the recursive function>> frecurs <- function(n=0, u0, func)+ {+ if (n==0) return(u0)+ else+ {+ return(frecurs(n=n-1, u0=func(u0), func))+ }+ }

1. Create a recursive function common to the three models frecurs() above. Then, create a specificfunction for each model (i.e. func() above) to calculate the corresponding densities, and apply therecursive function to each model. Make sure that all values of Nt are returned for t = 0 to t = tmax,not only at tmax.

Verification for the exponential model with r = 2, N0 = 2 and tmax = 50 :

t N1 0 22 1 43 2 84 3 165 4 326 5 64

Verification for the logistic model with r = 2, K = 10, N0 = 2 and tmax = 50 :

t N1 0 2.0000002 1 3.2000003 2 4.3520004 3 4.9160195 4 4.9985896 5 5.000000

Christelle [email protected]

Verification for the Gompertz model with r = 2, K = 10, N0 = 2 and tmax = 50 :t N

1 0 2.0000002 1 6.4377523 2 5.6704464 3 6.4338855 4 5.6747716 5 6.430139

4.2 Cobweb (stair step) diagram

The cobweb representation (or stair step diagram) consists in representing the recursion equationNt+1 = f(Nt) using the equation curves Nt+1 = f(Nt) and Nt+1 = Nt. An example is given belowfor the exponential model :

> r0 <- 1.5> tmax <- 50> K0 <- 0> Ni <- 2> N=frecurs(t=tmax,r=r0,K=K0,N0=Ni,func=Mexpo)> #frecurs is my recursive function,> #and Mexpo the reccurence function of the exponential model>> curve(r0*x, from=0, to=50, n=length(N), las=1,+ xlab=expression(N[t]), ylab=expression(N[t+1]),lwd=2)> abline(a=0,b=1, col="blue",lwd=2)> abline(h=0,lty=3)> abline(v=0,lty=3)> points(N, N, type="S", col="red")> legend("topleft",c("f(n)",expression (paste(paste(n[t+1],"="),n[t]))),lty=1,col=c("black","blue"),lwd=2)

0 10 20 30 40 50

0

20

40

60

Nt

Nt+

1

f(n)nt+1=nt

2. Do the same for the logistic and the Gompertz models with N0 = 2, r = 1.5, K = 10 and tmax = 50.Comment the results.

Christelle [email protected]

4.3 Dynamics of the models

We can also represent model predictions by plotting Nt over time. For each of the three models :

3. Plot (in 4 different graphics), the time-course of Nt, for t from 0 to 50, N0 = 10, K = 1000 anddifferent r values : r = 1.5, r = 2.8, r = 3.1 and r = 3.7. Be careful to represent the point estimatesof your densities by points, we do not simulate a continuous-time model...

4. Test different initial conditions. Comment.

Christelle [email protected]

4.4 Bifurcation diagram

We can also represent the asymptotic behavior of a model according to the values of one of itsparameter, and then plot a bifurcation diagram. Be careful, you have to simulate the model longenough to be sure you have reached the asymptotic regime.

We showed above that the predictions of the logistic model depend on the value of the populationgrowth rate (r parameter). The bifurcation diagram of the logistic model is plotted below forK = 200 and r varying from 0 to 4 with a step of 0.1 :

0 1 2 3 4

050

100

150

200

Value of r

N(t

=10

0 to

500

)

5. Reproduce this diagram with ../config/figs/Rlogo.pdf.

6. Which parameter should you change to obtain the following diagram ?

Christelle [email protected]

0 1 2 3 4

050

100

150

200

Value of r

N(t

=10

0 to

500

)

7. From this diagram, find the different types of dynamics and associate each type of dynamics withthe value of r in the interval [0,4].

Christelle [email protected]

8. Zoom into the area where 3 < r < 4 and give the values of r leading to a periodic dynamic. Givethe period.

9. Represent the bifurcation diagram for 3.4 < r < 4.0 and 3.847 < r < 3.857. What do you notice ?

Christelle [email protected]

5 Towards a stable structure of chaos ?

The chaotic dynamics predicted by models such as the discrete-time logistic model are part of whatis known as deterministic chaos, which can be seen as a paradigm of what is behind by the word hazard.But then, how to use such models in prediction ? Would it be not possible to give mean predictions ? Thisis what we are going to look at in this part. For that purpose, we will study with more details the logisticmodel with K = 1 and r = 3.98.

The first characteristic of such chaotic dynamics is the dependence on initial conditions, that drasti-cally limits a precise prediction.

5.1 Sensitivity to initial conditions

1. Simulate the previous discrete-time logistic model over 100 time steps for two very close initialconditions : N10 = 0.500 and N20 = 0.501. Represent the dynamics in the same figure.

2. In order to more easily quantify the difference between the two initial conditions, represent zt =N1t −N2t :

Christelle [email protected]

0 20 40 60 80 100

−1.

0−

0.5

0.0

0.5

1.0

Time (t)

z=N

1−N

2

3. In the same histogram, represent the distribution of Nt values for the two initial conditions pre-viously simulated over 100 time steps. This can be done using the multhist() function of the plotrixpackage.

Christelle [email protected]

0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95

Nt

Occ

uren

ce

05

1015

2025

30

4. Statistically compare the two distributions. What do you notice ?

5. Simulate the model with very different initial conditions (from 0.1 to 0.9) on 1000 time steps andrepresent the distribution of the values in the same histogram. Compare the obtained distributions.

Christelle [email protected]

5.2 Towards a mean prediction

In fact, we are able to identify an asymptotic statistical distribution of our model predictions, thatis independent on the initial conditions. It then becomes possible to make a ”mean” prediction.Indeed, each tested initial condition represents a simulation of a chaotic variable. By an ”original”application of the central limit theorem, Pave (2006) 1 has thus shown that the marginal distribu-tion of the sums of such chaotic variables, which are themselves chaotic, tends towards a Gaussianlaw :

Den

sity

0.0 0.2 0.4 0.6 0.8 1.0

0.0

0.5

1.0

1.5

2.0

2.5

6. Reproduce this figure through the following steps :

(a) From the previous simulations, calculate the marginal sum of Nt for each t corresponding tothe different initial conditions ;

1. Pave, 2006. Modeling living systems, their diversity and their complexity : some methodological and theoreticalproblems. C. R. Biologies 329, p.3-12.

Christelle [email protected]

(b) Represent the distribution of these sums ;

(c) Calculate the mean, µ, and the standard deviation, σ, of these marginal sums ;

(d) In the same graphic, represent the curve representing the probability distribution of the Gaus-sian law of mean µ and standard deviation σ.

5.3 Towards the ”control” of chaotic trajectories

As shown before, chaotic regimes are also sensitive to model parameter values.

7. Simulate the model for N0 = 0.5000, r1 = 3.9800 and r2 = 3.9801.

You can see very different dynamics for very close values of r. This sensitivity to the parametervalues can however be used to ”drive” periodic trajectories to a chosen state (Shinbrot et al., 1993) 2.The idea is to use sensitivity to small disturbances to drive the system to a state chosen in advance.The following illustration is taken from Pave (2012) 3 where these aspects are discussed and concreteexamples presented.

We are still in the case of a density population Nt whose dynamic is described by the discretelogistic model (with K = 1). It is assumed that r has a nominal value of r0 = 3.6 and that thecurrent state is Nt = 0.4. We want to reach the neighborhood of Nt = 0.8 (0.78 < Nt < 0.82), andfor this, we try to ”play” with the r value to achieve this goal as soon as possible. We can thus buildan adaptive control procedure, by writing the following model :

Nt+1 = (r0 + ε)Nt(1 − Nt

K ) = (r0 + ε)Nt(1 −Nt) for K = 1.

8. For these conditions, determine the value of ε that allows to reach the goal as soon as possible andspecify the number of time steps.

Thus, having a chaotic system allows to quickly reach a given goal, starting far from this goal andslightly modifying a parameter (or some parameters) of the model. Such ”soft piloting” procedurescan therefore be very interesting in different applied contexts (management of natural populations,renewable resources, etc.) but also in more fundamental approaches, related to evolution for example(origin of speciation, species extinction ...).

2. Shinbrot T., Grebogi C., Yorke JA, Ott E. (1993) Using Small Disturbances to Control Chaos, Nature 363, pp. 411-417.3. Pave, 2012. Modeling living systems, from the cell to the ecosystem. Ed. Lavoisier, pp. 633.