Description Usage Arguments Value Examples
Set independent variable for first and second order derivatives
1 | independent2(x)
|
x |
numeric vector to be differentiated with respect to |
a fAD2 vector with value being x, jacobian being the identity, and hessian being zero
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | x <- independent2(c(0,1))
y <- sum(square(x))/2
print(gradient(y)) # should be c(0,1)
print(hessian(y)) # should be identity
# define some function
f <- function(x){
M <- matrix(x,2,2)
return(sum(solve(M,c(-1,2))))
}
# run function with regular variables
print(f(c(1,-1,2,4)))
# run function with second order AD-variables
x <- independent2(c(1,-1,2,4))
y <- f(x)
print(value(y))
print(gradient(y))
print(hessian(y))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.