You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since it took me some time to find this information, here is how I think you can do it
using ForwardDiff
using DiffResults
# Function to differentiatef(x) =exp(sin(x)^2)
# Create container for result
result = DiffResults.DiffResult(0., 0.)
# Calculate function and derivative at x = 2.0
x =2.; result = ForwardDiff.derivative!(result, f, x)
@show DiffResults.value(result) ==f(x)
@show DiffResults.derivative(result) == ForwardDiff.derivative(f, x)
There are a couple of things I do not find entirely intuitive in this interface:
Although ForwardDiff has functions derivative and derivative!, there is no function DiffResults.DerivativeResult.
Although there is a ! in the function derivative!, this function in the code above does not modify its argument result.
Excellent package!
Is there a way to get the function value and its derivative in one call?
Thanks.
The text was updated successfully, but these errors were encountered: