R optimization - Passing objective and gradient function arguments as list
问题 I have a function that evaluates the gradient and output simultaneously. I want to optimize it with respect to an objective function. How do I pass the objective and gradient as a list to optimx ? The below example illustrates the problem: Suppose I want to find the smallest non-negative root of the polynomial x^4 - 3*x^2 + 2*x + 3 . Its gradient is 4*x^3 - 6*x + 2 . I use the method nlminb in optimx , as shown below. optimx(par = 100, method = "nlminb", fn = function(x) x^4 - 3*x^2 + 2*x + 3