Good day. I'm trying to check whether or not the function has a minimum at point.
For that I use derivatives and Hessian matrices.
The problem is that derivatives are stored in type "language", while I need them in "numeric".
For example, I use
der_x1 <- D(expression(3 + 2 * x_1 + 3 * x_2 + 2 * (x_1)^2 + 2 * x_1 * x_2 + 6 * (x_2)^2), "x_1")
der_x1x1 <- D(der_x1, "x_1")
And get der_x1x1 = 2 * 2
.
typeof(der_x1x1)
returns " language
".
But to find the determinant of the Hessian matrix I need R to simplify 2 * 2
to 4
and convert it to number.
If I try as.numeric(der_x1x1)
, I get Error: 'pairlist' object cannot be coerced to type 'double'
try the following code:
eval(der_x1x1)
x_1 <- 1
x_2 <- 1
eval(der_x1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.