fixedpoint <- function(ftn, x0, tol = 1e-9, max.iter = 100) {
  #applying fixed-point algorithm to find x such that ftn(x) == x
  #x0 is the starting point
  
  #first iteration
  xold <- x0
  xnew <- ftn(xold)
  iter <- 1
  cat("dar iteration 1 meghdare x:", xnew, "\n")
  
  #continue iteration until stopping condition
  while((abs(xnew - xold) > tol) && (iter < max.iter)) {
    xold <- xnew
    xnew <- ftn(xold)
    iter <- iter + 1
    cat("dar iteration", iter, "meghdare x:", xnew, "\n")
  }
  
  #output 
  if (abs(xnew - xold) > tol) {
    cat("algorithm vagara shod\n")
    return(NULL)
  } else {
    cat("Algorithm hamgera shod\n")
    return(xnew)
  }
  
}