BIOS13: Dynamic Systems(动力学系统)

牧云@^-^@ 提交于 2020-01-13 02:26:37

Dynamic Systems

A dynamic systems changes over time, a function relates to time.

Exponential growth

A simple example is that of exponential growth, applicable to bacterial growth in a test tube.

Assumption:

Birth rate: bb

Death rate: dd

Growth rate: r=bdr=b-d

Population size: NN

Because both birth rate and death rate are fixed, so growth rate is also fixed.
Nt+1=rNt N_{t+1} = rN_t
Solution:
Primitive function:N=f(t) Primitive\ function:N=f(t)

Derivation:f(t)=rN=rf(t) Derivation: f'(t) = rN=rf(t)

Backward derivation:Nt=f(t)=N0ert Backward\ derivation: N_t=f(t) = N_0e^{rt}

Here we suppose N0=1N_0=1.

t = seq(0, 10, 0.01)
r1 = 0.5
r2 = -1
n0 = 1
np = n0*exp(r1*t)
nn = n0*exp(r2*t)
plot(t,np,type = 'l',xlab = 'time', ylab = 'n', ylim = c(0, 10))
lines(t,nn,col = 'red')
legend("topleft",  c("r>0","r<0"), lty=c(1, 1), col=c("red", "black"))

在这里插入图片描述

Conclusion:

So when r>0, n increases, otherwise, decreases.

Differential calculus in R

library(deSolve)

expGrowth = function(t, n, r){
  dndt = r*n
  return(list(dndt)) # the output has to be a list
}

timevec = seq(0, 20, 0.1)
r =0.1
n0 = 1
# call the ode function to solve the differential equation
out = ode(y = n0, func = expGrowth, times = timevec, parms = r)

plot(out, main = "Exponential growth")

在这里插入图片描述

Logistic growth

Population can not go on forever. The per capita growth rate r will decrease with population size n.

Assumption:
r=r0(1NK) r=r_0(1-\frac{N}{K})

Nt+1=rNt=r0Nt(1NtK) N_{t+1}=rN_t=r_0N_t(1-\frac{N_t}{K})

在这里插入图片描述

Logistic equation:
Nt=K1+eN0rt N_t=\frac{K}{1+e^{N_0-rt}}
Using R:

par(mfrow=c(1,2))
n = seq(0, 10, 0.1)
K = 8
r0 = 1
r = r0*(1-n/K)
plot(n, r, type = 'l', col= 'blue')
abline(h = c(0))

plot(n, r*n, type = 'l', col= 'blue', ylab = 'dn/dt')
abline(h = c(0))
par(mfrow=c(1,1))

# defferential
# More than one parameter: use a list

library(deSolve)
logisticGrowth = function(t, n, P){
  dndt = P$r0 * n * (1- n/P$K)
  return(list(dndt))
}

timeVec = seq(0, 20, 0.1)
P = list(r0 = 1, K = 100)
n0 = 1
out = ode(y = n0, func = logisticGrowth, times = timeVec, parms = P)

plot(out, main = 'Logistic growth')

在这里插入图片描述

Stability:

According to previous conclusion and the equation 5, when n>K, N increases, n<K, N decreases and when n=K, the population size is stable.

And from mathematic aspect:

The derivative of population size N can show the growth trend, according the negative and positive.

Conclusion:

An equilibrium point is K, which means the system will be stable when started approaching K.

General condition for stability:

  1. Find the equilibrium point:

Let:  f(n)=0 Let:\ \ f(n^*) = 0

  1. Whether the equilibrium n* is stable:

f(n)<0 f'(n^*)<0

  1. Return time:

