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)%*%(A%*%x-b))
}
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)%*%(A%*%x-b))
}
Copyright © 2021 Jogjafile Inc.
CRAN package Deriv can compute symbolic derivatives of R functions.
In the code below I have removed the call to
returnin the posted functionf.Function
DDerivis a copy&paste from this RPubs post changed to useDerivinstead of baseDthat does not accept functions as its first argument.Using function
Derivdirectly:Using function
DDeriv: