fun <- function(x){ y <- x^2 - 6*x return(y); } opt <- nlm(fun,1) #optimizing the function out <- fun(2)