# NonlinearSolve uses AD Jacobian even when I specify it analytically

**URL:** <https://discourse.julialang.org/t/nonlinearsolve-uses-ad-jacobian-even-when-i-specify-it-analytically/122608>\
**Category:** Numerics\
**Tags:** nonlinearsolve\
**Created:** [November 13, 2024, 3:56pm UTC](https://discourse.julialang.org/t/nonlinearsolve-uses-ad-jacobian-even-when-i-specify-it-analytically/122608 "2024-11-13T15:56:42Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![DanDoe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dandoe/32/52717_2.png) [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Post date:** [November 14, 2024, 8:05am UTC](https://discourse.julialang.org/t/nonlinearsolve-uses-ad-jacobian-even-when-i-specify-it-analytically/122608/3 "2024-11-14T08:05:49Z")

</div>

So here is an MWE that demonstrates unexpected behaviour (for me) at multple places:

```julia
using NonlinearSolve

function r(gamma, params_nonlinear)
    println("r") # Does show up
    return gamma^params_nonlinear.exponent
end

function dr(gamma, params_nonlinear)
    println("dr") # Does not show up
    return params_nonlinear.exponent * gamma^(params_nonlinear.exponent - 1.0)
end

h = NonlinearFunction(r; jac = dr)
gamma_0 = 1.0
params_nonlinear = (exponent = 2.0, )
sol = NonlinearSolve.solve(NonlinearProblem(h, gamma_0, params_nonlinear), 
                           NewtonRaphson(;concrete_jac = true, autodiff = false), 
                           abstol = 2 * eps(Float64))
println(sol.stats) # SciMLBase.NLStats(27, 26, 0, 26, 26) => 26 Jacobians created

```

---

_[View the full topic](https://discourse.julialang.org/t/nonlinearsolve-uses-ad-jacobian-even-when-i-specify-it-analytically/122608)._
