For example if I want to find the gradient and Hessian with respect to x of:
f = function(x,y,alpha,A,b){ return((1/n)*(y-alpha*x)%*%(y-alpha*x) + (A%*%x-b)