I have this code:
Using ForwardDiff:gradient
derivative(f,x) = gradient(x->f(x[1]),[x])
I know gradient in the ForwardDiff take a vector as argument, but what does this mean: (x->f(x[1])), I am confused by x[1].
I am confused by
x[1]
It means to take the first element of the vector x.
This code doesn't really make much sense with the [x] as the last argument. You should probably just use e.g.:
julia> ForwardDiff.derivative(sin, 1.0)
0.5403023058681398
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With