#This function finds the minimum of the directional derivative if we "move" away # from the current iterarte c_1*f_theta1 +...+ c_m*f_thetam. FindMinFunc <- function(X,S,C,K,prec,grid){ l.g <- length(grid) DirecDer.vec <- grid for(i in 1:l.g){ #print(i) DirecDer.vec[i] <- DirecDer(grid[i],X,S,C,K) } minval <- min(DirecDer.vec) index <- match(1,rank(DirecDer.vec)) thetamin <- grid[index] #free(DirecDer.vec) c(thetamin,minval) }