In this simple example, the derivative is \partial(\mathrm{sqrte})/\partial y = -(\partial f/\partial x)^{-1} (\partial f / \partial y) (evaluated at the root x = nlsolve(f, x0).zero).
Ok so I’ve created a function that calculates the derivative of the square root using the implicit function theorem formula.
function sqrte_diff(x)
F_x(x_new,y) = gradient(g,x_new,y)[1]
F_y(x_new,y) = gradient(g,x_new,y)[2]
y = sqrte(x[1])[1]
y_prime_of_x = -(1/F_y(x,y))*F_x(x,y)
return y_prime_of_x
end
sqrte_diff(4.0)
> 0.24999999999999972
sqrte_diff(4.0) - (x -> sqrt(x))'(4.0)
> 2e-16 # Success!
But I’m having a bit of trouble with the ImplicitDifferentiation package though. Can someone suggest how to use that package for this square root example? Based on the docs, which use a more complicated example, it looks like the first steps are something like the following, but I’m not sure where to go next:
using ImplicitDifferentiation
function fixed_point_conditions(x,y)
return x[1]^2 - y[1]
end
differentiable_sqrte = ImplicitDifferentiation.ImplicitFunction(
sqrte, fixed_point_conditions)