Search code examples
riterationfixed-point-iteration

Finding the fixed points of a function


I am trying to find the fixed point of a logistic distribution function and determine how the fixed point changes for different parameter values. The code looks like:

nfxp.reps <- 0
err <- 10
p <- seq(0, 1, by = 0.0001)
pold <- p
gamma <- 6
k <- 3
while (err > 1E-12) {
  nfxp.reps <- nfxp.reps + 1
  if (nfxp.reps > 999) { 
    stop("The number of NFXP reps needs to be increased. \n")
  } 
  pnew <- plogis(-k + gamma * pold) 
  err <- max(abs(pnew - pold))
  pold <- pnew
}

The above code works very well in the above parameter choices: gamma and k - find 3 fixed points, 2 stable and 1 unstable (where p=0.5). However if I change the above parameter non-proportionally, where the middle fixed point is either above or below 0.5, say for:

gamma<-7
k<-3

The loop is unable to locate the middle fixed point which is p=0.3225 (if gamma=7, k=3)


Solution

  • Fixed point iteration by construction cannot find the unstable equilibria in your setup since it is repelling. In other words, unless you start right at the unstable equilibria the nfxp algorithm will always move away from it.

    An alternative approach is to use a root solving approach. Of course, there are no guarantees that all fixed points will be found. Here is a simple example:

    library(rootSolve) # for the uniroot.all function
    pfind<-function(k=3,gamma=7) 
    {
    pdiff <-function(p0) p0-plogis(-k + gamma * p0) 
    uniroot.all(p.diff,c(0,1))
    }
    > fps= pfind()
    > fps
    [1] 0.08036917 0.32257992 0.97925817
    

    We can verify this:

    pseq =seq(0,1,length=100)
    plot(x=pseq ,y= plogis(-k + gamma *pseq),type= 'l')
    abline(0,1,col='grey')
    points(matrix(rep(fps,each=2), ncol=2, byrow=TRUE),pch=19,col='red')
    

    Hope this helps.