# Julia equivalent for python scipy.optimize.fsolve

**URL:** https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139
**Category:** General Usage
**Tags:** package, roots
**Created:** [September 6, 2020, 12:09pm UTC](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139 "2020-09-06T12:09:12Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 6, 2020, 12:59pm UTC](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139/7 "2020-09-06T12:59:11Z")

</div>

> [@HerAdri](#):
>
> Or Exist in Julia a function or package that Convert a System of Linear Equations to Matrix Form?

Yes, if you use `NLsolve` as in my [post above](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139/5) with `autodiff=:forward` then it uses [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation) to form the Jacobian matrix for Newton iterations. If you have a linear system of equations, the Jacobian matrix is exactly the matrix form of the problem, and Newton iterations will converge in a single `\` step.

And if you know that your equations are linear, you can do the differentiation directly using the [ForwardDiff.jl package](https://github.com/JuliaDiff/ForwardDiff.jl):

```julia
julia> using ForwardDiff

julia> F(x) = [1- x[1] - x[2], 8 - x[1] - 3*x[2]]
F (generic function with 1 method)

julia> J = ForwardDiff.jacobian(F, [0,0])
2×2 Array{Int64,2}:
 -1 -1
 -1 -3

julia> x = -J \ F([0,0])
2-element Array{Float64,1}:
 -2.5
  3.5

```

Here, the Jacobian `J` corresponds to the “matrix form” of your problem for a right-hand-side of `-F([0,0])`, and appropriate use of `\` (equivalent to a single Newton step) gives the same solution `x` as above.

PS. [Please quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/75300).

---

_[View the full topic](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139)._
