calculating the Gradient and the Hessian in R

前端 未结 2 1685
悲&欢浪女
悲&欢浪女 2021-02-10 18:34

As you know, the Gradient of a function is the following vector:

\"the

and the Hessian is the fo

2条回答
  •  悲&欢浪女
    2021-02-10 19:10

    You can use the pracma library, such as:

    library(pracma)
    
    dummy <- function(x) {
      z <- x[1]; y <- x[2]
      rez <- (z^2)*(y^3)
      rez
    }
    
    grad(dummy, c(1,2))
    [1] 16 12
    
    hessian(dummy, c(1,2))
         [,1] [,2]
    [1,]   16   24
    [2,]   24   12
    

提交回复
热议问题