using ModelingToolkit, NLsolve
# define some symbols to be used for the symbolic part of the evaluation
@variables x
@parameters slope
@derivitaves D'~x
# The interesting function
f(x) = √(3 + x^2)
# A symbolic expression for the derivative of the function
∂xf_sym = expand_derivatives(D(f(x)))
# Build the system we would like solved
nl_sys = NonlinearSystem([0 ~ ∂xf_sym - slope], [x], [slope])
# generate an in-place evaluator and jacobian for the system
# These are julia functions that implement the symbolic calculation built above.
# https://mtk.sciml.ai/stable/tutorials/nonlinear/
f! = generate_function(nlsys, [x], [slope], expression=Val{false})[2]
j! = generate_jacobian(nlsys, expression=Val{false})[2]
# the desired value for slope
params = [0.01]
# pass the generated function and jacobian to the solver, with an initial guess
soln = nlsolve((out, x)->f!(out, x, params), (out, x)->j!(out, x, params), [0.0])
# build a Julia version of the symbolic derivative
∂xf = eval(build_function([∂xf_sym], [x])[1])
# check that the system is really solved
∂xf(soln.zero) ≈ params