TR=1f(n) T_R=-\frac{1}{f'(n^*)}

  1. The population go extinct:

n=0 n^*=0

Reference

Exercise

Multidimensional systems

The Lotka-Volterra competition model

{dn1dt=r1n1(1n1+αn2K1)dn2dt=r2n2(1n2+βn1K2) \begin{cases} \cfrac{dn_1}{dt}=r_1n_1(1-\cfrac{n_1+\alpha n_2}{K_1}) \\ \cfrac{dn_2}{dt}=r_2n_2(1-\cfrac{n_2+\beta n_1}{K_2}) \end{cases}

α\alpha = competition coefficient = How much population 2 competes with population 1.

Competition coefficient are usually, but not always, below 1.

Isoclines

Calculate the system equilibrium
dn1dt=r1n1(1n1+αn2K1)=0    n2=1αn1+K1α \cfrac{dn_1}{dt}=r_1n_1(1-\cfrac{n_1+\alpha n_2}{K_1})=0\ \ \Rightarrow\ \ n_2=- \cfrac{1}{\alpha}n_1+\cfrac{K_1}{\alpha}

dn2dt=r2n2(1n2+βn1K2)=0    n2=βn1+K2 \cfrac{dn_2}{dt}=r_2n_2(1-\cfrac{n_2+\beta n_1}{K_2})=0\ \ \Rightarrow\ \ n_2=- \beta n_1+K_2

在这里插入图片描述

在这里插入图片描述

Lotka-Volterra predator-prey model

{dndt=rnanpdpdt=canpμp \begin{cases} \cfrac{dn}{dt}=rn-anp \\ \cfrac{dp}{dt}=canp-\mu p \end{cases}

Assumption:

rn: Prey is exponential growth

a: Prey caught per time unit

c: Converting prey to predators

μ\mu: Background mortality of predators

在这里插入图片描述

When p = r/a, the population size of prey is stable. When predator(p>r/a) increases, prey decreases, vice versa. So the stability of prey is decided by the number of predator.

Stability

Jacobean matrix:
J=(fnnfnpfpnfpp)=(rapancapcanμ) J =\begin{pmatrix} \cfrac{\partial f_n}{\partial n} & \cfrac{\partial f_n}{\partial p} \\ \cfrac{\partial f_p}{\partial n} & \cfrac{\partial f_p}{\partial p} \end{pmatrix} =\begin{pmatrix} r-ap & -an \\ cap & can-\mu \end{pmatrix}
If all eigenvalues(特征值) of the Jacobean matrix have a negative real part, the equilibrium is stable.

**Equilibrium: **
(n,p)=(μca,ra) (n^*, p^*)=(\frac{\mu}{ca},\frac{r}{a})
Jacobean:
J=(rapancapcanμ)=(0μccr0) J =\begin{pmatrix} r-ap^* & -an^* \\ cap^* & can^*-\mu \end{pmatrix} =\begin{pmatrix} 0 & -\frac{\mu}{c} \\ cr & 0 \end{pmatrix}
Eigencalues of 2*2 matrices: λ1,2=T±T2D=±iur\lambda_{1,2}=T\pm\sqrt{T^2-D}=\pm i\sqrt{ur}
A=(a11a12a21a22) A=\begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix}

T=tr(A)=a11+a22 T=tr(A)=a_{11}+a_{22}

D=det(A)=a11a22a12a21 D=det(A)=a_{11}a_{22}-a_{12}a_{21}

Exercise

Stochastic systems

A stochastic system has an uncertain outcome, it can not be perfectly predicted beforehand. A single ‘run’ of a stochastic system is called a realization.

Stochastic models

A random walk

n = 1000 # the length of the walk
x = seq(0, n)

# get an empty plot
plot(NA, type = 'n', xlim = c(0, n), ylim = c(-2*sqrt(n), 2*sqrt(n)), xlab = 'steps', ylab = 'distance')
for(iter in 1:100){ # repeat 100 times
  # walk randomly
  for(i in 1:(n-1)){
    x[i+1] = x[i] + rnorm(1)
  }
  lines(x, col = 'black')
}

在这里插入图片描述

A queue

A model of a standard queue. Every minutes, a new customer is added to the queue with probability Pin. Also every minutes, a customer is finished with probability pout and leaves the queue.

runQ <- function(Pin, Pout, T_max) {
  q_length <- 0 # number of people in line
  q_stored <- rep(0,T_max)
  for (t_q in 1:T_max) {
    
    # every minute a person is added to the q
    # with probability Pin
    if(runif(1) < Pin){
      # add a person to the queue
      q_length <- q_length + 1
    }
    # every minute a person leaves
    # with probability Pout
    if(runif(1) < Pout ) {
      if(q_length>0) {
        # remove a person from the queue
        q_length <- q_length - 1
      }
    }
    q_stored[t_q] <- q_length
  }
  plot(1:T_max, q_stored, xlab='time (min)', ylab='q length', type='l')
}
runQ(0.6, 0.5, 100)

在这里插入图片描述

The Moran process

The Moran process is a model in population genetics. It is a model of the spread of an allele in a population. A population has N individuals of type A or B. Each time-step, one random individual is chosen to die. It is replaced by the copy of another randomly chosen individual. The process continues until A or B is fixed.

runMoran <- function(tmax, N) {
  # N is total population size
  # a function runMoran that simulates 
  # the Moran process tmax time-steps, 
  
  # population vector
  # each element represents one individual
  # 0 : B, wild type
  # 1 : A, mutant type
  population <- rep(0,N)
  # starting with a single copy of A 
  population[1] <- 1
  
  for (t in 1:tmax) {
    #Each time-step, 
    # one random individual is chosen to die. 
    # #It is replaced by the copy 
    # # of another randomly chosen individual.
    # a vector of two random individuals:
    dead_lucky <- sample.int(N,2)
    dead <- dead_lucky[1]
    lucky <- dead_lucky[2]
    population[dead] <- population[lucky]
    
    # if B fixed, stop:
    if(sum(population)==0 ) {
      break
    }
    # if A fixed, stop:
    if(sum(population)==N) {
      break
    }
  }
  # and returns the final number of A:s.
  return(sum(population))
}

Discrete time systems

conclusion

nt+1=f(nt)n_{t+1}=f(n_t)

Equilibrium: n=f(n)n^*=f(n^*)

Stability: f(n)<1|f'(n^*)|<1

The Ricker model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!