Description Usage Arguments Value Examples
Set independent variable for first order derivatives
1 | independent(x)
|
x |
numeric vector to be differentiated with respect to |
a fAD vector with value being x and jacobian being the identity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | x <- independent(c(0,1))
y <- sum(square(x))/2
print(gradient(y)) # should be c(0,1)
# 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 AD-variables
x <- independent(c(1,-1,2,4))
y <- f(x)
print(value(y))
print(gradient(y))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.