# Obtain jacobian used by NLsolve

**URL:** <https://discourse.julialang.org/t/obtain-jacobian-used-by-nlsolve/101532>\
**Category:** General Usage\
**Tags:** question, nlsolve\
**Created:** [July 12, 2023, 1:55pm UTC](https://discourse.julialang.org/t/obtain-jacobian-used-by-nlsolve/101532 "2023-07-12T13:55:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PABLO\_ESTEBAN\_MONTES](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablo_esteban_montes/32/47666_2.png) [@PABLO\_ESTEBAN\_MONTES](https://discourse.julialang.org/u/PABLO_ESTEBAN_MONTES)\
**Post date:** [July 12, 2023, 1:55pm UTC](https://discourse.julialang.org/t/obtain-jacobian-used-by-nlsolve/101532/1 "2023-07-12T13:55:04Z")

</div>

Hello, I have a function, let’s call it f!, whose zero I’m trying to find by using the Newton method. I know that the package NLsolve allows me to do this either giving it the jacobian, with something of the form  
`nlsolve(f!, j!, initial_x)`,  
or just allow it to calculate the jacobian itself, with  
`nlsolve(f!, initial_x)`.  
My issue is that I have a function j! that calculates the jacobian, but I seem to have a mistake on the jacobian because when I use mine it does not converge, but when I let NLsolve calculate it’s own jacobian it functions perfectly. I would like to be able to retrieve the jacobian calculated by the function nlsolve, to compare it with my own and find mistakes, is there a way to do so?.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 12, 2023, 3:03pm UTC](https://discourse.julialang.org/t/obtain-jacobian-used-by-nlsolve/101532/2 "2023-07-12T15:03:46Z")

</div>

To find an error in your code you don’t need the Jacobian computed by NLsolve.jl _specifically_: any library computing the right Jacobian will do.  
Depending on what your function looks like, various autodiff frameworks like ForwardDiff.jl or Zygote.jl could work, but your safest bet is probably FiniteDifferences.jl

---

<div class="post-metadata">

**Author:** ![PABLO\_ESTEBAN\_MONTES](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablo_esteban_montes/32/47666_2.png) [@PABLO\_ESTEBAN\_MONTES](https://discourse.julialang.org/u/PABLO_ESTEBAN_MONTES)\
**Post date:** [July 12, 2023, 3:08pm UTC](https://discourse.julialang.org/t/obtain-jacobian-used-by-nlsolve/101532/3 "2023-07-12T15:08:16Z")

</div>

> [@gdalle](#):
>
> FiniteDifferences.jl

Thanks, I found FiniteDifferences shortly before your answer and it did the trick. I tried using ForwardDiff before but it just didn’t work for me, the function uses auxiliary vectors and I had a lot of trouble propagating the Dual types inside it.
